@zimic/http 0.4.0-canary.0 → 0.4.0-canary.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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 {
@@ -127,31 +136,29 @@ declare namespace HttpFormDataSchemaName {
127
136
  * // "title" | "content"
128
137
  */
129
138
  type HttpFormDataSchemaName<Schema extends HttpFormDataSchema> = IfNever<Schema, never, keyof Schema & string>;
130
- type PrimitiveHttpFormDataSerialized<Type> = Type extends HttpFormDataSchema[string] ? Type : Type extends (infer ArrayItem)[] ? ArrayItem extends (infer _InternalArrayItem)[] ? never : PrimitiveHttpFormDataSerialized<ArrayItem>[] : Type extends number ? `${number}` : Type extends boolean ? `${boolean}` : never;
139
+ type PrimitiveHttpFormDataSerialized<Type> = [Type] extends [never] ? never : Type extends number ? `${number}` : Type extends boolean ? `${boolean}` : Type extends null ? 'null' : Type extends symbol ? never : Type extends HttpFormDataSchema[string] ? Type : Type extends (infer ArrayItem)[] ? ArrayItem extends (infer _InternalArrayItem)[] ? never : PrimitiveHttpFormDataSerialized<ArrayItem>[] : string;
131
140
  /**
132
141
  * Recursively converts a schema to its {@link https://developer.mozilla.org/docs/Web/API/FormData FormData}-serialized
133
- * version. Numbers and booleans are converted to `${number}` and `${boolean}` respectively, and not serializable values
134
- * are excluded, such as functions and dates.
142
+ * version. Numbers, booleans, and null are converted to `${number}`, `${boolean}`, and 'null' respectively, and other
143
+ * values become strings.
135
144
  *
136
145
  * @example
137
146
  * import { type HttpFormDataSerialized } from '@zimic/http';
138
147
  *
139
148
  * type Schema = HttpFormDataSerialized<{
140
- * contentTitle: string | null;
141
- * contentSize: number;
149
+ * contentTitle: string;
150
+ * contentSize: number | null;
142
151
  * content: Blob;
143
152
  * full?: boolean;
144
- * date: Date;
145
- * method: () => void;
146
153
  * }>;
147
154
  * // {
148
- * // contentTitle: string | null;
149
- * // contentSize? `${number}`;
155
+ * // contentTitle: string;
156
+ * // contentSize? `${number}` | 'null';
150
157
  * // content: Blob;
151
158
  * // full?: "false" | "true";
152
159
  * // }
153
160
  */
154
- type HttpFormDataSerialized<Type> = Type extends HttpFormDataSchema ? Type : Type extends (infer _ArrayItem)[] ? never : Type extends Date ? never : Type extends (...parameters: never[]) => unknown ? never : Type extends symbol ? never : Type extends Map<infer _Key, infer _Value> ? never : Type extends Set<infer _Value> ? never : Type extends object ? {
161
+ type HttpFormDataSerialized<Type> = [Type] extends [never] ? never : Type extends HttpFormDataSchema ? Type : Type extends object ? {
155
162
  [Key in keyof Type as IfNever<PrimitiveHttpFormDataSerialized<Type[Key]>, never, Key>]: PrimitiveHttpFormDataSerialized<Type[Key]>;
156
163
  } : never;
157
164
 
@@ -181,13 +188,14 @@ type HttpFormDataSerialized<Type> = Type extends HttpFormDataSchema ? Type : Typ
181
188
  *
182
189
  * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http#httpformdata `HttpFormData` API reference}
183
190
  */
184
- declare class HttpFormData<Schema extends HttpFormDataSchema = HttpFormDataSchema> extends FormData {
191
+ declare class HttpFormData<LooseSchema extends HttpFormDataSchema.Loose = HttpFormDataSchema.Loose> extends FormData {
192
+ readonly _schema: HttpFormDataSerialized<LooseSchema>;
185
193
  /** @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;
194
+ set<Name extends HttpFormDataSchemaName<this['_schema']>>(name: Name, value: Exclude<ArrayItemIfArray<NonNullable<LooseSchema[Name]>>, Blob>): void;
195
+ set<Name extends HttpFormDataSchemaName<this['_schema']>>(name: Name, blob: Exclude<ArrayItemIfArray<NonNullable<LooseSchema[Name]>>, string>, fileName?: string): void;
188
196
  /** @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;
197
+ append<Name extends HttpFormDataSchemaName<this['_schema']>>(name: Name, value: Exclude<ArrayItemIfArray<NonNullable<LooseSchema[Name]>>, Blob>): void;
198
+ append<Name extends HttpFormDataSchemaName<this['_schema']>>(name: Name, blob: Exclude<ArrayItemIfArray<NonNullable<LooseSchema[Name]>>, string>, fileName?: string): void;
191
199
  /**
192
200
  * Get the value of the entry associated to a key name.
193
201
  *
@@ -197,7 +205,7 @@ declare class HttpFormData<Schema extends HttpFormDataSchema = HttpFormDataSchem
197
205
  * @returns The value associated with the key name, or `null` if the key does not exist.
198
206
  * @see {@link https://developer.mozilla.org/docs/Web/API/FormData/get MDN Reference}
199
207
  */
200
- get<Name extends HttpFormDataSchemaName.NonArray<Schema>>(name: Name): ReplaceBy<ReplaceBy<ArrayItemIfArray<Schema[Name]>, undefined, null>, Blob, File>;
208
+ get<Name extends HttpFormDataSchemaName.NonArray<this['_schema']>>(name: Name): ReplaceBy<ReplaceBy<ArrayItemIfArray<this['_schema'][Name]>, undefined, null>, Blob, File>;
201
209
  /**
202
210
  * Get all the values of the entry associated with a key name.
203
211
  *
@@ -207,24 +215,24 @@ declare class HttpFormData<Schema extends HttpFormDataSchema = HttpFormDataSchem
207
215
  * @returns An array of values associated with the key name, or an empty array if the key does not exist.
208
216
  * @see {@link https://developer.mozilla.org/docs/Web/API/FormData/getAll MDN Reference}
209
217
  */
210
- getAll<Name extends HttpFormDataSchemaName.Array<Schema>>(name: Name): ReplaceBy<ArrayItemIfArray<NonNullable<Schema[Name]>>, Blob, File>[];
218
+ getAll<Name extends HttpFormDataSchemaName.Array<this['_schema']>>(name: Name): ReplaceBy<ArrayItemIfArray<NonNullable<this['_schema'][Name]>>, Blob, File>[];
211
219
  /** @see {@link https://developer.mozilla.org/docs/Web/API/FormData/has MDN Reference} */
212
- has<Name extends HttpFormDataSchemaName<Schema>>(name: Name): boolean;
220
+ has<Name extends HttpFormDataSchemaName<this['_schema']>>(name: Name): boolean;
213
221
  /** @see {@link https://developer.mozilla.org/docs/Web/API/FormData/delete MDN Reference} */
214
- delete<Name extends HttpFormDataSchemaName<Schema>>(name: Name): void;
215
- forEach<This extends HttpFormData<Schema>>(callback: <Key extends HttpFormDataSchemaName<Schema>>(value: ReplaceBy<ArrayItemIfArray<NonNullable<Schema[Key]>>, Blob, File>, key: Key, parent: HttpFormData<Schema>) => void, thisArg?: This): void;
222
+ delete<Name extends HttpFormDataSchemaName<this['_schema']>>(name: Name): void;
223
+ forEach<This extends HttpFormData<this['_schema']>>(callback: <Key extends HttpFormDataSchemaName<this['_schema']>>(value: ReplaceBy<ArrayItemIfArray<NonNullable<this['_schema'][Key]>>, Blob, File>, key: Key, parent: HttpFormData<this['_schema']>) => void, thisArg?: This): void;
216
224
  /** @see {@link https://developer.mozilla.org/docs/Web/API/FormData/keys MDN Reference} */
217
- keys(): FormDataIterator<HttpFormDataSchemaName<Schema>>;
225
+ keys(): FormDataIterator<HttpFormDataSchemaName<this['_schema']>>;
218
226
  /** @see {@link https://developer.mozilla.org/docs/Web/API/FormData/values MDN Reference} */
219
- values(): FormDataIterator<ReplaceBy<ArrayItemIfArray<NonNullable<Schema[HttpFormDataSchemaName<Schema>]>>, Blob, File>>;
227
+ values(): FormDataIterator<ReplaceBy<ArrayItemIfArray<NonNullable<this['_schema'][HttpFormDataSchemaName<this['_schema']>]>>, Blob, File>>;
220
228
  /** @see {@link https://developer.mozilla.org/docs/Web/API/FormData/entries MDN Reference} */
221
229
  entries(): FormDataIterator<[
222
- HttpFormDataSchemaName<Schema>,
223
- ReplaceBy<ArrayItemIfArray<NonNullable<Schema[HttpFormDataSchemaName<Schema>]>>, Blob, File>
230
+ HttpFormDataSchemaName<this['_schema']>,
231
+ ReplaceBy<ArrayItemIfArray<NonNullable<this['_schema'][HttpFormDataSchemaName<this['_schema']>]>>, Blob, File>
224
232
  ]>;
225
233
  [Symbol.iterator](): FormDataIterator<[
226
- HttpFormDataSchemaName<Schema>,
227
- ReplaceBy<ArrayItemIfArray<NonNullable<Schema[HttpFormDataSchemaName<Schema>]>>, Blob, File>
234
+ HttpFormDataSchemaName<this['_schema']>,
235
+ ReplaceBy<ArrayItemIfArray<NonNullable<this['_schema'][HttpFormDataSchemaName<this['_schema']>]>>, Blob, File>
228
236
  ]>;
229
237
  /**
230
238
  * Checks if the data is equal to the other data. Equality is defined as having the same keys and values, regardless
@@ -234,7 +242,7 @@ declare class HttpFormData<Schema extends HttpFormDataSchema = HttpFormDataSchem
234
242
  * @returns A promise that resolves with `true` if the data is equal to the other data, or `false` otherwise.
235
243
  * Important: both form data might be read while comparing.
236
244
  */
237
- equals<OtherSchema extends Schema>(otherData: HttpFormData<OtherSchema>): Promise<boolean>;
245
+ equals<OtherSchema extends LooseSchema>(otherData: HttpFormData<OtherSchema>): Promise<boolean>;
238
246
  /**
239
247
  * Checks if the data contains the other data. This method is less strict than {@link HttpFormData#equals} and only
240
248
  * requires that all keys and values in the other data are present in this data.
@@ -243,7 +251,7 @@ declare class HttpFormData<Schema extends HttpFormDataSchema = HttpFormDataSchem
243
251
  * @returns A promise that resolves with `true` if this data contains the other data, or `false` otherwise. Important:
244
252
  * both form data might be read while comparing.
245
253
  */
246
- contains<OtherSchema extends Schema>(otherData: HttpFormData<OtherSchema>): Promise<boolean>;
254
+ contains<OtherSchema extends LooseSchema>(otherData: HttpFormData<OtherSchema>): Promise<boolean>;
247
255
  /**
248
256
  * Converts this form data into a plain object. This method is useful for serialization and debugging purposes.
249
257
  *
@@ -268,7 +276,7 @@ declare class HttpFormData<Schema extends HttpFormDataSchema = HttpFormDataSchem
268
276
  *
269
277
  * @returns A plain object representation of this form data.
270
278
  */
271
- toObject(): Schema;
279
+ toObject(): this["_schema"];
272
280
  }
273
281
 
274
282
  interface HttpPathParamsSchema {
@@ -278,11 +286,10 @@ declare namespace HttpPathParamsSchema {
278
286
  /** A schema for loose HTTP path parameters. Parameter values are not strictly typed. */
279
287
  type Loose = Record<string, any>;
280
288
  }
281
- type PrimitiveHttpPathParamsSerialized<Type> = Type extends HttpPathParamsSchema[string] ? Type : Type extends (infer _ArrayItem)[] ? never : Type extends number ? `${number}` : Type extends boolean ? `${boolean}` : Type extends null ? undefined : never;
289
+ type PrimitiveHttpPathParamsSerialized<Type> = [Type] extends [never] ? never : Type extends number ? `${number}` : Type extends boolean ? `${boolean}` : Type extends null ? 'null' : Type extends symbol ? never : Type extends HttpPathParamsSchema[string] ? Type : string;
282
290
  /**
283
- * Recursively converts a schema to its path parameters-serialized version. Numbers and booleans are converted to
284
- * `${number}` and `${boolean}` respectively, null becomes undefined and not serializable values are excluded, such as
285
- * functions and dates.
291
+ * Recursively converts a schema to its path parameters-serialized version. Numbers, booleans, and null are converted to
292
+ * `${number}`, `${boolean}`, and 'null' respectively, and other values become strings.
286
293
  *
287
294
  * @example
288
295
  * import { type HttpPathParamsSerialized } from '@zimic/http';
@@ -291,16 +298,14 @@ type PrimitiveHttpPathParamsSerialized<Type> = Type extends HttpPathParamsSchema
291
298
  * userId: string;
292
299
  * notificationId: number | null;
293
300
  * full?: boolean;
294
- * from?: Date;
295
- * method: () => void;
296
301
  * }>;
297
302
  * // {
298
303
  * // userId: string;
299
- * // notificationId: `${number}` | undefined;
304
+ * // notificationId: `${number}` | 'null';
300
305
  * // full?: "false" | "true";
301
306
  * // }
302
307
  */
303
- type HttpPathParamsSerialized<Type> = Type extends HttpPathParamsSchema ? Type : Type extends (infer _ArrayItem)[] ? never : Type extends Date ? never : Type extends (...parameters: never[]) => unknown ? never : Type extends symbol ? never : Type extends Map<infer _Key, infer _Value> ? never : Type extends Set<infer _Value> ? never : Type extends object ? {
308
+ type HttpPathParamsSerialized<Type> = [Type] extends [never] ? never : Type extends HttpPathParamsSchema ? Type : Type extends object ? {
304
309
  [Key in keyof Type as IfNever<PrimitiveHttpPathParamsSerialized<Type[Key]>, never, Key>]: PrimitiveHttpPathParamsSerialized<Type[Key]>;
305
310
  } : never;
306
311
 
@@ -313,11 +318,11 @@ declare namespace HttpHeadersSchema {
313
318
  type Loose = Record<string, any>;
314
319
  }
315
320
  /** A strict tuple representation of a {@link HttpHeadersSchema}. */
316
- type HttpHeadersSchemaTuple<Schema extends HttpHeadersSchema = HttpHeadersSchema> = {
321
+ type HttpHeadersSchemaTuple<Schema extends HttpHeadersSchema.Loose = HttpHeadersSchema.Loose> = {
317
322
  [Key in keyof Schema & string]: [Key, NonNullable<Schema[Key]>];
318
323
  }[keyof Schema & string];
319
324
  /** 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>[];
325
+ type HttpHeadersInit<Schema extends HttpHeadersSchema.Loose = HttpHeadersSchema.Loose> = Headers | Schema | HttpHeaders<Schema> | HttpHeadersSchemaTuple<Schema>[];
321
326
  /**
322
327
  * Extracts the names of the headers defined in a {@link HttpHeadersSchema}. Each key is considered a header name.
323
328
  *
@@ -359,9 +364,6 @@ type HttpHeadersSerialized<Type> = HttpPathParamsSerialized<Type>;
359
364
  * An extended HTTP headers object with a strictly-typed schema. Fully compatible with the built-in
360
365
  * {@link https://developer.mozilla.org/docs/Web/API/Headers `Headers`} class.
361
366
  *
362
- * **IMPORTANT**: the input of `HttpHeaders` and all of its internal types must be declared inline or as a type aliases
363
- * (`type`). They cannot be interfaces.
364
- *
365
367
  * @example
366
368
  * import { HttpHeaders } from '@zimic/http';
367
369
  *
@@ -378,33 +380,34 @@ type HttpHeadersSerialized<Type> = HttpPathParamsSerialized<Type>;
378
380
  *
379
381
  * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http#httpheaders `HttpHeaders` API reference}
380
382
  */
381
- declare class HttpHeaders<Schema extends HttpHeadersSchema = HttpHeadersSchema> extends Headers {
382
- constructor(init?: HttpHeadersInit<Schema>);
383
+ declare class HttpHeaders<LooseSchema extends HttpHeadersSchema.Loose = HttpHeadersSchema.Loose> extends Headers {
384
+ readonly _schema: HttpHeadersSerialized<LooseSchema>;
385
+ constructor(init?: HttpHeadersInit<LooseSchema>);
383
386
  /** @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;
387
+ set<Name extends HttpHeadersSchemaName<this['_schema']>>(name: Name, value: NonNullable<LooseSchema[Name]>): void;
385
388
  /** @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;
389
+ append<Name extends HttpHeadersSchemaName<this['_schema']>>(name: Name, value: NonNullable<LooseSchema[Name]>): void;
387
390
  /** @see {@link https://developer.mozilla.org/docs/Web/API/Headers/get MDN Reference} */
388
- get<Name extends HttpHeadersSchemaName<Schema>>(name: Name): ReplaceBy<Schema[Name], undefined, null>;
391
+ get<Name extends HttpHeadersSchemaName<this['_schema']>>(name: Name): ReplaceBy<this['_schema'][Name], undefined, null>;
389
392
  /** @see {@link https://developer.mozilla.org/docs/Web/API/Headers/has MDN Reference} */
390
- getSetCookie(): NonNullable<Default<Schema['Set-Cookie'], string>>[];
393
+ getSetCookie(): NonNullable<Default<this['_schema']['Set-Cookie'], string>>[];
391
394
  /** @see {@link https://developer.mozilla.org/docs/Web/API/Headers/has MDN Reference} */
392
- has<Name extends HttpHeadersSchemaName<Schema>>(name: Name): boolean;
395
+ has<Name extends HttpHeadersSchemaName<this['_schema']>>(name: Name): boolean;
393
396
  /** @see {@link https://developer.mozilla.org/docs/Web/API/Headers/delete MDN Reference} */
394
- delete<Name extends HttpHeadersSchemaName<Schema>>(name: Name): void;
395
- forEach<This extends HttpHeaders<Schema>>(callback: <Key extends HttpHeadersSchemaName<Schema>>(value: NonNullable<Schema[Key]> & string, key: Key, parent: Headers) => void, thisArg?: This): void;
397
+ delete<Name extends HttpHeadersSchemaName<this['_schema']>>(name: Name): void;
398
+ forEach<This extends HttpHeaders<this['_schema']>>(callback: <Key extends HttpHeadersSchemaName<this['_schema']>>(value: NonNullable<this['_schema'][Key]> & string, key: Key, parent: Headers) => void, thisArg?: This): void;
396
399
  /** @see {@link https://developer.mozilla.org/docs/Web/API/Headers/keys MDN Reference} */
397
- keys(): HeadersIterator<HttpHeadersSchemaName<Schema>>;
400
+ keys(): HeadersIterator<HttpHeadersSchemaName<this['_schema']>>;
398
401
  /** @see {@link https://developer.mozilla.org/docs/Web/API/Headers/values MDN Reference} */
399
- values(): HeadersIterator<NonNullable<Schema[HttpHeadersSchemaName<Schema>]> & string>;
402
+ values(): HeadersIterator<NonNullable<this['_schema'][HttpHeadersSchemaName<this['_schema']>]> & string>;
400
403
  /** @see {@link https://developer.mozilla.org/docs/Web/API/Headers/entries MDN Reference} */
401
404
  entries(): HeadersIterator<[
402
- HttpHeadersSchemaName<Schema>,
403
- NonNullable<Schema[HttpHeadersSchemaName<Schema>]> & string
405
+ HttpHeadersSchemaName<this['_schema']>,
406
+ NonNullable<this['_schema'][HttpHeadersSchemaName<this['_schema']>]> & string
404
407
  ]>;
405
408
  [Symbol.iterator](): HeadersIterator<[
406
- HttpHeadersSchemaName<Schema>,
407
- NonNullable<Schema[HttpHeadersSchemaName<Schema>]> & string
409
+ HttpHeadersSchemaName<this['_schema']>,
410
+ NonNullable<this['_schema'][HttpHeadersSchemaName<this['_schema']>]> & string
408
411
  ]>;
409
412
  /**
410
413
  * Checks if this headers object is equal to another set of headers. Equality is defined as having the same keys and
@@ -413,7 +416,7 @@ declare class HttpHeaders<Schema extends HttpHeadersSchema = HttpHeadersSchema>
413
416
  * @param otherHeaders The other headers object to compare against.
414
417
  * @returns `true` if the headers are equal, `false` otherwise.
415
418
  */
416
- equals<OtherSchema extends Schema>(otherHeaders: HttpHeaders<OtherSchema>): boolean;
419
+ equals<OtherSchema extends LooseSchema>(otherHeaders: HttpHeaders<OtherSchema>): boolean;
417
420
  /**
418
421
  * Checks if this headers object contains another set of headers. This method is less strict than
419
422
  * {@link HttpHeaders#equals} and only requires that all keys and values in the other headers are present in these
@@ -422,7 +425,7 @@ declare class HttpHeaders<Schema extends HttpHeadersSchema = HttpHeadersSchema>
422
425
  * @param otherHeaders The other headers object to compare against.
423
426
  * @returns `true` if these headers contain the other headers, `false` otherwise.
424
427
  */
425
- contains<OtherSchema extends Schema>(otherHeaders: HttpHeaders<OtherSchema>): boolean;
428
+ contains<OtherSchema extends LooseSchema>(otherHeaders: HttpHeaders<OtherSchema>): boolean;
426
429
  /**
427
430
  * Converts these headers into a plain object. This method is useful for serialization and debugging purposes.
428
431
  *
@@ -436,7 +439,7 @@ declare class HttpHeaders<Schema extends HttpHeadersSchema = HttpHeadersSchema>
436
439
  *
437
440
  * @returns A plain object representation of these headers.
438
441
  */
439
- toObject(): Schema;
442
+ toObject(): this['_schema'];
440
443
  private splitHeaderValues;
441
444
  }
442
445
 
@@ -449,14 +452,14 @@ declare namespace HttpSearchParamsSchema {
449
452
  type Loose = Record<string, any>;
450
453
  }
451
454
  /** A strict tuple representation of a {@link HttpSearchParamsSchema}. */
452
- type HttpSearchParamsSchemaTuple<Schema extends HttpSearchParamsSchema = HttpSearchParamsSchema> = {
455
+ type HttpSearchParamsSchemaTuple<Schema extends HttpSearchParamsSchema.Loose = HttpSearchParamsSchema.Loose> = {
453
456
  [Key in keyof Schema & string]: [Key, ArrayItemIfArray<NonNullable<Schema[Key]>>];
454
457
  }[keyof Schema & string];
455
458
  /**
456
459
  * An initialization value for
457
460
  * {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http#httpsearchparams `HttpSearchParams`}.
458
461
  */
459
- type HttpSearchParamsInit<Schema extends HttpSearchParamsSchema = HttpSearchParamsSchema> = string | URLSearchParams | Schema | HttpSearchParams<Schema> | HttpSearchParamsSchemaTuple<Schema>[];
462
+ type HttpSearchParamsInit<Schema extends HttpSearchParamsSchema.Loose = HttpSearchParamsSchema.Loose> = string | URLSearchParams | Schema | HttpSearchParams<Schema> | HttpSearchParamsSchemaTuple<Schema>[];
460
463
  declare namespace HttpSearchParamsSchemaName {
461
464
  /** Extracts the names of the search params defined in a {@link HttpSearchParamsSchema} that are arrays. */
462
465
  type Array<Schema extends HttpSearchParamsSchema> = IfNever<Schema, never, ArrayKey<Schema> & string>;
@@ -493,30 +496,30 @@ declare namespace HttpSearchParamsSchemaName {
493
496
  * // "page" | "perPage"
494
497
  */
495
498
  type HttpSearchParamsSchemaName<Schema extends HttpSearchParamsSchema> = IfNever<Schema, never, keyof Schema & string>;
496
- type PrimitiveHttpSearchParamsSerialized<Type> = Type extends HttpSearchParamsSchema[string] ? Type : Type extends (infer ArrayItem)[] ? ArrayItem extends (infer _InternalArrayItem)[] ? never : PrimitiveHttpSearchParamsSerialized<ArrayItem>[] : Type extends number ? `${number}` : Type extends boolean ? `${boolean}` : Type extends null ? undefined : never;
499
+ type PrimitiveHttpSearchParamsSerialized<Type> = [Type] extends [never] ? never : Type extends number ? `${number}` : Type extends boolean ? `${boolean}` : Type extends null ? 'null' : Type extends symbol ? never : Type extends HttpSearchParamsSchema[string] ? Type : Type extends (infer ArrayItem)[] ? ArrayItem extends (infer _InternalArrayItem)[] ? string : PrimitiveHttpSearchParamsSerialized<ArrayItem>[] : string;
497
500
  /**
498
501
  * Recursively converts a schema to its
499
- * {@link https://developer.mozilla.org/docs/Web/API/URLSearchParams URLSearchParams}-serialized version. Numbers and
500
- * booleans are converted to `${number}` and `${boolean}` respectively, null becomes undefined and not serializable
501
- * values are excluded, such as functions and dates.
502
+ * {@link https://developer.mozilla.org/docs/Web/API/URLSearchParams URLSearchParams}-serialized version. Numbers,
503
+ * booleans, and null are converted to `${number}`, `${boolean}`, and 'null' respectively, and other values become
504
+ * strings.
502
505
  *
503
506
  * @example
504
507
  * import { type HttpSearchParamsSerialized } from '@zimic/http';
505
508
  *
506
509
  * type Params = HttpSearchParamsSerialized<{
507
- * query: string | null;
510
+ * query?: string;
511
+ * order: 'asc' | 'desc' | null;
508
512
  * page?: number;
509
513
  * full?: boolean;
510
- * date: Date;
511
- * method: () => void;
512
514
  * }>;
513
515
  * // {
514
- * // query: string | undefined;
516
+ * // query?: string;
517
+ * // order: 'asc' | 'desc' | 'null';
515
518
  * // page?: `${number}`;
516
519
  * // full?: "false" | "true";
517
520
  * // }
518
521
  */
519
- type HttpSearchParamsSerialized<Type> = Type extends HttpSearchParamsSchema ? Type : Type extends (infer _ArrayItem)[] ? never : Type extends Date ? never : Type extends (...parameters: never[]) => unknown ? never : Type extends symbol ? never : Type extends Map<infer _Key, infer _Value> ? never : Type extends Set<infer _Value> ? never : Type extends object ? {
522
+ type HttpSearchParamsSerialized<Type> = [Type] extends [never] ? never : Type extends HttpSearchParamsSchema ? Type : Type extends object ? {
520
523
  [Key in keyof Type as IfNever<PrimitiveHttpSearchParamsSerialized<Type[Key]>, never, Key>]: PrimitiveHttpSearchParamsSerialized<Type[Key]>;
521
524
  } : never;
522
525
 
@@ -524,9 +527,6 @@ type HttpSearchParamsSerialized<Type> = Type extends HttpSearchParamsSchema ? Ty
524
527
  * An extended HTTP search params object with a strictly-typed schema. Fully compatible with the built-in
525
528
  * {@link https://developer.mozilla.org/docs/Web/API/URLSearchParams `URLSearchParams`} class.
526
529
  *
527
- * **IMPORTANT**: the input of `HttpSearchParams` and all of its internal types must be declared inline or as a type
528
- * aliases (`type`). They cannot be interfaces.
529
- *
530
530
  * @example
531
531
  * import { HttpSearchParams } from '@zimic/http';
532
532
  *
@@ -546,13 +546,14 @@ type HttpSearchParamsSerialized<Type> = Type extends HttpSearchParamsSchema ? Ty
546
546
  *
547
547
  * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http#httpsearchparams `HttpSearchParams` API reference}
548
548
  */
549
- declare class HttpSearchParams<Schema extends HttpSearchParamsSchema = HttpSearchParamsSchema> extends URLSearchParams {
550
- constructor(init?: HttpSearchParamsInit<Schema>);
549
+ declare class HttpSearchParams<LooseSchema extends HttpSearchParamsSchema.Loose = HttpSearchParamsSchema.Loose> extends URLSearchParams {
550
+ readonly _schema: HttpSearchParamsSerialized<LooseSchema>;
551
+ constructor(init?: HttpSearchParamsInit<LooseSchema>);
551
552
  private populateInitArrayProperties;
552
553
  /** @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;
554
+ set<Name extends HttpSearchParamsSchemaName<this['_schema']>>(name: Name, value: ArrayItemIfArray<NonNullable<LooseSchema[Name]>>): void;
554
555
  /** @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;
556
+ append<Name extends HttpSearchParamsSchemaName<this['_schema']>>(name: Name, value: ArrayItemIfArray<NonNullable<LooseSchema[Name]>>): void;
556
557
  /**
557
558
  * Get the value of the entry associated to a key name.
558
559
  *
@@ -562,7 +563,7 @@ declare class HttpSearchParams<Schema extends HttpSearchParamsSchema = HttpSearc
562
563
  * @returns The value associated with the key name, or `null` if the key does not exist.
563
564
  * @see {@link https://developer.mozilla.org/docs/Web/API/URLSearchParams/get MDN Reference}
564
565
  */
565
- get<Name extends HttpSearchParamsSchemaName.NonArray<Schema>>(name: Name): ReplaceBy<ArrayItemIfArray<Schema[Name]>, undefined, null>;
566
+ get<Name extends HttpSearchParamsSchemaName.NonArray<this['_schema']>>(name: Name): ReplaceBy<ArrayItemIfArray<this['_schema'][Name]>, undefined, null>;
566
567
  /**
567
568
  * Get all the values of the entry associated with a key name.
568
569
  *
@@ -572,24 +573,24 @@ declare class HttpSearchParams<Schema extends HttpSearchParamsSchema = HttpSearc
572
573
  * @returns An array of values associated with the key name, or an empty array if the key does not exist.
573
574
  * @see {@link https://developer.mozilla.org/docs/Web/API/URLSearchParams/getAll MDN Reference}
574
575
  */
575
- getAll<Name extends HttpSearchParamsSchemaName.Array<Schema>>(name: Name): ArrayItemIfArray<NonNullable<Schema[Name]>>[];
576
+ getAll<Name extends HttpSearchParamsSchemaName.Array<this['_schema']>>(name: Name): ArrayItemIfArray<NonNullable<this['_schema'][Name]>>[];
576
577
  /** @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;
578
+ has<Name extends HttpSearchParamsSchemaName<this['_schema']>>(name: Name, value?: ArrayItemIfArray<NonNullable<LooseSchema[Name]>>): boolean;
578
579
  /** @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;
580
- forEach<This extends HttpSearchParams<Schema>>(callback: <Key extends HttpSearchParamsSchemaName<Schema>>(value: ArrayItemIfArray<NonNullable<Schema[Key]>>, key: Key, parent: HttpSearchParams<Schema>) => void, thisArg?: This): void;
580
+ delete<Name extends HttpSearchParamsSchemaName<this['_schema']>>(name: Name, value?: ArrayItemIfArray<NonNullable<LooseSchema[Name]>>): void;
581
+ forEach<This extends HttpSearchParams<this['_schema']>>(callback: <Key extends HttpSearchParamsSchemaName<this['_schema']>>(value: ArrayItemIfArray<NonNullable<this['_schema'][Key]>>, key: Key, parent: HttpSearchParams<this['_schema']>) => void, thisArg?: This): void;
581
582
  /** @see {@link https://developer.mozilla.org/docs/Web/API/URLSearchParams/keys MDN Reference} */
582
- keys(): URLSearchParamsIterator<HttpSearchParamsSchemaName<Schema>>;
583
+ keys(): URLSearchParamsIterator<HttpSearchParamsSchemaName<this['_schema']>>;
583
584
  /** @see {@link https://developer.mozilla.org/docs/Web/API/URLSearchParams/values MDN Reference} */
584
- values(): URLSearchParamsIterator<ArrayItemIfArray<NonNullable<Schema[HttpSearchParamsSchemaName<Schema>]>>>;
585
+ values(): URLSearchParamsIterator<ArrayItemIfArray<NonNullable<this['_schema'][HttpSearchParamsSchemaName<this['_schema']>]>>>;
585
586
  /** @see {@link https://developer.mozilla.org/docs/Web/API/URLSearchParams/entries MDN Reference} */
586
587
  entries(): URLSearchParamsIterator<[
587
- HttpSearchParamsSchemaName<Schema>,
588
- ArrayItemIfArray<NonNullable<Schema[HttpSearchParamsSchemaName<Schema>]>>
588
+ HttpSearchParamsSchemaName<this['_schema']>,
589
+ ArrayItemIfArray<NonNullable<this['_schema'][HttpSearchParamsSchemaName<this['_schema']>]>>
589
590
  ]>;
590
591
  [Symbol.iterator](): URLSearchParamsIterator<[
591
- HttpSearchParamsSchemaName<Schema>,
592
- ArrayItemIfArray<NonNullable<Schema[HttpSearchParamsSchemaName<Schema>]>>
592
+ HttpSearchParamsSchemaName<this['_schema']>,
593
+ ArrayItemIfArray<NonNullable<this['_schema'][HttpSearchParamsSchemaName<this['_schema']>]>>
593
594
  ]>;
594
595
  /**
595
596
  * Checks if these search params are equal to another set of search parameters. Equality is defined as having the same
@@ -598,7 +599,7 @@ declare class HttpSearchParams<Schema extends HttpSearchParamsSchema = HttpSearc
598
599
  * @param otherParams The other search parameters to compare against.
599
600
  * @returns `true` if the search parameters are equal, `false` otherwise.
600
601
  */
601
- equals<OtherSchema extends Schema>(otherParams: HttpSearchParams<OtherSchema>): boolean;
602
+ equals<OtherSchema extends LooseSchema>(otherParams: HttpSearchParams<OtherSchema>): boolean;
602
603
  /**
603
604
  * Checks if these search params contain another set of search parameters. This method is less strict than
604
605
  * {@link HttpSearchParams#equals} and only requires that all keys and values in the other search parameters are
@@ -607,7 +608,7 @@ declare class HttpSearchParams<Schema extends HttpSearchParamsSchema = HttpSearc
607
608
  * @param otherParams The other search parameters to check for containment.
608
609
  * @returns `true` if these search parameters contain the other search parameters, `false` otherwise.
609
610
  */
610
- contains<OtherSchema extends Schema>(otherParams: HttpSearchParams<OtherSchema>): boolean;
611
+ contains<OtherSchema extends LooseSchema>(otherParams: HttpSearchParams<OtherSchema>): boolean;
611
612
  /**
612
613
  * Converts these search params into a plain object. This method is useful for serialization and debugging purposes.
613
614
  *
@@ -626,7 +627,7 @@ declare class HttpSearchParams<Schema extends HttpSearchParamsSchema = HttpSearc
626
627
  *
627
628
  * @returns A plain object representation of these search params.
628
629
  */
629
- toObject(): Schema;
630
+ toObject(): this["_schema"];
630
631
  }
631
632
 
632
633
  declare const HTTP_METHODS: readonly ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"];
@@ -645,12 +646,6 @@ interface HttpRequestSchema {
645
646
  searchParams?: HttpSearchParamsSchema.Loose;
646
647
  body?: HttpBody.Loose;
647
648
  }
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
649
  /**
655
650
  * A schema representing the structure of an HTTP response.
656
651
  *
@@ -660,14 +655,6 @@ interface HttpResponseSchema {
660
655
  headers?: HttpHeadersSchema.Loose;
661
656
  body?: HttpBody.Loose;
662
657
  }
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
658
  /**
672
659
  * The status codes used in HTTP responses, as defined by
673
660
  * {@link https://httpwg.org/specs/rfc9110.html#overview.of.status.codes RFC-9110}.
@@ -716,21 +703,9 @@ declare namespace HttpStatusCode {
716
703
  *
717
704
  * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http‐schemas Declaring HTTP interceptor schemas}
718
705
  */
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
- }
706
+ type HttpResponseSchemaByStatusCode = {
707
+ [StatusCode in HttpStatusCode]?: HttpResponseSchema;
708
+ };
734
709
  /**
735
710
  * Extracts the status codes used in a response schema by status code.
736
711
  *
@@ -746,44 +721,19 @@ interface HttpMethodSchema {
746
721
  request?: HttpRequestSchema;
747
722
  response?: HttpResponseSchemaByStatusCode;
748
723
  }
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
724
  /**
769
725
  * A schema representing the structure of HTTP request and response by method.
770
726
  *
771
727
  * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http‐schemas Declaring HTTP interceptor schemas}
772
728
  */
773
729
  interface HttpMethodsSchema {
774
- GET?: HttpMethodSchema.NoRequestBody;
730
+ GET?: HttpMethodSchema;
775
731
  POST?: HttpMethodSchema;
776
732
  PUT?: HttpMethodSchema;
777
733
  PATCH?: HttpMethodSchema;
778
734
  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
- };
735
+ HEAD?: HttpMethodSchema;
736
+ OPTIONS?: HttpMethodSchema;
787
737
  }
788
738
  interface BaseHttpSchema {
789
739
  [path: string]: HttpMethodsSchema;
@@ -800,7 +750,7 @@ interface BaseHttpSchema {
800
750
  *
801
751
  * interface UserListSearchParams {
802
752
  * name?: string;
803
- * limit?: `${number}`;
753
+ * limit?: number;
804
754
  * }
805
755
  *
806
756
  * type Schema = HttpSchema<{
@@ -823,12 +773,8 @@ interface BaseHttpSchema {
823
773
  *
824
774
  * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http‐schemas Declaring HTTP interceptor schemas}
825
775
  */
826
- type HttpSchema<Schema extends BaseHttpSchema = BaseHttpSchema> = HttpSchema.AsStrict<Schema>;
776
+ type HttpSchema<Schema extends BaseHttpSchema = BaseHttpSchema> = Branded<Schema, 'HttpSchema'>;
827
777
  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
778
  /**
833
779
  * Declares an HTTP service methods schema.
834
780
  *
@@ -847,7 +793,7 @@ declare namespace HttpSchema {
847
793
  * '/users': UserMethods;
848
794
  * }>;
849
795
  */
850
- type Methods<Schema extends HttpMethodsSchema> = HttpMethodsSchema.AsStrict<Schema>;
796
+ type Methods<Schema extends HttpMethodsSchema> = Schema;
851
797
  /**
852
798
  * Declares an HTTP service method schema.
853
799
  *
@@ -866,7 +812,7 @@ declare namespace HttpSchema {
866
812
  * };
867
813
  * }>;
868
814
  */
869
- type Method<Schema extends HttpMethodSchema> = HttpMethodSchema.AsStrict<Schema>;
815
+ type Method<Schema extends HttpMethodSchema> = Schema;
870
816
  /**
871
817
  * Declares an HTTP service request schema.
872
818
  *
@@ -889,7 +835,7 @@ declare namespace HttpSchema {
889
835
  * };
890
836
  * }>;
891
837
  */
892
- type Request<Schema extends HttpRequestSchema> = HttpRequestSchema.AsStrict<Schema>;
838
+ type Request<Schema extends HttpRequestSchema> = Schema;
893
839
  /**
894
840
  * Declares an HTTP service response schema by status code.
895
841
  *
@@ -909,7 +855,7 @@ declare namespace HttpSchema {
909
855
  * };
910
856
  * }>;
911
857
  */
912
- type ResponseByStatusCode<Schema extends HttpResponseSchemaByStatusCode> = HttpResponseSchemaByStatusCode.AsStrict<Schema>;
858
+ type ResponseByStatusCode<Schema extends HttpResponseSchemaByStatusCode> = Schema;
913
859
  /**
914
860
  * Declares an HTTP service response schema.
915
861
  *
@@ -930,10 +876,9 @@ declare namespace HttpSchema {
930
876
  * };
931
877
  * }>;
932
878
  */
933
- type Response<Schema extends HttpResponseSchema> = HttpResponseSchema.AsStrict<Schema>;
879
+ type Response<Schema extends HttpResponseSchema> = Schema;
934
880
  /**
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.
881
+ * Declares an HTTP body schema.
937
882
  *
938
883
  * @example
939
884
  * import { type HttpSchema } from '@zimic/http';
@@ -950,11 +895,9 @@ declare namespace HttpSchema {
950
895
  * };
951
896
  * }>;
952
897
  */
953
- type Body<Schema extends HttpBody.Loose> = HttpBody.AsStrict<Schema>;
898
+ type Body<Schema extends HttpBody.Loose> = Schema;
954
899
  /**
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.
900
+ * Declares an HTTP headers schema.
958
901
  *
959
902
  * @example
960
903
  * import { type HttpSchema } from '@zimic/http';
@@ -976,11 +919,9 @@ declare namespace HttpSchema {
976
919
  * };
977
920
  * }>;
978
921
  */
979
- type Headers<Schema extends HttpHeadersSchema.Loose> = HttpHeadersSerialized<Schema>;
922
+ type Headers<Schema extends HttpHeadersSchema.Loose> = Schema;
980
923
  /**
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.
924
+ * Declares an HTTP search params schema.
984
925
  *
985
926
  * @example
986
927
  * import { type HttpSchema } from '@zimic/http';
@@ -1003,10 +944,9 @@ declare namespace HttpSchema {
1003
944
  * };
1004
945
  * }>;
1005
946
  */
1006
- type SearchParams<Schema extends HttpSearchParamsSchema.Loose> = HttpSearchParamsSerialized<Schema>;
947
+ type SearchParams<Schema extends HttpSearchParamsSchema.Loose> = Schema;
1007
948
  /**
1008
- * Declares an HTTP path params schema. Path params are serialized to their strict form using
1009
- * {@link HttpPathParamsSerialized} if necessary.
949
+ * Declares an HTTP path params schema.
1010
950
  *
1011
951
  * @example
1012
952
  * import { type HttpSchema, InferPathParams } from '@zimic/http';
@@ -1028,11 +968,9 @@ declare namespace HttpSchema {
1028
968
  * // Or infer from the path string
1029
969
  * type UserByIdPathParams = InferPathParams<Schema, '/users/:userId'>;
1030
970
  */
1031
- type PathParams<Schema extends HttpPathParamsSchema.Loose> = HttpPathParamsSerialized<Schema>;
971
+ type PathParams<Schema extends HttpPathParamsSchema.Loose> = Schema;
1032
972
  /**
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.
973
+ * Declares an HTTP form data schema.
1036
974
  *
1037
975
  * @example
1038
976
  * import { HttpFormData, type HttpSchema } from '@zimic/http';
@@ -1057,7 +995,7 @@ declare namespace HttpSchema {
1057
995
  * };
1058
996
  * }>;
1059
997
  */
1060
- type FormData<Schema extends HttpFormDataSchema.Loose> = HttpFormDataSerialized<Schema>;
998
+ type FormData<Schema extends HttpFormDataSchema.Loose> = Schema;
1061
999
  }
1062
1000
  /**
1063
1001
  * Extracts the methods from an HTTP service schema.
@@ -1200,11 +1138,7 @@ type RecursiveInferPathParams<Path extends string> = Path extends `${infer _Pref
1200
1138
  * // { userId: string }
1201
1139
  */
1202
1140
  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;
1141
+ type OmitPastHttpStatusCodes<Schema extends HttpResponseSchemaByStatusCode, PastSchemas extends HttpResponseSchemaByStatusCode[]> = PastSchemas extends NonEmptyArray<HttpResponseSchemaByStatusCode> ? Omit<Schema, keyof UnionToIntersection<PastSchemas[number]>> : Schema;
1208
1142
  /**
1209
1143
  * Merges multiple HTTP response schemas by status code into a single schema. When there are duplicate status codes, the
1210
1144
  * first declaration takes precedence.
@@ -1238,36 +1172,37 @@ type RecursiveMergeHttpResponsesByStatusCode<Schemas extends HttpResponseSchemaB
1238
1172
  * };
1239
1173
  * }>;
1240
1174
  */
1241
- type MergeHttpResponsesByStatusCode<Schemas extends HttpResponseSchemaByStatusCode.Loose[], PastSchemas extends HttpResponseSchemaByStatusCode.Loose[] = []> = HttpResponseSchemaByStatusCode.AsStrict<RecursiveMergeHttpResponsesByStatusCode<Schemas, PastSchemas>>;
1175
+ type MergeHttpResponsesByStatusCode<Schemas extends HttpResponseSchemaByStatusCode[], PastSchemas extends HttpResponseSchemaByStatusCode[] = []> = Schemas extends [
1176
+ infer FirstSchema extends HttpResponseSchemaByStatusCode,
1177
+ ...infer RestSchemas extends HttpResponseSchemaByStatusCode[]
1178
+ ] ? RestSchemas extends NonEmptyArray<HttpResponseSchemaByStatusCode> ? OmitPastHttpStatusCodes<FirstSchema, PastSchemas> & MergeHttpResponsesByStatusCode<RestSchemas, [...PastSchemas, FirstSchema]> : OmitPastHttpStatusCodes<FirstSchema, PastSchemas> : never;
1242
1179
 
1243
1180
  /** The body type for HTTP requests and responses. */
1244
1181
  type HttpBody = JSONValue | HttpFormData<any> | HttpSearchParams<any> | Blob | ArrayBuffer;
1245
1182
  declare namespace HttpBody {
1246
1183
  /** A loose version of the HTTP body type. JSON values are not strictly typed. */
1247
1184
  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
1185
  }
1251
1186
  /**
1252
1187
  * An HTTP headers object with a strictly-typed schema. Fully compatible with the built-in
1253
1188
  * {@link https://developer.mozilla.org/docs/Web/API/Headers `Headers`} class.
1254
1189
  */
1255
- type StrictHeaders<Schema extends HttpHeadersSchema = HttpHeadersSchema> = Pick<HttpHeaders<Schema>, keyof Headers>;
1190
+ type StrictHeaders<Schema extends HttpHeadersSchema.Loose = HttpHeadersSchema.Loose> = Pick<HttpHeaders<Schema>, keyof Headers>;
1256
1191
  /**
1257
1192
  * An HTTP search params object with a strictly-typed schema. Fully compatible with the built-in
1258
1193
  * {@link https://developer.mozilla.org/docs/Web/API/URLSearchParams `URLSearchParams`} class.
1259
1194
  */
1260
- type StrictURLSearchParams<Schema extends HttpSearchParamsSchema = HttpSearchParamsSchema> = Pick<HttpSearchParams<Schema>, keyof URLSearchParams>;
1195
+ type StrictURLSearchParams<Schema extends HttpSearchParamsSchema.Loose = HttpSearchParamsSchema.Loose> = Pick<HttpSearchParams<Schema>, keyof URLSearchParams>;
1261
1196
  /**
1262
1197
  * An HTTP form data object with a strictly-typed schema. Fully compatible with the built-in
1263
1198
  * {@link https://developer.mozilla.org/docs/Web/API/FormData `FormData`} class.
1264
1199
  */
1265
- type StrictFormData<Schema extends HttpFormDataSchema = HttpFormDataSchema> = Pick<HttpFormData<Schema>, keyof FormData>;
1200
+ type StrictFormData<Schema extends HttpFormDataSchema.Loose = HttpFormDataSchema.Loose> = Pick<HttpFormData<Schema>, keyof FormData>;
1266
1201
  /**
1267
1202
  * An HTTP request with a strictly-typed JSON body. Fully compatible with the built-in
1268
1203
  * {@link https://developer.mozilla.org/docs/Web/API/Request `Request`} class.
1269
1204
  */
1270
- interface HttpRequest<StrictBody extends HttpBody.Loose = HttpBody, StrictHeadersSchema extends HttpHeadersSchema = HttpHeadersSchema> extends Request {
1205
+ interface HttpRequest<StrictBody extends HttpBody.Loose = HttpBody.Loose, StrictHeadersSchema extends HttpHeadersSchema.Loose = HttpHeadersSchema.Loose> extends Request {
1271
1206
  headers: StrictHeaders<StrictHeadersSchema>;
1272
1207
  text: () => Promise<StrictBody extends string ? StrictBody : string>;
1273
1208
  json: () => Promise<StrictBody extends string | Exclude<HttpBody, JSONValue> ? never : StrictBody>;
@@ -1278,7 +1213,7 @@ interface HttpRequest<StrictBody extends HttpBody.Loose = HttpBody, StrictHeader
1278
1213
  * An HTTP response with a strictly-typed JSON body and status code. Fully compatible with the built-in
1279
1214
  * {@link https://developer.mozilla.org/docs/Web/API/Response `Response`} class.
1280
1215
  */
1281
- interface HttpResponse<StrictBody extends HttpBody.Loose = HttpBody, StatusCode extends number = number, StrictHeadersSchema extends HttpHeadersSchema = HttpHeadersSchema> extends Response {
1216
+ interface HttpResponse<StrictBody extends HttpBody.Loose = HttpBody.Loose, StrictHeadersSchema extends HttpHeadersSchema.Loose = HttpHeadersSchema.Loose, StatusCode extends number = number> extends Response {
1282
1217
  ok: StatusCode extends HttpStatusCode.Information | HttpStatusCode.Success | HttpStatusCode.Redirection ? true : false;
1283
1218
  status: StatusCode;
1284
1219
  headers: StrictHeaders<StrictHeadersSchema>;
@@ -1287,10 +1222,20 @@ interface HttpResponse<StrictBody extends HttpBody.Loose = HttpBody, StatusCode
1287
1222
  formData: () => Promise<StrictBody extends HttpFormData<infer HttpFormDataSchema> ? StrictFormData<HttpFormDataSchema> : StrictBody extends HttpSearchParams<infer HttpSearchParamsSchema> ? StrictFormData<HttpSearchParamsSchema> : FormData>;
1288
1223
  clone: () => this;
1289
1224
  }
1290
- type HttpRequestHeadersSchema<MethodSchema extends HttpMethodSchema> = Default<Default<MethodSchema['request']>['headers']>;
1291
- type HttpRequestSearchParamsSchema<MethodSchema extends HttpMethodSchema> = Default<Default<MethodSchema['request']>['searchParams']>;
1225
+ type HttpRequestHeadersSchemaFromBody<RequestSchema extends HttpRequestSchema, DefaultHeadersSchema> = 'body' extends keyof RequestSchema ? [RequestSchema['body']] extends [never] ? DefaultHeadersSchema : [Extract<RequestSchema['body'], BodyInit | HttpFormData | HttpSearchParams>] extends [never] ? 'headers' extends keyof RequestSchema ? [RequestSchema['headers']] extends [never] ? DefaultHeadersSchema : 'content-type' extends keyof Default<RequestSchema['headers']> ? DefaultHeadersSchema : {
1226
+ 'content-type': 'application/json';
1227
+ } : {
1228
+ 'content-type': 'application/json';
1229
+ } : DefaultHeadersSchema : DefaultHeadersSchema;
1230
+ type HttpRequestHeadersSchema<MethodSchema extends HttpMethodSchema> = 'headers' extends keyof MethodSchema['request'] ? [MethodSchema['request']['headers']] extends [never] ? HttpRequestHeadersSchemaFromBody<Default<MethodSchema['request']>, never> : (MethodSchema['request']['headers'] & HttpRequestHeadersSchemaFromBody<Default<MethodSchema['request']>, {}>) | (MethodSchema['request']['headers'] & undefined) : HttpRequestHeadersSchemaFromBody<Default<MethodSchema['request']>, never>;
1231
+ type HttpRequestSearchParamsSchema<MethodSchema extends HttpMethodSchema> = 'searchParams' extends keyof MethodSchema['request'] ? Default<MethodSchema['request']>['searchParams'] : never;
1292
1232
  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']>>;
1233
+ type HttpResponseHeadersSchemaFromBody<ResponseSchema extends HttpResponseSchema, DefaultHeadersSchema> = 'body' extends keyof ResponseSchema ? [ResponseSchema['body']] extends [never] ? DefaultHeadersSchema : [Extract<ResponseSchema['body'], BodyInit | HttpSearchParams | HttpFormData>] extends [never] ? 'headers' extends keyof ResponseSchema ? [ResponseSchema['headers']] extends [never] ? DefaultHeadersSchema : 'content-type' extends keyof Default<ResponseSchema['headers']> ? DefaultHeadersSchema : {
1234
+ 'content-type': 'application/json';
1235
+ } : {
1236
+ 'content-type': 'application/json';
1237
+ } : DefaultHeadersSchema : DefaultHeadersSchema;
1238
+ type HttpResponseHeadersSchema<MethodSchema extends HttpMethodSchema, StatusCode extends HttpStatusCode> = 'headers' extends keyof Default<MethodSchema['response']>[StatusCode] ? [Default<MethodSchema['response']>[StatusCode]] extends [never] ? HttpResponseHeadersSchemaFromBody<Default<Default<MethodSchema['response']>[StatusCode]>, never> : Default<Default<MethodSchema['response']>[StatusCode]>['headers'] & HttpResponseHeadersSchemaFromBody<Default<Default<MethodSchema['response']>[StatusCode]>, {}> : HttpResponseHeadersSchemaFromBody<Default<Default<MethodSchema['response']>[StatusCode]>, never>;
1294
1239
  type HttpResponseBodySchema<MethodSchema extends HttpMethodSchema, StatusCode extends HttpStatusCode> = ReplaceBy<ReplaceBy<IfNever<DefaultNoExclude<Default<Default<MethodSchema['response']>[StatusCode]>['body']>, null>, undefined, null>, ArrayBuffer, Blob>;
1295
1240
 
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 };
1241
+ 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 };