@zimic/http 0.5.0 → 0.5.1-canary.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -170
- package/dist/{chunk-KVTV4E5K.mjs → chunk-3DBBG4IX.mjs} +2 -2
- package/dist/chunk-3DBBG4IX.mjs.map +1 -0
- package/dist/{chunk-LOHINQWU.js → chunk-6NKD7JVQ.js} +2 -2
- package/dist/chunk-6NKD7JVQ.js.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 +88 -458
- package/dist/index.js +36 -145
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +36 -145
- package/dist/index.mjs.map +1 -1
- package/dist/typegen.d.ts +2 -52
- package/dist/typegen.js +2 -2
- package/dist/typegen.mjs +1 -1
- package/package.json +5 -5
- package/src/formData/HttpFormData.ts +15 -92
- package/src/headers/HttpHeaders.ts +14 -45
- 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 +2 -52
- package/src/types/schema.ts +42 -234
- 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,8 @@ 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/guides/schemas Declaring schemas}
|
|
27
|
+
* @see {@link https://zimic.dev/docs/http/api/http-schema `HttpSchema` API reference}
|
|
27
28
|
*/
|
|
28
29
|
export interface HttpRequestSchema {
|
|
29
30
|
headers?: HttpHeadersSchema.Loose;
|
|
@@ -34,7 +35,8 @@ export interface HttpRequestSchema {
|
|
|
34
35
|
/**
|
|
35
36
|
* A schema representing the structure of an HTTP response.
|
|
36
37
|
*
|
|
37
|
-
* @see {@link https://
|
|
38
|
+
* @see {@link https://zimic.dev/docs/http/guides/schemas Declaring schemas}
|
|
39
|
+
* @see {@link https://zimic.dev/docs/http/api/http-schema `HttpSchema` API reference}
|
|
38
40
|
*/
|
|
39
41
|
export interface HttpResponseSchema {
|
|
40
42
|
headers?: HttpHeadersSchema.Loose;
|
|
@@ -159,7 +161,8 @@ export namespace HttpStatusCode {
|
|
|
159
161
|
/**
|
|
160
162
|
* A schema representing the structure of HTTP responses by status code.
|
|
161
163
|
*
|
|
162
|
-
* @see {@link https://
|
|
164
|
+
* @see {@link https://zimic.dev/docs/http/guides/schemas Declaring schemas}
|
|
165
|
+
* @see {@link https://zimic.dev/docs/http/api/http-schema `HttpSchema` API reference}
|
|
163
166
|
*/
|
|
164
167
|
export type HttpResponseSchemaByStatusCode = {
|
|
165
168
|
[StatusCode in HttpStatusCode]?: HttpResponseSchema;
|
|
@@ -168,7 +171,8 @@ export type HttpResponseSchemaByStatusCode = {
|
|
|
168
171
|
/**
|
|
169
172
|
* Extracts the status codes used in a response schema by status code.
|
|
170
173
|
*
|
|
171
|
-
* @see {@link https://
|
|
174
|
+
* @see {@link https://zimic.dev/docs/http/guides/schemas Declaring schemas}
|
|
175
|
+
* @see {@link https://zimic.dev/docs/http/api/http-schema `HttpSchema` API reference}
|
|
172
176
|
*/
|
|
173
177
|
export type HttpResponseSchemaStatusCode<ResponseSchemaByStatusCode extends HttpResponseSchemaByStatusCode> =
|
|
174
178
|
keyof ResponseSchemaByStatusCode & HttpStatusCode;
|
|
@@ -176,7 +180,8 @@ export type HttpResponseSchemaStatusCode<ResponseSchemaByStatusCode extends Http
|
|
|
176
180
|
/**
|
|
177
181
|
* A schema representing the structure of an HTTP request and response for a given method.
|
|
178
182
|
*
|
|
179
|
-
* @see {@link https://
|
|
183
|
+
* @see {@link https://zimic.dev/docs/http/guides/schemas Declaring schemas}
|
|
184
|
+
* @see {@link https://zimic.dev/docs/http/api/http-schema `HttpSchema` API reference}
|
|
180
185
|
*/
|
|
181
186
|
export interface HttpMethodSchema {
|
|
182
187
|
request?: HttpRequestSchema;
|
|
@@ -186,7 +191,8 @@ export interface HttpMethodSchema {
|
|
|
186
191
|
/**
|
|
187
192
|
* A schema representing the structure of HTTP request and response by method.
|
|
188
193
|
*
|
|
189
|
-
* @see {@link https://
|
|
194
|
+
* @see {@link https://zimic.dev/docs/http/guides/schemas Declaring schemas}
|
|
195
|
+
* @see {@link https://zimic.dev/docs/http/api/http-schema `HttpSchema` API reference}
|
|
190
196
|
*/
|
|
191
197
|
export interface HttpMethodsSchema {
|
|
192
198
|
GET?: HttpMethodSchema;
|
|
@@ -203,271 +209,69 @@ interface BaseHttpSchema {
|
|
|
203
209
|
}
|
|
204
210
|
|
|
205
211
|
/**
|
|
206
|
-
*
|
|
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}
|
|
212
|
+
* @see {@link https://zimic.dev/docs/http/guides/schemas Declaring schemas}
|
|
213
|
+
* @see {@link https://zimic.dev/docs/http/api/http-schema `HttpSchema` API reference}
|
|
239
214
|
*/
|
|
240
215
|
export type HttpSchema<Schema extends BaseHttpSchema = BaseHttpSchema> = Branded<Schema, 'HttpSchema'>;
|
|
241
216
|
|
|
242
217
|
export namespace HttpSchema {
|
|
243
218
|
/**
|
|
244
|
-
*
|
|
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
|
-
* }>;
|
|
219
|
+
* @see {@link https://zimic.dev/docs/http/guides/schemas Declaring schemas}
|
|
220
|
+
* @see {@link https://zimic.dev/docs/http/api/http-schema#httpschemamethods `HttpSchema.Methods` API reference}
|
|
260
221
|
*/
|
|
261
222
|
export type Methods<Schema extends HttpMethodsSchema> = Schema;
|
|
262
223
|
|
|
263
224
|
/**
|
|
264
|
-
*
|
|
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
|
-
* }>;
|
|
225
|
+
* @see {@link https://zimic.dev/docs/http/guides/schemas Declaring schemas}
|
|
226
|
+
* @see {@link https://zimic.dev/docs/http/api/http-schema#httpschemamethod `HttpSchema.Method` API reference}
|
|
280
227
|
*/
|
|
281
228
|
export type Method<Schema extends HttpMethodSchema> = Schema;
|
|
282
229
|
|
|
283
230
|
/**
|
|
284
|
-
*
|
|
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
|
-
* }>;
|
|
231
|
+
* @see {@link https://zimic.dev/docs/http/guides/schemas Declaring schemas}
|
|
232
|
+
* @see {@link https://zimic.dev/docs/http/api/http-schema#httpschemarequest `HttpSchema.Request` API reference}
|
|
304
233
|
*/
|
|
305
234
|
export type Request<Schema extends HttpRequestSchema> = Schema;
|
|
306
235
|
|
|
307
236
|
/**
|
|
308
|
-
*
|
|
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
|
-
* }>;
|
|
237
|
+
* @see {@link https://zimic.dev/docs/http/guides/schemas Declaring schemas}
|
|
238
|
+
* @see {@link https://zimic.dev/docs/http/api/http-schema#httpschemaresponsebystatuscode `HttpSchema.ResponseByStatusCode` API reference}
|
|
325
239
|
*/
|
|
326
240
|
export type ResponseByStatusCode<Schema extends HttpResponseSchemaByStatusCode> = Schema;
|
|
327
241
|
|
|
328
242
|
/**
|
|
329
|
-
*
|
|
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
|
-
* }>;
|
|
243
|
+
* @see {@link https://zimic.dev/docs/http/guides/schemas Declaring schemas}
|
|
244
|
+
* @see {@link https://zimic.dev/docs/http/api/http-schema#httpschemaresponse `HttpSchema.Response` API reference}
|
|
347
245
|
*/
|
|
348
246
|
export type Response<Schema extends HttpResponseSchema> = Schema;
|
|
349
247
|
|
|
350
248
|
/**
|
|
351
|
-
*
|
|
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
|
-
* }>;
|
|
249
|
+
* @see {@link https://zimic.dev/docs/http/guides/schemas Declaring schemas}
|
|
250
|
+
* @see {@link https://zimic.dev/docs/http/api/http-schema#httpschemabody `HttpSchema.Body` API reference}
|
|
367
251
|
*/
|
|
368
252
|
export type Body<Schema extends HttpBody.Loose> = Schema;
|
|
369
253
|
|
|
370
254
|
/**
|
|
371
|
-
*
|
|
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
|
-
* }>;
|
|
255
|
+
* @see {@link https://zimic.dev/docs/http/guides/schemas Declaring schemas}
|
|
256
|
+
* @see {@link https://zimic.dev/docs/http/api/http-schema#httpschemaheaders `HttpSchema.Headers` API reference}
|
|
392
257
|
*/
|
|
393
258
|
export type Headers<Schema extends HttpHeadersSchema.Loose> = Schema;
|
|
394
259
|
|
|
395
260
|
/**
|
|
396
|
-
*
|
|
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
|
-
* }>;
|
|
261
|
+
* @see {@link https://zimic.dev/docs/http/guides/schemas Declaring schemas}
|
|
262
|
+
* @see {@link https://zimic.dev/docs/http/api/http-schema#httpschemasearchparams `HttpSchema.SearchParams` API reference}
|
|
418
263
|
*/
|
|
419
264
|
export type SearchParams<Schema extends HttpSearchParamsSchema.Loose> = Schema;
|
|
420
265
|
|
|
421
266
|
/**
|
|
422
|
-
*
|
|
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'>;
|
|
267
|
+
* @see {@link https://zimic.dev/docs/http/guides/schemas Declaring schemas}
|
|
268
|
+
* @see {@link https://zimic.dev/docs/http/api/http-schema#httpschemapathparams `HttpSchema.PathParams` API reference}
|
|
443
269
|
*/
|
|
444
270
|
export type PathParams<Schema extends HttpPathParamsSchema.Loose> = Schema;
|
|
445
271
|
|
|
446
272
|
/**
|
|
447
|
-
*
|
|
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
|
-
* }>;
|
|
273
|
+
* @see {@link https://zimic.dev/docs/http/guides/schemas Declaring schemas}
|
|
274
|
+
* @see {@link https://zimic.dev/docs/http/api/http-schema#httpschemaformdata `HttpSchema.FormData` API reference}
|
|
471
275
|
*/
|
|
472
276
|
export type FormData<Schema extends HttpFormDataSchema.Loose> = Schema;
|
|
473
277
|
}
|
|
@@ -475,7 +279,8 @@ export namespace HttpSchema {
|
|
|
475
279
|
/**
|
|
476
280
|
* Extracts the methods from an HTTP service schema.
|
|
477
281
|
*
|
|
478
|
-
* @see {@link https://
|
|
282
|
+
* @see {@link https://zimic.dev/docs/http/guides/schemas Declaring schemas}
|
|
283
|
+
* @see {@link https://zimic.dev/docs/http/api/http-schema `HttpSchema` API reference}
|
|
479
284
|
*/
|
|
480
285
|
export type HttpSchemaMethod<Schema extends HttpSchema> = IfAny<
|
|
481
286
|
Schema,
|
|
@@ -515,7 +320,8 @@ export type AllowAnyStringInPathParams<Path extends string> = Path extends `${in
|
|
|
515
320
|
* type GetPath = HttpSchemaPath<Schema, 'GET'>;
|
|
516
321
|
* // "/users"
|
|
517
322
|
*
|
|
518
|
-
* @see {@link https://
|
|
323
|
+
* @see {@link https://zimic.dev/docs/http/guides/schemas Declaring schemas}
|
|
324
|
+
* @see {@link https://zimic.dev/docs/http/api/http-schema `HttpSchema` API reference}
|
|
519
325
|
*/
|
|
520
326
|
export namespace HttpSchemaPath {
|
|
521
327
|
type LooseLiteral<Schema extends HttpSchema, Method extends HttpMethod = HttpMethod> = {
|
|
@@ -548,7 +354,8 @@ export namespace HttpSchemaPath {
|
|
|
548
354
|
* type LiteralGetPath = HttpSchemaPath.Literal<Schema, 'GET'>;
|
|
549
355
|
* // "/users"
|
|
550
356
|
*
|
|
551
|
-
* @see {@link https://
|
|
357
|
+
* @see {@link https://zimic.dev/docs/http/guides/schemas Declaring schemas}
|
|
358
|
+
* @see {@link https://zimic.dev/docs/http/api/http-schema `HttpSchema` API reference} `}
|
|
552
359
|
*/
|
|
553
360
|
export type Literal<
|
|
554
361
|
Schema extends HttpSchema,
|
|
@@ -581,7 +388,8 @@ export namespace HttpSchemaPath {
|
|
|
581
388
|
* type NonLiteralGetPath = HttpSchemaPath.NonLiteral<Schema, 'GET'>;
|
|
582
389
|
* // "/users"
|
|
583
390
|
*
|
|
584
|
-
* @see {@link https://
|
|
391
|
+
* @see {@link https://zimic.dev/docs/http/guides/schemas Declaring schemas}
|
|
392
|
+
* @see {@link https://zimic.dev/docs/http/api/http-schema `HttpSchema` API reference} `}
|
|
585
393
|
*/
|
|
586
394
|
export type NonLiteral<
|
|
587
395
|
Schema extends HttpSchema,
|