@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/src/types/schema.ts
CHANGED
|
@@ -23,7 +23,7 @@ export type HttpMethod = (typeof HTTP_METHODS)[number];
|
|
|
23
23
|
/**
|
|
24
24
|
* A schema representing the structure of an HTTP request.
|
|
25
25
|
*
|
|
26
|
-
* @see {@link https://
|
|
26
|
+
* @see {@link https://zimic.dev/docs/http/api/http-schema `HttpSchema` API reference}
|
|
27
27
|
*/
|
|
28
28
|
export interface HttpRequestSchema {
|
|
29
29
|
headers?: HttpHeadersSchema.Loose;
|
|
@@ -34,7 +34,7 @@ export interface HttpRequestSchema {
|
|
|
34
34
|
/**
|
|
35
35
|
* A schema representing the structure of an HTTP response.
|
|
36
36
|
*
|
|
37
|
-
* @see {@link https://
|
|
37
|
+
* @see {@link https://zimic.dev/docs/http/api/http-schema `HttpSchema` API reference}
|
|
38
38
|
*/
|
|
39
39
|
export interface HttpResponseSchema {
|
|
40
40
|
headers?: HttpHeadersSchema.Loose;
|
|
@@ -159,7 +159,7 @@ export namespace HttpStatusCode {
|
|
|
159
159
|
/**
|
|
160
160
|
* A schema representing the structure of HTTP responses by status code.
|
|
161
161
|
*
|
|
162
|
-
* @see {@link https://
|
|
162
|
+
* @see {@link https://zimic.dev/docs/http/api/http-schema `HttpSchema` API reference}
|
|
163
163
|
*/
|
|
164
164
|
export type HttpResponseSchemaByStatusCode = {
|
|
165
165
|
[StatusCode in HttpStatusCode]?: HttpResponseSchema;
|
|
@@ -168,7 +168,7 @@ export type HttpResponseSchemaByStatusCode = {
|
|
|
168
168
|
/**
|
|
169
169
|
* Extracts the status codes used in a response schema by status code.
|
|
170
170
|
*
|
|
171
|
-
* @see {@link https://
|
|
171
|
+
* @see {@link https://zimic.dev/docs/http/api/http-schema `HttpSchema` API reference}
|
|
172
172
|
*/
|
|
173
173
|
export type HttpResponseSchemaStatusCode<ResponseSchemaByStatusCode extends HttpResponseSchemaByStatusCode> =
|
|
174
174
|
keyof ResponseSchemaByStatusCode & HttpStatusCode;
|
|
@@ -176,7 +176,7 @@ export type HttpResponseSchemaStatusCode<ResponseSchemaByStatusCode extends Http
|
|
|
176
176
|
/**
|
|
177
177
|
* A schema representing the structure of an HTTP request and response for a given method.
|
|
178
178
|
*
|
|
179
|
-
* @see {@link https://
|
|
179
|
+
* @see {@link https://zimic.dev/docs/http/api/http-schema `HttpSchema` API reference}
|
|
180
180
|
*/
|
|
181
181
|
export interface HttpMethodSchema {
|
|
182
182
|
request?: HttpRequestSchema;
|
|
@@ -186,7 +186,7 @@ export interface HttpMethodSchema {
|
|
|
186
186
|
/**
|
|
187
187
|
* A schema representing the structure of HTTP request and response by method.
|
|
188
188
|
*
|
|
189
|
-
* @see {@link https://
|
|
189
|
+
* @see {@link https://zimic.dev/docs/http/api/http-schema `HttpSchema` API reference}
|
|
190
190
|
*/
|
|
191
191
|
export interface HttpMethodsSchema {
|
|
192
192
|
GET?: HttpMethodSchema;
|
|
@@ -202,280 +202,45 @@ interface BaseHttpSchema {
|
|
|
202
202
|
[path: string]: HttpMethodsSchema;
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
-
/**
|
|
206
|
-
* Declares an HTTP service schema.
|
|
207
|
-
*
|
|
208
|
-
* @example
|
|
209
|
-
* import { type HttpSchema } from '@zimic/http';
|
|
210
|
-
*
|
|
211
|
-
* interface UserListHeaders {
|
|
212
|
-
* accept: string;
|
|
213
|
-
* }
|
|
214
|
-
*
|
|
215
|
-
* interface UserListSearchParams {
|
|
216
|
-
* name?: string;
|
|
217
|
-
* limit?: number;
|
|
218
|
-
* }
|
|
219
|
-
*
|
|
220
|
-
* type Schema = HttpSchema<{
|
|
221
|
-
* '/users': {
|
|
222
|
-
* GET: {
|
|
223
|
-
* request: {
|
|
224
|
-
* headers: UserListHeaders;
|
|
225
|
-
* searchParams: UserListSearchParams;
|
|
226
|
-
* };
|
|
227
|
-
* response: {
|
|
228
|
-
* 200: {
|
|
229
|
-
* // Inline headers declaration
|
|
230
|
-
* headers: { 'content-type': string };
|
|
231
|
-
* body: User[];
|
|
232
|
-
* };
|
|
233
|
-
* };
|
|
234
|
-
* };
|
|
235
|
-
* };
|
|
236
|
-
* }>;
|
|
237
|
-
*
|
|
238
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http‐schemas Declaring HTTP interceptor schemas}
|
|
239
|
-
*/
|
|
205
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-schema `HttpSchema` API reference} */
|
|
240
206
|
export type HttpSchema<Schema extends BaseHttpSchema = BaseHttpSchema> = Branded<Schema, 'HttpSchema'>;
|
|
241
207
|
|
|
242
208
|
export namespace HttpSchema {
|
|
243
|
-
/**
|
|
244
|
-
* Declares an HTTP service methods schema.
|
|
245
|
-
*
|
|
246
|
-
* @example
|
|
247
|
-
* import { type HttpSchema } from '@zimic/http';
|
|
248
|
-
*
|
|
249
|
-
* type UserMethods = HttpSchema.Methods<{
|
|
250
|
-
* GET: {
|
|
251
|
-
* response: {
|
|
252
|
-
* 200: { body: User[] };
|
|
253
|
-
* };
|
|
254
|
-
* };
|
|
255
|
-
* }>;
|
|
256
|
-
*
|
|
257
|
-
* type Schema = HttpSchema<{
|
|
258
|
-
* '/users': UserMethods;
|
|
259
|
-
* }>;
|
|
260
|
-
*/
|
|
209
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-schema#httpschemamethods `HttpSchema.Methods` API reference} */
|
|
261
210
|
export type Methods<Schema extends HttpMethodsSchema> = Schema;
|
|
262
211
|
|
|
263
|
-
/**
|
|
264
|
-
* Declares an HTTP service method schema.
|
|
265
|
-
*
|
|
266
|
-
* @example
|
|
267
|
-
* import { type HttpSchema } from '@zimic/http';
|
|
268
|
-
*
|
|
269
|
-
* type UserListMethod = HttpSchema.Method<{
|
|
270
|
-
* response: {
|
|
271
|
-
* 200: { body: User[] };
|
|
272
|
-
* };
|
|
273
|
-
* }>;
|
|
274
|
-
*
|
|
275
|
-
* type Schema = HttpSchema<{
|
|
276
|
-
* '/users': {
|
|
277
|
-
* GET: UserListMethod;
|
|
278
|
-
* };
|
|
279
|
-
* }>;
|
|
280
|
-
*/
|
|
212
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-schema#httpschemamethod `HttpSchema.Method` API reference} */
|
|
281
213
|
export type Method<Schema extends HttpMethodSchema> = Schema;
|
|
282
214
|
|
|
283
|
-
/**
|
|
284
|
-
* Declares an HTTP service request schema.
|
|
285
|
-
*
|
|
286
|
-
* @example
|
|
287
|
-
* import { type HttpSchema } from '@zimic/http';
|
|
288
|
-
*
|
|
289
|
-
* type UserCreationRequest = HttpSchema.Request<{
|
|
290
|
-
* headers: { 'content-type': 'application/json' };
|
|
291
|
-
* body: User;
|
|
292
|
-
* }>;
|
|
293
|
-
*
|
|
294
|
-
* type Schema = HttpSchema<{
|
|
295
|
-
* '/users': {
|
|
296
|
-
* POST: {
|
|
297
|
-
* request: UserCreationRequest;
|
|
298
|
-
* response: {
|
|
299
|
-
* 201: { body: User };
|
|
300
|
-
* };
|
|
301
|
-
* };
|
|
302
|
-
* };
|
|
303
|
-
* }>;
|
|
304
|
-
*/
|
|
215
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-schema#httpschemarequest `HttpSchema.Request` API reference} */
|
|
305
216
|
export type Request<Schema extends HttpRequestSchema> = Schema;
|
|
306
217
|
|
|
307
|
-
/**
|
|
308
|
-
* Declares an HTTP service response schema by status code.
|
|
309
|
-
*
|
|
310
|
-
* @example
|
|
311
|
-
* import { type HttpSchema } from '@zimic/http';
|
|
312
|
-
*
|
|
313
|
-
* type UserListResponseByStatusCode = HttpSchema.ResponseByStatusCode<{
|
|
314
|
-
* 200: { body: User[] };
|
|
315
|
-
* 400: { body: { message: string } };
|
|
316
|
-
* }>;
|
|
317
|
-
*
|
|
318
|
-
* type Schema = HttpSchema<{
|
|
319
|
-
* '/users': {
|
|
320
|
-
* GET: {
|
|
321
|
-
* response: UserListResponseByStatusCode;
|
|
322
|
-
* };
|
|
323
|
-
* };
|
|
324
|
-
* }>;
|
|
325
|
-
*/
|
|
218
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-schema#httpschemaresponsebystatuscode `HttpSchema.ResponseByStatusCode` API reference} */
|
|
326
219
|
export type ResponseByStatusCode<Schema extends HttpResponseSchemaByStatusCode> = Schema;
|
|
327
220
|
|
|
328
|
-
/**
|
|
329
|
-
* Declares an HTTP service response schema.
|
|
330
|
-
*
|
|
331
|
-
* @example
|
|
332
|
-
* import { type HttpSchema } from '@zimic/http';
|
|
333
|
-
*
|
|
334
|
-
* type UserListSuccessResponse = HttpSchema.Response<{
|
|
335
|
-
* body: User[];
|
|
336
|
-
* }>;
|
|
337
|
-
*
|
|
338
|
-
* type Schema = HttpSchema<{
|
|
339
|
-
* '/users': {
|
|
340
|
-
* GET: {
|
|
341
|
-
* response: {
|
|
342
|
-
* 200: UserListSuccessResponse;
|
|
343
|
-
* };
|
|
344
|
-
* };
|
|
345
|
-
* };
|
|
346
|
-
* }>;
|
|
347
|
-
*/
|
|
221
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-schema#httpschemaresponse `HttpSchema.Response` API reference} */
|
|
348
222
|
export type Response<Schema extends HttpResponseSchema> = Schema;
|
|
349
223
|
|
|
350
|
-
/**
|
|
351
|
-
* Declares an HTTP body schema.
|
|
352
|
-
*
|
|
353
|
-
* @example
|
|
354
|
-
* import { type HttpSchema } from '@zimic/http';
|
|
355
|
-
*
|
|
356
|
-
* type UserListSuccessResponseBody = HttpSchema.Body<User[]>;
|
|
357
|
-
*
|
|
358
|
-
* type Schema = HttpSchema<{
|
|
359
|
-
* '/users': {
|
|
360
|
-
* GET: {
|
|
361
|
-
* response: {
|
|
362
|
-
* 200: { body: UserListSuccessResponseBody };
|
|
363
|
-
* };
|
|
364
|
-
* };
|
|
365
|
-
* };
|
|
366
|
-
* }>;
|
|
367
|
-
*/
|
|
224
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-schema#httpschemabody `HttpSchema.Body` API reference} */
|
|
368
225
|
export type Body<Schema extends HttpBody.Loose> = Schema;
|
|
369
226
|
|
|
370
|
-
/**
|
|
371
|
-
* Declares an HTTP headers schema.
|
|
372
|
-
*
|
|
373
|
-
* @example
|
|
374
|
-
* import { type HttpSchema } from '@zimic/http';
|
|
375
|
-
*
|
|
376
|
-
* type UserListHeaders = HttpSchema.Headers<{
|
|
377
|
-
* accept: 'application/json';
|
|
378
|
-
* }>;
|
|
379
|
-
*
|
|
380
|
-
* type Schema = HttpSchema<{
|
|
381
|
-
* '/users': {
|
|
382
|
-
* GET: {
|
|
383
|
-
* request: {
|
|
384
|
-
* headers: UserListHeaders;
|
|
385
|
-
* };
|
|
386
|
-
* response: {
|
|
387
|
-
* 200: { body: User[] };
|
|
388
|
-
* };
|
|
389
|
-
* };
|
|
390
|
-
* };
|
|
391
|
-
* }>;
|
|
392
|
-
*/
|
|
227
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-schema#httpschemaheaders `HttpSchema.Headers` API reference} */
|
|
393
228
|
export type Headers<Schema extends HttpHeadersSchema.Loose> = Schema;
|
|
394
229
|
|
|
395
|
-
/**
|
|
396
|
-
* Declares an HTTP search params schema.
|
|
397
|
-
*
|
|
398
|
-
* @example
|
|
399
|
-
* import { type HttpSchema } from '@zimic/http';
|
|
400
|
-
*
|
|
401
|
-
* type UserListSearchParams = HttpSchema.SearchParams<{
|
|
402
|
-
* limit: `${number}`;
|
|
403
|
-
* offset: `${number}`;
|
|
404
|
-
* }>;
|
|
405
|
-
*
|
|
406
|
-
* type Schema = HttpSchema<{
|
|
407
|
-
* '/users': {
|
|
408
|
-
* GET: {
|
|
409
|
-
* request: {
|
|
410
|
-
* searchParams: UserListSearchParams;
|
|
411
|
-
* };
|
|
412
|
-
* response: {
|
|
413
|
-
* 200: { body: User[] };
|
|
414
|
-
* };
|
|
415
|
-
* };
|
|
416
|
-
* };
|
|
417
|
-
* }>;
|
|
418
|
-
*/
|
|
230
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-schema#httpschemasearchparams `HttpSchema.SearchParams` API reference} */
|
|
419
231
|
export type SearchParams<Schema extends HttpSearchParamsSchema.Loose> = Schema;
|
|
420
232
|
|
|
421
|
-
/**
|
|
422
|
-
* Declares an HTTP path params schema.
|
|
423
|
-
*
|
|
424
|
-
* @example
|
|
425
|
-
* import { type HttpSchema, InferPathParams } from '@zimic/http';
|
|
426
|
-
*
|
|
427
|
-
* type Schema = HttpSchema<{
|
|
428
|
-
* '/users/:userId': {
|
|
429
|
-
* GET: {
|
|
430
|
-
* response: {
|
|
431
|
-
* 200: { body: User };
|
|
432
|
-
* };
|
|
433
|
-
* };
|
|
434
|
-
* };
|
|
435
|
-
* }>;
|
|
436
|
-
*
|
|
437
|
-
* type UserByIdPathParams = HttpSchema.PathParams<{
|
|
438
|
-
* userId: string;
|
|
439
|
-
* }>;
|
|
440
|
-
*
|
|
441
|
-
* // Or infer from the path string
|
|
442
|
-
* type UserByIdPathParams = InferPathParams<Schema, '/users/:userId'>;
|
|
443
|
-
*/
|
|
233
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-schema#httpschemapathparams `HttpSchema.PathParams` API reference} */
|
|
444
234
|
export type PathParams<Schema extends HttpPathParamsSchema.Loose> = Schema;
|
|
445
235
|
|
|
446
|
-
/**
|
|
447
|
-
* Declares an HTTP form data schema.
|
|
448
|
-
*
|
|
449
|
-
* @example
|
|
450
|
-
* import { HttpFormData, type HttpSchema } from '@zimic/http';
|
|
451
|
-
*
|
|
452
|
-
* type UserCreationFormData = HttpFormData<
|
|
453
|
-
* HttpSchema.FormData<{
|
|
454
|
-
* name: string;
|
|
455
|
-
* email: string;
|
|
456
|
-
* }>
|
|
457
|
-
* >;
|
|
458
|
-
*
|
|
459
|
-
* type Schema = HttpSchema<{
|
|
460
|
-
* '/users': {
|
|
461
|
-
* POST: {
|
|
462
|
-
* request: {
|
|
463
|
-
* body: UserCreationFormData;
|
|
464
|
-
* };
|
|
465
|
-
* response: {
|
|
466
|
-
* 201: { body: User };
|
|
467
|
-
* };
|
|
468
|
-
* };
|
|
469
|
-
* };
|
|
470
|
-
* }>;
|
|
471
|
-
*/
|
|
236
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-schema#httpschemaformdata `HttpSchema.FormData` API reference} */
|
|
472
237
|
export type FormData<Schema extends HttpFormDataSchema.Loose> = Schema;
|
|
473
238
|
}
|
|
474
239
|
|
|
475
240
|
/**
|
|
476
241
|
* Extracts the methods from an HTTP service schema.
|
|
477
242
|
*
|
|
478
|
-
* @see {@link https://
|
|
243
|
+
* @see {@link https://zimic.dev/docs/http/api/http-schema `HttpSchema` API reference}
|
|
479
244
|
*/
|
|
480
245
|
export type HttpSchemaMethod<Schema extends HttpSchema> = IfAny<
|
|
481
246
|
Schema,
|
|
@@ -489,100 +254,19 @@ export type AllowAnyStringInPathParams<Path extends string> = Path extends `${in
|
|
|
489
254
|
? `${Prefix}${string}`
|
|
490
255
|
: Path;
|
|
491
256
|
|
|
492
|
-
/**
|
|
493
|
-
* Extracts the paths from an HTTP service schema. Optionally receives a second argument with one or more methods to
|
|
494
|
-
* filter the paths with. Only the methods defined in the schema are allowed.
|
|
495
|
-
*
|
|
496
|
-
* @example
|
|
497
|
-
* import { type HttpSchema, type HttpSchemaPath } from '@zimic/http';
|
|
498
|
-
*
|
|
499
|
-
* type Schema = HttpSchema<{
|
|
500
|
-
* '/users': {
|
|
501
|
-
* GET: {
|
|
502
|
-
* response: { 200: { body: User[] } };
|
|
503
|
-
* };
|
|
504
|
-
* };
|
|
505
|
-
* '/users/:userId': {
|
|
506
|
-
* DELETE: {
|
|
507
|
-
* response: { 200: { body: User } };
|
|
508
|
-
* };
|
|
509
|
-
* };
|
|
510
|
-
* }>;
|
|
511
|
-
*
|
|
512
|
-
* type Path = HttpSchemaPath<Schema>;
|
|
513
|
-
* // "/users" | "/users/:userId" | "/users/${string}"
|
|
514
|
-
*
|
|
515
|
-
* type GetPath = HttpSchemaPath<Schema, 'GET'>;
|
|
516
|
-
* // "/users"
|
|
517
|
-
*
|
|
518
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http‐schemas Declaring HTTP interceptor schemas}
|
|
519
|
-
*/
|
|
257
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-schema#httpschemapath `HttpSchemaPath` API reference} */
|
|
520
258
|
export namespace HttpSchemaPath {
|
|
521
259
|
type LooseLiteral<Schema extends HttpSchema, Method extends HttpMethod = HttpMethod> = {
|
|
522
260
|
[Path in keyof Schema & string]: Method extends keyof Schema[Path] ? Path : never;
|
|
523
261
|
}[keyof Schema & string];
|
|
524
262
|
|
|
525
|
-
/**
|
|
526
|
-
* Extracts the literal paths from an HTTP service schema. Optionally receives a second argument with one or more
|
|
527
|
-
* methods to filter the paths with. Only the methods defined in the schema are allowed.
|
|
528
|
-
*
|
|
529
|
-
* @example
|
|
530
|
-
* import { type HttpSchema, type HttpSchemaPath } from '@zimic/http';
|
|
531
|
-
*
|
|
532
|
-
* type Schema = HttpSchema<{
|
|
533
|
-
* '/users': {
|
|
534
|
-
* GET: {
|
|
535
|
-
* response: { 200: { body: User[] } };
|
|
536
|
-
* };
|
|
537
|
-
* };
|
|
538
|
-
* '/users/:userId': {
|
|
539
|
-
* DELETE: {
|
|
540
|
-
* response: { 200: { body: User } };
|
|
541
|
-
* };
|
|
542
|
-
* };
|
|
543
|
-
* }>;
|
|
544
|
-
*
|
|
545
|
-
* type LiteralPath = HttpSchemaPath.Literal<Schema>;
|
|
546
|
-
* // "/users" | "/users/:userId"
|
|
547
|
-
*
|
|
548
|
-
* type LiteralGetPath = HttpSchemaPath.Literal<Schema, 'GET'>;
|
|
549
|
-
* // "/users"
|
|
550
|
-
*
|
|
551
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http‐schemas Declaring HTTP interceptor schemas}
|
|
552
|
-
*/
|
|
263
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-schema#httpschemapathliteral `HttpSchemaPath.Literal` API reference} */
|
|
553
264
|
export type Literal<
|
|
554
265
|
Schema extends HttpSchema,
|
|
555
266
|
Method extends HttpSchemaMethod<Schema> = HttpSchemaMethod<Schema>,
|
|
556
267
|
> = LooseLiteral<Schema, Method>;
|
|
557
268
|
|
|
558
|
-
/**
|
|
559
|
-
* Extracts the non-literal paths from an HTTP service schema. Optionally receives a second argument with one or more
|
|
560
|
-
* methods to filter the paths with. Only the methods defined in the schema are allowed.
|
|
561
|
-
*
|
|
562
|
-
* @example
|
|
563
|
-
* import { type HttpSchema, type HttpSchemaPath } from '@zimic/http';
|
|
564
|
-
*
|
|
565
|
-
* type Schema = HttpSchema<{
|
|
566
|
-
* '/users': {
|
|
567
|
-
* GET: {
|
|
568
|
-
* response: { 200: { body: User[] } };
|
|
569
|
-
* };
|
|
570
|
-
* };
|
|
571
|
-
* '/users/:userId': {
|
|
572
|
-
* DELETE: {
|
|
573
|
-
* response: { 200: { body: User } };
|
|
574
|
-
* };
|
|
575
|
-
* };
|
|
576
|
-
* }>;
|
|
577
|
-
*
|
|
578
|
-
* type NonLiteralPath = HttpSchemaPath.NonLiteral<Schema>;
|
|
579
|
-
* // "/users" | "/users/${string}"
|
|
580
|
-
*
|
|
581
|
-
* type NonLiteralGetPath = HttpSchemaPath.NonLiteral<Schema, 'GET'>;
|
|
582
|
-
* // "/users"
|
|
583
|
-
*
|
|
584
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐http‐schemas Declaring HTTP interceptor schemas}
|
|
585
|
-
*/
|
|
269
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-schema#httpschemapathnonliteral `HttpSchemaPath.NonLiteral` API reference} */
|
|
586
270
|
export type NonLiteral<
|
|
587
271
|
Schema extends HttpSchema,
|
|
588
272
|
Method extends HttpSchemaMethod<Schema> = HttpSchemaMethod<Schema>,
|
|
@@ -631,34 +315,7 @@ type RecursiveInferPathParams<Path extends string> = Path extends `${infer _Pref
|
|
|
631
315
|
? { [Name in ParamName]: string }
|
|
632
316
|
: {};
|
|
633
317
|
|
|
634
|
-
/**
|
|
635
|
-
* Infers the path parameters schema from a path string, optionally validating it against an {@link HttpSchema}.
|
|
636
|
-
*
|
|
637
|
-
* If the first argument is a {@link HttpSchema} (recommended), the second argument is checked to be a valid path in that
|
|
638
|
-
* schema.
|
|
639
|
-
*
|
|
640
|
-
* @example
|
|
641
|
-
* import { HttpSchema, InferPathParams } from '@zimic/http';
|
|
642
|
-
*
|
|
643
|
-
* type Schema = HttpSchema<{
|
|
644
|
-
* '/users/:userId': {
|
|
645
|
-
* GET: {
|
|
646
|
-
* response: { 200: { body: User } };
|
|
647
|
-
* };
|
|
648
|
-
* };
|
|
649
|
-
* }>;
|
|
650
|
-
*
|
|
651
|
-
* // Using a schema to validate the path (recommended):
|
|
652
|
-
* type PathParams = InferPathParams<Schema, '/users/:userId'>;
|
|
653
|
-
* // { userId: string }
|
|
654
|
-
*
|
|
655
|
-
* @example
|
|
656
|
-
* import { InferPathParams } from '@zimic/http';
|
|
657
|
-
*
|
|
658
|
-
* // Without using a schema to validate the path (works as `PathParamsSchemaFromPath`):
|
|
659
|
-
* type PathParams = InferPathParams<'/users/:userId'>;
|
|
660
|
-
* // { userId: string }
|
|
661
|
-
*/
|
|
318
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-schema#inferpathparams `InferPathParams` API reference} */
|
|
662
319
|
export type InferPathParams<
|
|
663
320
|
PathOrSchema extends string | HttpSchema,
|
|
664
321
|
OptionalPath extends PathOrSchema extends HttpSchema ? HttpSchemaPath.Literal<PathOrSchema> : never = never,
|
|
@@ -676,39 +333,7 @@ type OmitPastHttpStatusCodes<
|
|
|
676
333
|
? Omit<Schema, keyof UnionToIntersection<PastSchemas[number]>>
|
|
677
334
|
: Schema;
|
|
678
335
|
|
|
679
|
-
/**
|
|
680
|
-
* Merges multiple HTTP response schemas by status code into a single schema. When there are duplicate status codes, the
|
|
681
|
-
* first declaration takes precedence.
|
|
682
|
-
*
|
|
683
|
-
* @example
|
|
684
|
-
* import { type HttpSchema, type HttpStatusCode, MergeHttpResponsesByStatusCode } from '@zimic/http';
|
|
685
|
-
*
|
|
686
|
-
* // Overriding the 400 status code with a more specific schema
|
|
687
|
-
* // and using a generic schema for all other client errors.
|
|
688
|
-
* type MergedResponseByStatusCode = MergeHttpResponsesByStatusCode<
|
|
689
|
-
* [
|
|
690
|
-
* {
|
|
691
|
-
* 400: { body: { message: string; issues: string[] } };
|
|
692
|
-
* },
|
|
693
|
-
* {
|
|
694
|
-
* [StatusCode in HttpStatusCode.ClientError]: { body: { message: string } };
|
|
695
|
-
* },
|
|
696
|
-
* ]
|
|
697
|
-
* >;
|
|
698
|
-
* // {
|
|
699
|
-
* // 400: { body: { message: string; issues: string[] } };
|
|
700
|
-
* // 401: { body: { message: string}; };
|
|
701
|
-
* // 402: { body: { message: string}; };
|
|
702
|
-
* // 403: { body: { message: string}; };
|
|
703
|
-
* // ...
|
|
704
|
-
* // }
|
|
705
|
-
*
|
|
706
|
-
* type Schema = HttpSchema<{
|
|
707
|
-
* '/users': {
|
|
708
|
-
* GET: { response: MergedResponseByStatusCode };
|
|
709
|
-
* };
|
|
710
|
-
* }>;
|
|
711
|
-
*/
|
|
336
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-schema#mergehttpresponsesbystatuscode `MergeHttpResponsesByStatusCode` API reference} */
|
|
712
337
|
export type MergeHttpResponsesByStatusCode<
|
|
713
338
|
Schemas extends HttpResponseSchemaByStatusCode[],
|
|
714
339
|
PastSchemas extends HttpResponseSchemaByStatusCode[] = [],
|