@zimic/http 0.5.1-canary.0 → 0.5.1-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/{chunk-LOHINQWU.js → chunk-CFBC3ABT.js} +2 -2
- package/dist/chunk-CFBC3ABT.js.map +1 -0
- package/dist/{chunk-KVTV4E5K.mjs → chunk-UUVECE3U.mjs} +2 -2
- package/dist/chunk-UUVECE3U.mjs.map +1 -0
- package/dist/cli.js +7 -7
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +2 -2
- package/dist/cli.mjs.map +1 -1
- package/dist/index.d.ts +70 -635
- package/dist/index.js +37 -158
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +37 -158
- package/dist/index.mjs.map +1 -1
- package/dist/typegen.d.ts +9 -52
- package/dist/typegen.js +2 -2
- package/dist/typegen.mjs +1 -1
- package/package.json +6 -6
- package/src/formData/HttpFormData.ts +15 -92
- package/src/headers/HttpHeaders.ts +15 -58
- package/src/headers/types.ts +1 -1
- package/src/searchParams/HttpSearchParams.ts +15 -82
- package/src/searchParams/types.ts +1 -4
- package/src/typegen/openapi/generate.ts +9 -52
- package/src/types/schema.ts +23 -398
- package/dist/chunk-KVTV4E5K.mjs.map +0 -1
- package/dist/chunk-LOHINQWU.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -162,70 +162,30 @@ type HttpFormDataSerialized<Type> = [Type] extends [never] ? never : Type extend
|
|
|
162
162
|
[Key in keyof Type as IfNever<PrimitiveHttpFormDataSerialized<Type[Key]>, never, Key>]: PrimitiveHttpFormDataSerialized<Type[Key]>;
|
|
163
163
|
} : never;
|
|
164
164
|
|
|
165
|
-
/**
|
|
166
|
-
* An extended HTTP form data object with a strictly-typed schema. Fully compatible with the built-in
|
|
167
|
-
* {@link https://developer.mozilla.org/docs/Web/API/FormData `FormData`} class.
|
|
168
|
-
*
|
|
169
|
-
* **IMPORTANT**: the input of `HttpFormData` and all of its internal types must be declared inline or as a type aliases
|
|
170
|
-
* (`type`). They cannot be interfaces.
|
|
171
|
-
*
|
|
172
|
-
* @example
|
|
173
|
-
* import { HttpFormData } from '@zimic/http';
|
|
174
|
-
*
|
|
175
|
-
* const formData = new HttpFormData<{
|
|
176
|
-
* files: File[];
|
|
177
|
-
* description?: string;
|
|
178
|
-
* }>();
|
|
179
|
-
*
|
|
180
|
-
* formData.append('file', new File(['content'], 'file.txt', { type: 'text/plain' }));
|
|
181
|
-
* formData.append('description', 'My file');
|
|
182
|
-
*
|
|
183
|
-
* const files = formData.getAll('file');
|
|
184
|
-
* console.log(files); // [File { name: 'file.txt', type: 'text/plain' }]
|
|
185
|
-
*
|
|
186
|
-
* const description = formData.get('description');
|
|
187
|
-
* console.log(description); // 'My file'
|
|
188
|
-
*
|
|
189
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http#httpformdata `HttpFormData` API reference}
|
|
190
|
-
*/
|
|
165
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-form-data `HttpFormData` API reference} */
|
|
191
166
|
declare class HttpFormData<LooseSchema extends HttpFormDataSchema.Loose = HttpFormDataSchema.Loose> extends FormData {
|
|
192
167
|
readonly _schema: HttpFormDataSerialized<LooseSchema>;
|
|
193
|
-
/** @see {@link https://
|
|
168
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-form-data#formdataset `formData.set()` API reference} */
|
|
194
169
|
set<Name extends HttpFormDataSchemaName<this['_schema']>>(name: Name, value: Exclude<ArrayItemIfArray<NonNullable<LooseSchema[Name]>>, Blob>): void;
|
|
195
170
|
set<Name extends HttpFormDataSchemaName<this['_schema']>>(name: Name, blob: Exclude<ArrayItemIfArray<NonNullable<LooseSchema[Name]>>, string>, fileName?: string): void;
|
|
196
|
-
/** @see {@link https://
|
|
171
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-form-data#formdataappend `formData.append()` API reference} */
|
|
197
172
|
append<Name extends HttpFormDataSchemaName<this['_schema']>>(name: Name, value: Exclude<ArrayItemIfArray<NonNullable<LooseSchema[Name]>>, Blob>): void;
|
|
198
173
|
append<Name extends HttpFormDataSchemaName<this['_schema']>>(name: Name, blob: Exclude<ArrayItemIfArray<NonNullable<LooseSchema[Name]>>, string>, fileName?: string): void;
|
|
199
|
-
/**
|
|
200
|
-
* Get the value of the entry associated to a key name.
|
|
201
|
-
*
|
|
202
|
-
* If the key might have multiple values, use {@link HttpFormData#getAll} instead.
|
|
203
|
-
*
|
|
204
|
-
* @param name The name of the key to get the value of.
|
|
205
|
-
* @returns The value associated with the key name, or `null` if the key does not exist.
|
|
206
|
-
* @see {@link https://developer.mozilla.org/docs/Web/API/FormData/get MDN Reference}
|
|
207
|
-
*/
|
|
174
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-form-data#formdataget `formData.get()` API reference} */
|
|
208
175
|
get<Name extends HttpFormDataSchemaName.NonArray<this['_schema']>>(name: Name): ReplaceBy<ReplaceBy<ArrayItemIfArray<this['_schema'][Name]>, undefined, null>, Blob, File>;
|
|
209
|
-
/**
|
|
210
|
-
* Get all the values of the entry associated with a key name.
|
|
211
|
-
*
|
|
212
|
-
* If the key has at most a single value, use {@link HttpFormData#get} instead.
|
|
213
|
-
*
|
|
214
|
-
* @param name The name of the key to get the values of.
|
|
215
|
-
* @returns An array of values associated with the key name, or an empty array if the key does not exist.
|
|
216
|
-
* @see {@link https://developer.mozilla.org/docs/Web/API/FormData/getAll MDN Reference}
|
|
217
|
-
*/
|
|
176
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-form-data#formdatagetall `formData.getAll()` API reference} */
|
|
218
177
|
getAll<Name extends HttpFormDataSchemaName.Array<this['_schema']>>(name: Name): ReplaceBy<ArrayItemIfArray<NonNullable<this['_schema'][Name]>>, Blob, File>[];
|
|
219
|
-
/** @see {@link https://
|
|
178
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-form-data#formdatahas `formData.has()` API reference} */
|
|
220
179
|
has<Name extends HttpFormDataSchemaName<this['_schema']>>(name: Name): boolean;
|
|
221
|
-
/** @see {@link https://
|
|
180
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-form-data#formdatadelete `formData.delete()` API reference} */
|
|
222
181
|
delete<Name extends HttpFormDataSchemaName<this['_schema']>>(name: Name): void;
|
|
223
|
-
|
|
224
|
-
|
|
182
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-form-data#formdataforEach `formData.forEach()` API reference} */
|
|
183
|
+
forEach<This extends HttpFormData<this['_schema']>>(callback: <Key extends HttpFormDataSchemaName<this['_schema']>>(value: ReplaceBy<ArrayItemIfArray<NonNullable<this['_schema'][Key]>>, Blob, File>, key: Key, formData: HttpFormData<this['_schema']>) => void, thisArg?: This): void;
|
|
184
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-form-data#formdatakeys `formData.keys()` API reference} */
|
|
225
185
|
keys(): FormDataIterator<HttpFormDataSchemaName<this['_schema']>>;
|
|
226
|
-
/** @see {@link https://
|
|
186
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-form-data#formdatavalues `formData.values()` API reference} */
|
|
227
187
|
values(): FormDataIterator<ReplaceBy<ArrayItemIfArray<NonNullable<this['_schema'][HttpFormDataSchemaName<this['_schema']>]>>, Blob, File>>;
|
|
228
|
-
/** @see {@link https://
|
|
188
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-form-data#formdataentries `formData.entries()` API reference} */
|
|
229
189
|
entries(): FormDataIterator<[
|
|
230
190
|
HttpFormDataSchemaName<this['_schema']>,
|
|
231
191
|
ReplaceBy<ArrayItemIfArray<NonNullable<this['_schema'][HttpFormDataSchemaName<this['_schema']>]>>, Blob, File>
|
|
@@ -234,48 +194,11 @@ declare class HttpFormData<LooseSchema extends HttpFormDataSchema.Loose = HttpFo
|
|
|
234
194
|
HttpFormDataSchemaName<this['_schema']>,
|
|
235
195
|
ReplaceBy<ArrayItemIfArray<NonNullable<this['_schema'][HttpFormDataSchemaName<this['_schema']>]>>, Blob, File>
|
|
236
196
|
]>;
|
|
237
|
-
/**
|
|
238
|
-
* Checks if the data is equal to the other data. Equality is defined as having the same keys and values, regardless
|
|
239
|
-
* of the order of keys.
|
|
240
|
-
*
|
|
241
|
-
* @param otherData The other data to compare.
|
|
242
|
-
* @returns A promise that resolves with `true` if the data is equal to the other data, or `false` otherwise.
|
|
243
|
-
* Important: both form data might be read while comparing.
|
|
244
|
-
*/
|
|
197
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-form-data#formdataequals `formData.equals()` API reference} */
|
|
245
198
|
equals<OtherSchema extends LooseSchema>(otherData: HttpFormData<OtherSchema>): Promise<boolean>;
|
|
246
|
-
/**
|
|
247
|
-
* Checks if the data contains the other data. This method is less strict than {@link HttpFormData#equals} and only
|
|
248
|
-
* requires that all keys and values in the other data are present in this data.
|
|
249
|
-
*
|
|
250
|
-
* @param otherData The other data to compare.
|
|
251
|
-
* @returns A promise that resolves with `true` if this data contains the other data, or `false` otherwise. Important:
|
|
252
|
-
* both form data might be read while comparing.
|
|
253
|
-
*/
|
|
199
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-form-data#formdatacontains `formData.contains()` API reference} */
|
|
254
200
|
contains<OtherSchema extends LooseSchema>(otherData: HttpFormData<OtherSchema>): Promise<boolean>;
|
|
255
|
-
/**
|
|
256
|
-
* Converts this form data into a plain object. This method is useful for serialization and debugging purposes.
|
|
257
|
-
*
|
|
258
|
-
* **NOTE**: If a key has multiple values, the object will contain an array of values for that key. If the key has
|
|
259
|
-
* only one value, the object will contain its value directly, without an array, regardless of how the value was
|
|
260
|
-
* initialized when creating the form data.
|
|
261
|
-
*
|
|
262
|
-
* @example
|
|
263
|
-
* const formData = new HttpFormData<{
|
|
264
|
-
* title: string;
|
|
265
|
-
* descriptions: string[];
|
|
266
|
-
* content: Blob;
|
|
267
|
-
* }>();
|
|
268
|
-
*
|
|
269
|
-
* formData.set('title', 'My title');
|
|
270
|
-
* formData.append('descriptions', 'Description 1');
|
|
271
|
-
* formData.append('descriptions', 'Description 2');
|
|
272
|
-
* formData.set('content', new Blob(['content'], { type: 'text/plain' }));
|
|
273
|
-
*
|
|
274
|
-
* const object = formData.toObject();
|
|
275
|
-
* console.log(object); // { title: 'My title', descriptions: ['Description 1', 'Description 2'], content: Blob { type: 'text/plain' } }
|
|
276
|
-
*
|
|
277
|
-
* @returns A plain object representation of this form data.
|
|
278
|
-
*/
|
|
201
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-form-data#formdatatoobject `formData.toObject()` API reference} */
|
|
279
202
|
toObject(): this["_schema"];
|
|
280
203
|
}
|
|
281
204
|
|
|
@@ -321,7 +244,7 @@ declare namespace HttpHeadersSchema {
|
|
|
321
244
|
type HttpHeadersSchemaTuple<Schema extends HttpHeadersSchema.Loose = HttpHeadersSchema.Loose> = {
|
|
322
245
|
[Key in keyof Schema & string]: [Key, NonNullable<Schema[Key]>];
|
|
323
246
|
}[keyof Schema & string];
|
|
324
|
-
/** An initialization value for {@link https://
|
|
247
|
+
/** An initialization value for {@link https://zimic.dev/docs/http/api/http-headers `HttpHeaders`}. */
|
|
325
248
|
type HttpHeadersInit<Schema extends HttpHeadersSchema.Loose = HttpHeadersSchema.Loose> = Headers | Schema | HttpHeaders<Schema> | HttpHeadersSchemaTuple<Schema>[];
|
|
326
249
|
/**
|
|
327
250
|
* Extracts the names of the headers defined in a {@link HttpHeadersSchema}. Each key is considered a header name.
|
|
@@ -360,47 +283,29 @@ type HttpHeadersSchemaName<Schema extends HttpHeadersSchema> = IfNever<Schema, n
|
|
|
360
283
|
*/
|
|
361
284
|
type HttpHeadersSerialized<Type> = HttpPathParamsSerialized<Type>;
|
|
362
285
|
|
|
363
|
-
/**
|
|
364
|
-
* An extended HTTP headers object with a strictly-typed schema. Fully compatible with the built-in
|
|
365
|
-
* {@link https://developer.mozilla.org/docs/Web/API/Headers `Headers`} class.
|
|
366
|
-
*
|
|
367
|
-
* @example
|
|
368
|
-
* import { HttpHeaders } from '@zimic/http';
|
|
369
|
-
*
|
|
370
|
-
* const headers = new HttpHeaders<{
|
|
371
|
-
* accept?: string;
|
|
372
|
-
* 'content-type'?: string;
|
|
373
|
-
* }>({
|
|
374
|
-
* accept: '*',
|
|
375
|
-
* 'content-type': 'application/json',
|
|
376
|
-
* });
|
|
377
|
-
*
|
|
378
|
-
* const contentType = headers.get('content-type');
|
|
379
|
-
* console.log(contentType); // 'application/json'
|
|
380
|
-
*
|
|
381
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http#httpheaders `HttpHeaders` API reference}
|
|
382
|
-
*/
|
|
286
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-headers `HttpHeaders` API reference} */
|
|
383
287
|
declare class HttpHeaders<LooseSchema extends HttpHeadersSchema.Loose = HttpHeadersSchema.Loose> extends Headers {
|
|
384
288
|
readonly _schema: HttpHeadersSerialized<LooseSchema>;
|
|
385
289
|
constructor(init?: HttpHeadersInit<LooseSchema>);
|
|
386
|
-
/** @see {@link https://
|
|
290
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-headers#headersset `headers.set()` API reference} */
|
|
387
291
|
set<Name extends HttpHeadersSchemaName<this['_schema']>>(name: Name, value: NonNullable<LooseSchema[Name]>): void;
|
|
388
|
-
/** @see {@link https://
|
|
292
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-headers#headersappend `headers.append()` API reference} */
|
|
389
293
|
append<Name extends HttpHeadersSchemaName<this['_schema']>>(name: Name, value: NonNullable<LooseSchema[Name]>): void;
|
|
390
|
-
/** @see {@link https://
|
|
294
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-headers#headersget `headers.get()` API reference} */
|
|
391
295
|
get<Name extends HttpHeadersSchemaName<this['_schema']>>(name: Name): ReplaceBy<this['_schema'][Name], undefined, null>;
|
|
392
|
-
/** @see {@link https://
|
|
296
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-headers#headersgetSetCookie `headers.getSetCookie()` API reference} */
|
|
393
297
|
getSetCookie(): NonNullable<Default<this['_schema']['Set-Cookie'], string>>[];
|
|
394
|
-
/** @see {@link https://
|
|
298
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-headers#headershas `headers.has()` API reference} */
|
|
395
299
|
has<Name extends HttpHeadersSchemaName<this['_schema']>>(name: Name): boolean;
|
|
396
|
-
/** @see {@link https://
|
|
300
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-headers#headersdelete `headers.delete()` API reference} */
|
|
397
301
|
delete<Name extends HttpHeadersSchemaName<this['_schema']>>(name: Name): void;
|
|
398
|
-
|
|
399
|
-
|
|
302
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-headers#headersforEach `headers.forEach()` API reference} */
|
|
303
|
+
forEach<This extends HttpHeaders<this['_schema']>>(callback: <Key extends HttpHeadersSchemaName<this['_schema']>>(value: NonNullable<this['_schema'][Key]> & string, key: Key, headers: Headers) => void, thisArg?: This): void;
|
|
304
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-headers#headerskeys `headers.keys()` API reference} */
|
|
400
305
|
keys(): HeadersIterator<HttpHeadersSchemaName<this['_schema']>>;
|
|
401
|
-
/** @see {@link https://
|
|
306
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-headers#headersvalues `headers.values()` API reference} */
|
|
402
307
|
values(): HeadersIterator<NonNullable<this['_schema'][HttpHeadersSchemaName<this['_schema']>]> & string>;
|
|
403
|
-
/** @see {@link https://
|
|
308
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-headers#headersentries `headers.entries()` API reference} */
|
|
404
309
|
entries(): HeadersIterator<[
|
|
405
310
|
HttpHeadersSchemaName<this['_schema']>,
|
|
406
311
|
NonNullable<this['_schema'][HttpHeadersSchemaName<this['_schema']>]> & string
|
|
@@ -409,36 +314,11 @@ declare class HttpHeaders<LooseSchema extends HttpHeadersSchema.Loose = HttpHead
|
|
|
409
314
|
HttpHeadersSchemaName<this['_schema']>,
|
|
410
315
|
NonNullable<this['_schema'][HttpHeadersSchemaName<this['_schema']>]> & string
|
|
411
316
|
]>;
|
|
412
|
-
/**
|
|
413
|
-
* Checks if this headers object is equal to another set of headers. Equality is defined as having the same keys and
|
|
414
|
-
* values, regardless of the order of keys.
|
|
415
|
-
*
|
|
416
|
-
* @param otherHeaders The other headers object to compare against.
|
|
417
|
-
* @returns `true` if the headers are equal, `false` otherwise.
|
|
418
|
-
*/
|
|
317
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-headers#headersequals `headers.equals()` API reference} */
|
|
419
318
|
equals<OtherSchema extends LooseSchema>(otherHeaders: HttpHeaders<OtherSchema>): boolean;
|
|
420
|
-
/**
|
|
421
|
-
* Checks if this headers object contains another set of headers. This method is less strict than
|
|
422
|
-
* {@link HttpHeaders#equals} and only requires that all keys and values in the other headers are present in these
|
|
423
|
-
* headers.
|
|
424
|
-
*
|
|
425
|
-
* @param otherHeaders The other headers object to compare against.
|
|
426
|
-
* @returns `true` if these headers contain the other headers, `false` otherwise.
|
|
427
|
-
*/
|
|
319
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-headers#headerscontains `headers.contains()` API reference} */
|
|
428
320
|
contains<OtherSchema extends LooseSchema>(otherHeaders: HttpHeaders<OtherSchema>): boolean;
|
|
429
|
-
/**
|
|
430
|
-
* Converts these headers into a plain object. This method is useful for serialization and debugging purposes.
|
|
431
|
-
*
|
|
432
|
-
* @example
|
|
433
|
-
* const headers = new HttpHeaders({
|
|
434
|
-
* accept: 'application/json',
|
|
435
|
-
* 'content-type': 'application/json',
|
|
436
|
-
* });
|
|
437
|
-
* const object = headers.toObject();
|
|
438
|
-
* console.log(object); // { accept: 'application/json', 'content-type': 'application/json' }
|
|
439
|
-
*
|
|
440
|
-
* @returns A plain object representation of these headers.
|
|
441
|
-
*/
|
|
321
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-headers#headerstoobject `headers.toObject()` API reference} */
|
|
442
322
|
toObject(): this['_schema'];
|
|
443
323
|
private splitHeaderValues;
|
|
444
324
|
}
|
|
@@ -455,10 +335,7 @@ declare namespace HttpSearchParamsSchema {
|
|
|
455
335
|
type HttpSearchParamsSchemaTuple<Schema extends HttpSearchParamsSchema.Loose = HttpSearchParamsSchema.Loose> = {
|
|
456
336
|
[Key in keyof Schema & string]: [Key, ArrayItemIfArray<NonNullable<Schema[Key]>>];
|
|
457
337
|
}[keyof Schema & string];
|
|
458
|
-
/**
|
|
459
|
-
* An initialization value for
|
|
460
|
-
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http#httpsearchparams `HttpSearchParams`}.
|
|
461
|
-
*/
|
|
338
|
+
/** An initialization value for {@link https://zimic.dev/docs/http/api/http-search-params `HttpSearchParams`}. */
|
|
462
339
|
type HttpSearchParamsInit<Schema extends HttpSearchParamsSchema.Loose = HttpSearchParamsSchema.Loose> = string | URLSearchParams | Schema | HttpSearchParams<Schema> | HttpSearchParamsSchemaTuple<Schema>[];
|
|
463
340
|
declare namespace HttpSearchParamsSchemaName {
|
|
464
341
|
/** Extracts the names of the search params defined in a {@link HttpSearchParamsSchema} that are arrays. */
|
|
@@ -523,67 +400,30 @@ type HttpSearchParamsSerialized<Type> = [Type] extends [never] ? never : Type ex
|
|
|
523
400
|
[Key in keyof Type as IfNever<PrimitiveHttpSearchParamsSerialized<Type[Key]>, never, Key>]: PrimitiveHttpSearchParamsSerialized<Type[Key]>;
|
|
524
401
|
} : never;
|
|
525
402
|
|
|
526
|
-
/**
|
|
527
|
-
* An extended HTTP search params object with a strictly-typed schema. Fully compatible with the built-in
|
|
528
|
-
* {@link https://developer.mozilla.org/docs/Web/API/URLSearchParams `URLSearchParams`} class.
|
|
529
|
-
*
|
|
530
|
-
* @example
|
|
531
|
-
* import { HttpSearchParams } from '@zimic/http';
|
|
532
|
-
*
|
|
533
|
-
* const searchParams = new HttpSearchParams<{
|
|
534
|
-
* names?: string[];
|
|
535
|
-
* page?: `${number}`;
|
|
536
|
-
* }>({
|
|
537
|
-
* names: ['user 1', 'user 2'],
|
|
538
|
-
* page: '1',
|
|
539
|
-
* });
|
|
540
|
-
*
|
|
541
|
-
* const names = searchParams.getAll('names');
|
|
542
|
-
* console.log(names); // ['user 1', 'user 2']
|
|
543
|
-
*
|
|
544
|
-
* const page = searchParams.get('page');
|
|
545
|
-
* console.log(page); // '1'
|
|
546
|
-
*
|
|
547
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http#httpsearchparams `HttpSearchParams` API reference}
|
|
548
|
-
*/
|
|
403
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-search-params `HttpSearchParams` API reference} */
|
|
549
404
|
declare class HttpSearchParams<LooseSchema extends HttpSearchParamsSchema.Loose = HttpSearchParamsSchema.Loose> extends URLSearchParams {
|
|
550
405
|
readonly _schema: HttpSearchParamsSerialized<LooseSchema>;
|
|
551
406
|
constructor(init?: HttpSearchParamsInit<LooseSchema>);
|
|
552
407
|
private populateInitArrayProperties;
|
|
553
|
-
/** @see {@link https://
|
|
408
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-search-params#searchparamsset `searchParams.set()` API reference} */
|
|
554
409
|
set<Name extends HttpSearchParamsSchemaName<this['_schema']>>(name: Name, value: ArrayItemIfArray<NonNullable<LooseSchema[Name]>>): void;
|
|
555
|
-
/** @see {@link https://
|
|
410
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-search-params#searchparamsappend `searchParams.append()` API reference} */
|
|
556
411
|
append<Name extends HttpSearchParamsSchemaName<this['_schema']>>(name: Name, value: ArrayItemIfArray<NonNullable<LooseSchema[Name]>>): void;
|
|
557
|
-
/**
|
|
558
|
-
* Get the value of the entry associated to a key name.
|
|
559
|
-
*
|
|
560
|
-
* If the key might have multiple values, use {@link HttpSearchParams#getAll} instead.
|
|
561
|
-
*
|
|
562
|
-
* @param name The name of the key to get the value of.
|
|
563
|
-
* @returns The value associated with the key name, or `null` if the key does not exist.
|
|
564
|
-
* @see {@link https://developer.mozilla.org/docs/Web/API/URLSearchParams/get MDN Reference}
|
|
565
|
-
*/
|
|
412
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-search-params#searchparamsget `searchParams.get()` API reference} */
|
|
566
413
|
get<Name extends HttpSearchParamsSchemaName.NonArray<this['_schema']>>(name: Name): ReplaceBy<ArrayItemIfArray<this['_schema'][Name]>, undefined, null>;
|
|
567
|
-
/**
|
|
568
|
-
* Get all the values of the entry associated with a key name.
|
|
569
|
-
*
|
|
570
|
-
* If the key has at most one value, use {@link HttpSearchParams#get} instead.
|
|
571
|
-
*
|
|
572
|
-
* @param name The name of the key to get the values of.
|
|
573
|
-
* @returns An array of values associated with the key name, or an empty array if the key does not exist.
|
|
574
|
-
* @see {@link https://developer.mozilla.org/docs/Web/API/URLSearchParams/getAll MDN Reference}
|
|
575
|
-
*/
|
|
414
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-search-params#searchparamsgetall `searchParams.getAll()` API reference} */
|
|
576
415
|
getAll<Name extends HttpSearchParamsSchemaName.Array<this['_schema']>>(name: Name): ArrayItemIfArray<NonNullable<this['_schema'][Name]>>[];
|
|
577
|
-
/** @see {@link https://
|
|
416
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-search-params#searchparamshas `searchParams.has()` API reference} */
|
|
578
417
|
has<Name extends HttpSearchParamsSchemaName<this['_schema']>>(name: Name, value?: ArrayItemIfArray<NonNullable<LooseSchema[Name]>>): boolean;
|
|
579
|
-
/** @see {@link https://
|
|
418
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-search-params#searchparamsdelete `searchParams.delete()` API reference} */
|
|
580
419
|
delete<Name extends HttpSearchParamsSchemaName<this['_schema']>>(name: Name, value?: ArrayItemIfArray<NonNullable<LooseSchema[Name]>>): void;
|
|
581
|
-
|
|
582
|
-
|
|
420
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-search-params#searchparamsforEach `searchParams.forEach()` API reference} */
|
|
421
|
+
forEach<This extends HttpSearchParams<this['_schema']>>(callback: <Key extends HttpSearchParamsSchemaName<this['_schema']>>(value: ArrayItemIfArray<NonNullable<this['_schema'][Key]>>, key: Key, searchParams: HttpSearchParams<this['_schema']>) => void, thisArg?: This): void;
|
|
422
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-search-params#searchparamskeys `searchParams.keys()` API reference} */
|
|
583
423
|
keys(): URLSearchParamsIterator<HttpSearchParamsSchemaName<this['_schema']>>;
|
|
584
|
-
/** @see {@link https://
|
|
424
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-search-params#searchparamsvalues `searchParams.values()` API reference} */
|
|
585
425
|
values(): URLSearchParamsIterator<ArrayItemIfArray<NonNullable<this['_schema'][HttpSearchParamsSchemaName<this['_schema']>]>>>;
|
|
586
|
-
/** @see {@link https://
|
|
426
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-search-params#searchparamsentries `searchParams.entries()` API reference} */
|
|
587
427
|
entries(): URLSearchParamsIterator<[
|
|
588
428
|
HttpSearchParamsSchemaName<this['_schema']>,
|
|
589
429
|
ArrayItemIfArray<NonNullable<this['_schema'][HttpSearchParamsSchemaName<this['_schema']>]>>
|
|
@@ -592,41 +432,11 @@ declare class HttpSearchParams<LooseSchema extends HttpSearchParamsSchema.Loose
|
|
|
592
432
|
HttpSearchParamsSchemaName<this['_schema']>,
|
|
593
433
|
ArrayItemIfArray<NonNullable<this['_schema'][HttpSearchParamsSchemaName<this['_schema']>]>>
|
|
594
434
|
]>;
|
|
595
|
-
/**
|
|
596
|
-
* Checks if these search params are equal to another set of search parameters. Equality is defined as having the same
|
|
597
|
-
* keys and values, regardless of the order of the keys.
|
|
598
|
-
*
|
|
599
|
-
* @param otherParams The other search parameters to compare against.
|
|
600
|
-
* @returns `true` if the search parameters are equal, `false` otherwise.
|
|
601
|
-
*/
|
|
435
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-search-params#searchparamsequals `searchParams.equals()` API reference} */
|
|
602
436
|
equals<OtherSchema extends LooseSchema>(otherParams: HttpSearchParams<OtherSchema>): boolean;
|
|
603
|
-
/**
|
|
604
|
-
* Checks if these search params contain another set of search parameters. This method is less strict than
|
|
605
|
-
* {@link HttpSearchParams#equals} and only requires that all keys and values in the other search parameters are
|
|
606
|
-
* present in these search parameters.
|
|
607
|
-
*
|
|
608
|
-
* @param otherParams The other search parameters to check for containment.
|
|
609
|
-
* @returns `true` if these search parameters contain the other search parameters, `false` otherwise.
|
|
610
|
-
*/
|
|
437
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-search-params#searchparamscontains `searchParams.contains()` API reference} */
|
|
611
438
|
contains<OtherSchema extends LooseSchema>(otherParams: HttpSearchParams<OtherSchema>): boolean;
|
|
612
|
-
/**
|
|
613
|
-
* Converts these search params into a plain object. This method is useful for serialization and debugging purposes.
|
|
614
|
-
*
|
|
615
|
-
* **NOTE**: If a key has multiple values, the object will contain an array of values for that key. If the key has
|
|
616
|
-
* only one value, the object will contain its value directly, without an array, regardless of how the value was
|
|
617
|
-
* initialized when creating the search params object.
|
|
618
|
-
*
|
|
619
|
-
* @example
|
|
620
|
-
* const searchParams = new HttpSearchParams({
|
|
621
|
-
* names: ['user 1', 'user 2'],
|
|
622
|
-
* name: ['user 3'],
|
|
623
|
-
* page: '1',
|
|
624
|
-
* });
|
|
625
|
-
* const object = searchParams.toObject();
|
|
626
|
-
* console.log(object); // { names: ['user 1', 'user 2'], name: 'user 3', page: '1' }
|
|
627
|
-
*
|
|
628
|
-
* @returns A plain object representation of these search params.
|
|
629
|
-
*/
|
|
439
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-search-params#searchparamstoobject `searchParams.toObject()` API reference} */
|
|
630
440
|
toObject(): this["_schema"];
|
|
631
441
|
}
|
|
632
442
|
|
|
@@ -639,7 +449,7 @@ type HttpMethod = (typeof HTTP_METHODS)[number];
|
|
|
639
449
|
/**
|
|
640
450
|
* A schema representing the structure of an HTTP request.
|
|
641
451
|
*
|
|
642
|
-
* @see {@link https://
|
|
452
|
+
* @see {@link https://zimic.dev/docs/http/api/http-schema `HttpSchema` API reference}
|
|
643
453
|
*/
|
|
644
454
|
interface HttpRequestSchema {
|
|
645
455
|
headers?: HttpHeadersSchema.Loose;
|
|
@@ -649,7 +459,7 @@ interface HttpRequestSchema {
|
|
|
649
459
|
/**
|
|
650
460
|
* A schema representing the structure of an HTTP response.
|
|
651
461
|
*
|
|
652
|
-
* @see {@link https://
|
|
462
|
+
* @see {@link https://zimic.dev/docs/http/api/http-schema `HttpSchema` API reference}
|
|
653
463
|
*/
|
|
654
464
|
interface HttpResponseSchema {
|
|
655
465
|
headers?: HttpHeadersSchema.Loose;
|
|
@@ -701,7 +511,7 @@ declare namespace HttpStatusCode {
|
|
|
701
511
|
/**
|
|
702
512
|
* A schema representing the structure of HTTP responses by status code.
|
|
703
513
|
*
|
|
704
|
-
* @see {@link https://
|
|
514
|
+
* @see {@link https://zimic.dev/docs/http/api/http-schema `HttpSchema` API reference}
|
|
705
515
|
*/
|
|
706
516
|
type HttpResponseSchemaByStatusCode = {
|
|
707
517
|
[StatusCode in HttpStatusCode]?: HttpResponseSchema;
|
|
@@ -709,13 +519,13 @@ type HttpResponseSchemaByStatusCode = {
|
|
|
709
519
|
/**
|
|
710
520
|
* Extracts the status codes used in a response schema by status code.
|
|
711
521
|
*
|
|
712
|
-
* @see {@link https://
|
|
522
|
+
* @see {@link https://zimic.dev/docs/http/api/http-schema `HttpSchema` API reference}
|
|
713
523
|
*/
|
|
714
524
|
type HttpResponseSchemaStatusCode<ResponseSchemaByStatusCode extends HttpResponseSchemaByStatusCode> = keyof ResponseSchemaByStatusCode & HttpStatusCode;
|
|
715
525
|
/**
|
|
716
526
|
* A schema representing the structure of an HTTP request and response for a given method.
|
|
717
527
|
*
|
|
718
|
-
* @see {@link https://
|
|
528
|
+
* @see {@link https://zimic.dev/docs/http/api/http-schema `HttpSchema` API reference}
|
|
719
529
|
*/
|
|
720
530
|
interface HttpMethodSchema {
|
|
721
531
|
request?: HttpRequestSchema;
|
|
@@ -724,7 +534,7 @@ interface HttpMethodSchema {
|
|
|
724
534
|
/**
|
|
725
535
|
* A schema representing the structure of HTTP request and response by method.
|
|
726
536
|
*
|
|
727
|
-
* @see {@link https://
|
|
537
|
+
* @see {@link https://zimic.dev/docs/http/api/http-schema `HttpSchema` API reference}
|
|
728
538
|
*/
|
|
729
539
|
interface HttpMethodsSchema {
|
|
730
540
|
GET?: HttpMethodSchema;
|
|
@@ -738,363 +548,47 @@ interface HttpMethodsSchema {
|
|
|
738
548
|
interface BaseHttpSchema {
|
|
739
549
|
[path: string]: HttpMethodsSchema;
|
|
740
550
|
}
|
|
741
|
-
/**
|
|
742
|
-
* Declares an HTTP service schema.
|
|
743
|
-
*
|
|
744
|
-
* @example
|
|
745
|
-
* import { type HttpSchema } from '@zimic/http';
|
|
746
|
-
*
|
|
747
|
-
* interface UserListHeaders {
|
|
748
|
-
* accept: string;
|
|
749
|
-
* }
|
|
750
|
-
*
|
|
751
|
-
* interface UserListSearchParams {
|
|
752
|
-
* name?: string;
|
|
753
|
-
* limit?: number;
|
|
754
|
-
* }
|
|
755
|
-
*
|
|
756
|
-
* type Schema = HttpSchema<{
|
|
757
|
-
* '/users': {
|
|
758
|
-
* GET: {
|
|
759
|
-
* request: {
|
|
760
|
-
* headers: UserListHeaders;
|
|
761
|
-
* searchParams: UserListSearchParams;
|
|
762
|
-
* };
|
|
763
|
-
* response: {
|
|
764
|
-
* 200: {
|
|
765
|
-
* // Inline headers declaration
|
|
766
|
-
* headers: { 'content-type': string };
|
|
767
|
-
* body: User[];
|
|
768
|
-
* };
|
|
769
|
-
* };
|
|
770
|
-
* };
|
|
771
|
-
* };
|
|
772
|
-
* }>;
|
|
773
|
-
*
|
|
774
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http‐schemas Declaring HTTP interceptor schemas}
|
|
775
|
-
*/
|
|
551
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-schema `HttpSchema` API reference} */
|
|
776
552
|
type HttpSchema<Schema extends BaseHttpSchema = BaseHttpSchema> = Branded<Schema, 'HttpSchema'>;
|
|
777
553
|
declare namespace HttpSchema {
|
|
778
|
-
/**
|
|
779
|
-
* Declares an HTTP service methods schema.
|
|
780
|
-
*
|
|
781
|
-
* @example
|
|
782
|
-
* import { type HttpSchema } from '@zimic/http';
|
|
783
|
-
*
|
|
784
|
-
* type UserMethods = HttpSchema.Methods<{
|
|
785
|
-
* GET: {
|
|
786
|
-
* response: {
|
|
787
|
-
* 200: { body: User[] };
|
|
788
|
-
* };
|
|
789
|
-
* };
|
|
790
|
-
* }>;
|
|
791
|
-
*
|
|
792
|
-
* type Schema = HttpSchema<{
|
|
793
|
-
* '/users': UserMethods;
|
|
794
|
-
* }>;
|
|
795
|
-
*/
|
|
554
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-schema#httpschemamethods `HttpSchema.Methods` API reference} */
|
|
796
555
|
type Methods<Schema extends HttpMethodsSchema> = Schema;
|
|
797
|
-
/**
|
|
798
|
-
* Declares an HTTP service method schema.
|
|
799
|
-
*
|
|
800
|
-
* @example
|
|
801
|
-
* import { type HttpSchema } from '@zimic/http';
|
|
802
|
-
*
|
|
803
|
-
* type UserListMethod = HttpSchema.Method<{
|
|
804
|
-
* response: {
|
|
805
|
-
* 200: { body: User[] };
|
|
806
|
-
* };
|
|
807
|
-
* }>;
|
|
808
|
-
*
|
|
809
|
-
* type Schema = HttpSchema<{
|
|
810
|
-
* '/users': {
|
|
811
|
-
* GET: UserListMethod;
|
|
812
|
-
* };
|
|
813
|
-
* }>;
|
|
814
|
-
*/
|
|
556
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-schema#httpschemamethod `HttpSchema.Method` API reference} */
|
|
815
557
|
type Method<Schema extends HttpMethodSchema> = Schema;
|
|
816
|
-
/**
|
|
817
|
-
* Declares an HTTP service request schema.
|
|
818
|
-
*
|
|
819
|
-
* @example
|
|
820
|
-
* import { type HttpSchema } from '@zimic/http';
|
|
821
|
-
*
|
|
822
|
-
* type UserCreationRequest = HttpSchema.Request<{
|
|
823
|
-
* headers: { 'content-type': 'application/json' };
|
|
824
|
-
* body: User;
|
|
825
|
-
* }>;
|
|
826
|
-
*
|
|
827
|
-
* type Schema = HttpSchema<{
|
|
828
|
-
* '/users': {
|
|
829
|
-
* POST: {
|
|
830
|
-
* request: UserCreationRequest;
|
|
831
|
-
* response: {
|
|
832
|
-
* 201: { body: User };
|
|
833
|
-
* };
|
|
834
|
-
* };
|
|
835
|
-
* };
|
|
836
|
-
* }>;
|
|
837
|
-
*/
|
|
558
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-schema#httpschemarequest `HttpSchema.Request` API reference} */
|
|
838
559
|
type Request<Schema extends HttpRequestSchema> = Schema;
|
|
839
|
-
/**
|
|
840
|
-
* Declares an HTTP service response schema by status code.
|
|
841
|
-
*
|
|
842
|
-
* @example
|
|
843
|
-
* import { type HttpSchema } from '@zimic/http';
|
|
844
|
-
*
|
|
845
|
-
* type UserListResponseByStatusCode = HttpSchema.ResponseByStatusCode<{
|
|
846
|
-
* 200: { body: User[] };
|
|
847
|
-
* 400: { body: { message: string } };
|
|
848
|
-
* }>;
|
|
849
|
-
*
|
|
850
|
-
* type Schema = HttpSchema<{
|
|
851
|
-
* '/users': {
|
|
852
|
-
* GET: {
|
|
853
|
-
* response: UserListResponseByStatusCode;
|
|
854
|
-
* };
|
|
855
|
-
* };
|
|
856
|
-
* }>;
|
|
857
|
-
*/
|
|
560
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-schema#httpschemaresponsebystatuscode `HttpSchema.ResponseByStatusCode` API reference} */
|
|
858
561
|
type ResponseByStatusCode<Schema extends HttpResponseSchemaByStatusCode> = Schema;
|
|
859
|
-
/**
|
|
860
|
-
* Declares an HTTP service response schema.
|
|
861
|
-
*
|
|
862
|
-
* @example
|
|
863
|
-
* import { type HttpSchema } from '@zimic/http';
|
|
864
|
-
*
|
|
865
|
-
* type UserListSuccessResponse = HttpSchema.Response<{
|
|
866
|
-
* body: User[];
|
|
867
|
-
* }>;
|
|
868
|
-
*
|
|
869
|
-
* type Schema = HttpSchema<{
|
|
870
|
-
* '/users': {
|
|
871
|
-
* GET: {
|
|
872
|
-
* response: {
|
|
873
|
-
* 200: UserListSuccessResponse;
|
|
874
|
-
* };
|
|
875
|
-
* };
|
|
876
|
-
* };
|
|
877
|
-
* }>;
|
|
878
|
-
*/
|
|
562
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-schema#httpschemaresponse `HttpSchema.Response` API reference} */
|
|
879
563
|
type Response<Schema extends HttpResponseSchema> = Schema;
|
|
880
|
-
/**
|
|
881
|
-
* Declares an HTTP body schema.
|
|
882
|
-
*
|
|
883
|
-
* @example
|
|
884
|
-
* import { type HttpSchema } from '@zimic/http';
|
|
885
|
-
*
|
|
886
|
-
* type UserListSuccessResponseBody = HttpSchema.Body<User[]>;
|
|
887
|
-
*
|
|
888
|
-
* type Schema = HttpSchema<{
|
|
889
|
-
* '/users': {
|
|
890
|
-
* GET: {
|
|
891
|
-
* response: {
|
|
892
|
-
* 200: { body: UserListSuccessResponseBody };
|
|
893
|
-
* };
|
|
894
|
-
* };
|
|
895
|
-
* };
|
|
896
|
-
* }>;
|
|
897
|
-
*/
|
|
564
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-schema#httpschemabody `HttpSchema.Body` API reference} */
|
|
898
565
|
type Body<Schema extends HttpBody.Loose> = Schema;
|
|
899
|
-
/**
|
|
900
|
-
* Declares an HTTP headers schema.
|
|
901
|
-
*
|
|
902
|
-
* @example
|
|
903
|
-
* import { type HttpSchema } from '@zimic/http';
|
|
904
|
-
*
|
|
905
|
-
* type UserListHeaders = HttpSchema.Headers<{
|
|
906
|
-
* accept: 'application/json';
|
|
907
|
-
* }>;
|
|
908
|
-
*
|
|
909
|
-
* type Schema = HttpSchema<{
|
|
910
|
-
* '/users': {
|
|
911
|
-
* GET: {
|
|
912
|
-
* request: {
|
|
913
|
-
* headers: UserListHeaders;
|
|
914
|
-
* };
|
|
915
|
-
* response: {
|
|
916
|
-
* 200: { body: User[] };
|
|
917
|
-
* };
|
|
918
|
-
* };
|
|
919
|
-
* };
|
|
920
|
-
* }>;
|
|
921
|
-
*/
|
|
566
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-schema#httpschemaheaders `HttpSchema.Headers` API reference} */
|
|
922
567
|
type Headers<Schema extends HttpHeadersSchema.Loose> = Schema;
|
|
923
|
-
/**
|
|
924
|
-
* Declares an HTTP search params schema.
|
|
925
|
-
*
|
|
926
|
-
* @example
|
|
927
|
-
* import { type HttpSchema } from '@zimic/http';
|
|
928
|
-
*
|
|
929
|
-
* type UserListSearchParams = HttpSchema.SearchParams<{
|
|
930
|
-
* limit: `${number}`;
|
|
931
|
-
* offset: `${number}`;
|
|
932
|
-
* }>;
|
|
933
|
-
*
|
|
934
|
-
* type Schema = HttpSchema<{
|
|
935
|
-
* '/users': {
|
|
936
|
-
* GET: {
|
|
937
|
-
* request: {
|
|
938
|
-
* searchParams: UserListSearchParams;
|
|
939
|
-
* };
|
|
940
|
-
* response: {
|
|
941
|
-
* 200: { body: User[] };
|
|
942
|
-
* };
|
|
943
|
-
* };
|
|
944
|
-
* };
|
|
945
|
-
* }>;
|
|
946
|
-
*/
|
|
568
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-schema#httpschemasearchparams `HttpSchema.SearchParams` API reference} */
|
|
947
569
|
type SearchParams<Schema extends HttpSearchParamsSchema.Loose> = Schema;
|
|
948
|
-
/**
|
|
949
|
-
* Declares an HTTP path params schema.
|
|
950
|
-
*
|
|
951
|
-
* @example
|
|
952
|
-
* import { type HttpSchema, InferPathParams } from '@zimic/http';
|
|
953
|
-
*
|
|
954
|
-
* type Schema = HttpSchema<{
|
|
955
|
-
* '/users/:userId': {
|
|
956
|
-
* GET: {
|
|
957
|
-
* response: {
|
|
958
|
-
* 200: { body: User };
|
|
959
|
-
* };
|
|
960
|
-
* };
|
|
961
|
-
* };
|
|
962
|
-
* }>;
|
|
963
|
-
*
|
|
964
|
-
* type UserByIdPathParams = HttpSchema.PathParams<{
|
|
965
|
-
* userId: string;
|
|
966
|
-
* }>;
|
|
967
|
-
*
|
|
968
|
-
* // Or infer from the path string
|
|
969
|
-
* type UserByIdPathParams = InferPathParams<Schema, '/users/:userId'>;
|
|
970
|
-
*/
|
|
570
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-schema#httpschemapathparams `HttpSchema.PathParams` API reference} */
|
|
971
571
|
type PathParams<Schema extends HttpPathParamsSchema.Loose> = Schema;
|
|
972
|
-
/**
|
|
973
|
-
* Declares an HTTP form data schema.
|
|
974
|
-
*
|
|
975
|
-
* @example
|
|
976
|
-
* import { HttpFormData, type HttpSchema } from '@zimic/http';
|
|
977
|
-
*
|
|
978
|
-
* type UserCreationFormData = HttpFormData<
|
|
979
|
-
* HttpSchema.FormData<{
|
|
980
|
-
* name: string;
|
|
981
|
-
* email: string;
|
|
982
|
-
* }>
|
|
983
|
-
* >;
|
|
984
|
-
*
|
|
985
|
-
* type Schema = HttpSchema<{
|
|
986
|
-
* '/users': {
|
|
987
|
-
* POST: {
|
|
988
|
-
* request: {
|
|
989
|
-
* body: UserCreationFormData;
|
|
990
|
-
* };
|
|
991
|
-
* response: {
|
|
992
|
-
* 201: { body: User };
|
|
993
|
-
* };
|
|
994
|
-
* };
|
|
995
|
-
* };
|
|
996
|
-
* }>;
|
|
997
|
-
*/
|
|
572
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-schema#httpschemaformdata `HttpSchema.FormData` API reference} */
|
|
998
573
|
type FormData<Schema extends HttpFormDataSchema.Loose> = Schema;
|
|
999
574
|
}
|
|
1000
575
|
/**
|
|
1001
576
|
* Extracts the methods from an HTTP service schema.
|
|
1002
577
|
*
|
|
1003
|
-
* @see {@link https://
|
|
578
|
+
* @see {@link https://zimic.dev/docs/http/api/http-schema `HttpSchema` API reference}
|
|
1004
579
|
*/
|
|
1005
580
|
type HttpSchemaMethod<Schema extends HttpSchema> = IfAny<Schema, any, // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
1006
581
|
// eslint-disable-line @typescript-eslint/no-explicit-any
|
|
1007
582
|
keyof UnionToIntersection<Schema[keyof Schema]> & HttpMethod>;
|
|
1008
583
|
type AllowAnyStringInPathParams<Path extends string> = Path extends `${infer Prefix}:${string}/${infer Suffix}` ? `${Prefix}${string}/${AllowAnyStringInPathParams<Suffix>}` : Path extends `${infer Prefix}:${string}` ? `${Prefix}${string}` : Path;
|
|
1009
|
-
/**
|
|
1010
|
-
* Extracts the paths from an HTTP service schema. Optionally receives a second argument with one or more methods to
|
|
1011
|
-
* filter the paths with. Only the methods defined in the schema are allowed.
|
|
1012
|
-
*
|
|
1013
|
-
* @example
|
|
1014
|
-
* import { type HttpSchema, type HttpSchemaPath } from '@zimic/http';
|
|
1015
|
-
*
|
|
1016
|
-
* type Schema = HttpSchema<{
|
|
1017
|
-
* '/users': {
|
|
1018
|
-
* GET: {
|
|
1019
|
-
* response: { 200: { body: User[] } };
|
|
1020
|
-
* };
|
|
1021
|
-
* };
|
|
1022
|
-
* '/users/:userId': {
|
|
1023
|
-
* DELETE: {
|
|
1024
|
-
* response: { 200: { body: User } };
|
|
1025
|
-
* };
|
|
1026
|
-
* };
|
|
1027
|
-
* }>;
|
|
1028
|
-
*
|
|
1029
|
-
* type Path = HttpSchemaPath<Schema>;
|
|
1030
|
-
* // "/users" | "/users/:userId" | "/users/${string}"
|
|
1031
|
-
*
|
|
1032
|
-
* type GetPath = HttpSchemaPath<Schema, 'GET'>;
|
|
1033
|
-
* // "/users"
|
|
1034
|
-
*
|
|
1035
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http‐schemas Declaring HTTP interceptor schemas}
|
|
1036
|
-
*/
|
|
584
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-schema#httpschemapath `HttpSchemaPath` API reference} */
|
|
1037
585
|
declare namespace HttpSchemaPath {
|
|
1038
586
|
type LooseLiteral<Schema extends HttpSchema, Method extends HttpMethod = HttpMethod> = {
|
|
1039
587
|
[Path in keyof Schema & string]: Method extends keyof Schema[Path] ? Path : never;
|
|
1040
588
|
}[keyof Schema & string];
|
|
1041
|
-
/**
|
|
1042
|
-
* Extracts the literal paths from an HTTP service schema. Optionally receives a second argument with one or more
|
|
1043
|
-
* methods to filter the paths with. Only the methods defined in the schema are allowed.
|
|
1044
|
-
*
|
|
1045
|
-
* @example
|
|
1046
|
-
* import { type HttpSchema, type HttpSchemaPath } from '@zimic/http';
|
|
1047
|
-
*
|
|
1048
|
-
* type Schema = HttpSchema<{
|
|
1049
|
-
* '/users': {
|
|
1050
|
-
* GET: {
|
|
1051
|
-
* response: { 200: { body: User[] } };
|
|
1052
|
-
* };
|
|
1053
|
-
* };
|
|
1054
|
-
* '/users/:userId': {
|
|
1055
|
-
* DELETE: {
|
|
1056
|
-
* response: { 200: { body: User } };
|
|
1057
|
-
* };
|
|
1058
|
-
* };
|
|
1059
|
-
* }>;
|
|
1060
|
-
*
|
|
1061
|
-
* type LiteralPath = HttpSchemaPath.Literal<Schema>;
|
|
1062
|
-
* // "/users" | "/users/:userId"
|
|
1063
|
-
*
|
|
1064
|
-
* type LiteralGetPath = HttpSchemaPath.Literal<Schema, 'GET'>;
|
|
1065
|
-
* // "/users"
|
|
1066
|
-
*
|
|
1067
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http‐schemas Declaring HTTP interceptor schemas}
|
|
1068
|
-
*/
|
|
589
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-schema#httpschemapathliteral `HttpSchemaPath.Literal` API reference} */
|
|
1069
590
|
export type Literal<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema> = HttpSchemaMethod<Schema>> = LooseLiteral<Schema, Method>;
|
|
1070
|
-
/**
|
|
1071
|
-
* Extracts the non-literal paths from an HTTP service schema. Optionally receives a second argument with one or more
|
|
1072
|
-
* methods to filter the paths with. Only the methods defined in the schema are allowed.
|
|
1073
|
-
*
|
|
1074
|
-
* @example
|
|
1075
|
-
* import { type HttpSchema, type HttpSchemaPath } from '@zimic/http';
|
|
1076
|
-
*
|
|
1077
|
-
* type Schema = HttpSchema<{
|
|
1078
|
-
* '/users': {
|
|
1079
|
-
* GET: {
|
|
1080
|
-
* response: { 200: { body: User[] } };
|
|
1081
|
-
* };
|
|
1082
|
-
* };
|
|
1083
|
-
* '/users/:userId': {
|
|
1084
|
-
* DELETE: {
|
|
1085
|
-
* response: { 200: { body: User } };
|
|
1086
|
-
* };
|
|
1087
|
-
* };
|
|
1088
|
-
* }>;
|
|
1089
|
-
*
|
|
1090
|
-
* type NonLiteralPath = HttpSchemaPath.NonLiteral<Schema>;
|
|
1091
|
-
* // "/users" | "/users/${string}"
|
|
1092
|
-
*
|
|
1093
|
-
* type NonLiteralGetPath = HttpSchemaPath.NonLiteral<Schema, 'GET'>;
|
|
1094
|
-
* // "/users"
|
|
1095
|
-
*
|
|
1096
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http‐schemas Declaring HTTP interceptor schemas}
|
|
1097
|
-
*/
|
|
591
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-schema#httpschemapathnonliteral `HttpSchemaPath.NonLiteral` API reference} */
|
|
1098
592
|
export type NonLiteral<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema> = HttpSchemaMethod<Schema>> = AllowAnyStringInPathParams<Literal<Schema, Method>>;
|
|
1099
593
|
export { };
|
|
1100
594
|
}
|
|
@@ -1109,69 +603,10 @@ type RecursiveInferPathParams<Path extends string> = Path extends `${infer _Pref
|
|
|
1109
603
|
} & RecursiveInferPathParams<Suffix> : Path extends `${infer _Prefix}:${infer ParamName}` ? {
|
|
1110
604
|
[Name in ParamName]: string;
|
|
1111
605
|
} : {};
|
|
1112
|
-
/**
|
|
1113
|
-
* Infers the path parameters schema from a path string, optionally validating it against an {@link HttpSchema}.
|
|
1114
|
-
*
|
|
1115
|
-
* If the first argument is a {@link HttpSchema} (recommended), the second argument is checked to be a valid path in that
|
|
1116
|
-
* schema.
|
|
1117
|
-
*
|
|
1118
|
-
* @example
|
|
1119
|
-
* import { HttpSchema, InferPathParams } from '@zimic/http';
|
|
1120
|
-
*
|
|
1121
|
-
* type Schema = HttpSchema<{
|
|
1122
|
-
* '/users/:userId': {
|
|
1123
|
-
* GET: {
|
|
1124
|
-
* response: { 200: { body: User } };
|
|
1125
|
-
* };
|
|
1126
|
-
* };
|
|
1127
|
-
* }>;
|
|
1128
|
-
*
|
|
1129
|
-
* // Using a schema to validate the path (recommended):
|
|
1130
|
-
* type PathParams = InferPathParams<Schema, '/users/:userId'>;
|
|
1131
|
-
* // { userId: string }
|
|
1132
|
-
*
|
|
1133
|
-
* @example
|
|
1134
|
-
* import { InferPathParams } from '@zimic/http';
|
|
1135
|
-
*
|
|
1136
|
-
* // Without using a schema to validate the path (works as `PathParamsSchemaFromPath`):
|
|
1137
|
-
* type PathParams = InferPathParams<'/users/:userId'>;
|
|
1138
|
-
* // { userId: string }
|
|
1139
|
-
*/
|
|
606
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-schema#inferpathparams `InferPathParams` API reference} */
|
|
1140
607
|
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>>;
|
|
1141
608
|
type OmitPastHttpStatusCodes<Schema extends HttpResponseSchemaByStatusCode, PastSchemas extends HttpResponseSchemaByStatusCode[]> = PastSchemas extends NonEmptyArray<HttpResponseSchemaByStatusCode> ? Omit<Schema, keyof UnionToIntersection<PastSchemas[number]>> : Schema;
|
|
1142
|
-
/**
|
|
1143
|
-
* Merges multiple HTTP response schemas by status code into a single schema. When there are duplicate status codes, the
|
|
1144
|
-
* first declaration takes precedence.
|
|
1145
|
-
*
|
|
1146
|
-
* @example
|
|
1147
|
-
* import { type HttpSchema, type HttpStatusCode, MergeHttpResponsesByStatusCode } from '@zimic/http';
|
|
1148
|
-
*
|
|
1149
|
-
* // Overriding the 400 status code with a more specific schema
|
|
1150
|
-
* // and using a generic schema for all other client errors.
|
|
1151
|
-
* type MergedResponseByStatusCode = MergeHttpResponsesByStatusCode<
|
|
1152
|
-
* [
|
|
1153
|
-
* {
|
|
1154
|
-
* 400: { body: { message: string; issues: string[] } };
|
|
1155
|
-
* },
|
|
1156
|
-
* {
|
|
1157
|
-
* [StatusCode in HttpStatusCode.ClientError]: { body: { message: string } };
|
|
1158
|
-
* },
|
|
1159
|
-
* ]
|
|
1160
|
-
* >;
|
|
1161
|
-
* // {
|
|
1162
|
-
* // 400: { body: { message: string; issues: string[] } };
|
|
1163
|
-
* // 401: { body: { message: string}; };
|
|
1164
|
-
* // 402: { body: { message: string}; };
|
|
1165
|
-
* // 403: { body: { message: string}; };
|
|
1166
|
-
* // ...
|
|
1167
|
-
* // }
|
|
1168
|
-
*
|
|
1169
|
-
* type Schema = HttpSchema<{
|
|
1170
|
-
* '/users': {
|
|
1171
|
-
* GET: { response: MergedResponseByStatusCode };
|
|
1172
|
-
* };
|
|
1173
|
-
* }>;
|
|
1174
|
-
*/
|
|
609
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-schema#mergehttpresponsesbystatuscode `MergeHttpResponsesByStatusCode` API reference} */
|
|
1175
610
|
type MergeHttpResponsesByStatusCode<Schemas extends HttpResponseSchemaByStatusCode[], PastSchemas extends HttpResponseSchemaByStatusCode[] = []> = Schemas extends [
|
|
1176
611
|
infer FirstSchema extends HttpResponseSchemaByStatusCode,
|
|
1177
612
|
...infer RestSchemas extends HttpResponseSchemaByStatusCode[]
|