@zimic/http 0.5.1-canary.1 → 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-6NKD7JVQ.js → chunk-CFBC3ABT.js} +2 -2
- package/dist/chunk-CFBC3ABT.js.map +1 -0
- package/dist/{chunk-3DBBG4IX.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 +17 -212
- package/dist/index.js +1 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -13
- package/dist/index.mjs.map +1 -1
- package/dist/typegen.d.ts +8 -1
- package/dist/typegen.js +2 -2
- package/dist/typegen.mjs +1 -1
- package/package.json +4 -4
- package/src/headers/HttpHeaders.ts +1 -13
- package/src/typegen/openapi/generate.ts +8 -1
- package/src/types/schema.ts +16 -199
- package/dist/chunk-3DBBG4IX.mjs.map +0 -1
- package/dist/chunk-6NKD7JVQ.js.map +0 -1
package/src/types/schema.ts
CHANGED
|
@@ -23,7 +23,6 @@ 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://zimic.dev/docs/http/guides/schemas Declaring schemas}
|
|
27
26
|
* @see {@link https://zimic.dev/docs/http/api/http-schema `HttpSchema` API reference}
|
|
28
27
|
*/
|
|
29
28
|
export interface HttpRequestSchema {
|
|
@@ -35,7 +34,6 @@ export interface HttpRequestSchema {
|
|
|
35
34
|
/**
|
|
36
35
|
* A schema representing the structure of an HTTP response.
|
|
37
36
|
*
|
|
38
|
-
* @see {@link https://zimic.dev/docs/http/guides/schemas Declaring schemas}
|
|
39
37
|
* @see {@link https://zimic.dev/docs/http/api/http-schema `HttpSchema` API reference}
|
|
40
38
|
*/
|
|
41
39
|
export interface HttpResponseSchema {
|
|
@@ -161,7 +159,6 @@ export namespace HttpStatusCode {
|
|
|
161
159
|
/**
|
|
162
160
|
* A schema representing the structure of HTTP responses by status code.
|
|
163
161
|
*
|
|
164
|
-
* @see {@link https://zimic.dev/docs/http/guides/schemas Declaring schemas}
|
|
165
162
|
* @see {@link https://zimic.dev/docs/http/api/http-schema `HttpSchema` API reference}
|
|
166
163
|
*/
|
|
167
164
|
export type HttpResponseSchemaByStatusCode = {
|
|
@@ -171,7 +168,6 @@ export type HttpResponseSchemaByStatusCode = {
|
|
|
171
168
|
/**
|
|
172
169
|
* Extracts the status codes used in a response schema by status code.
|
|
173
170
|
*
|
|
174
|
-
* @see {@link https://zimic.dev/docs/http/guides/schemas Declaring schemas}
|
|
175
171
|
* @see {@link https://zimic.dev/docs/http/api/http-schema `HttpSchema` API reference}
|
|
176
172
|
*/
|
|
177
173
|
export type HttpResponseSchemaStatusCode<ResponseSchemaByStatusCode extends HttpResponseSchemaByStatusCode> =
|
|
@@ -180,7 +176,6 @@ export type HttpResponseSchemaStatusCode<ResponseSchemaByStatusCode extends Http
|
|
|
180
176
|
/**
|
|
181
177
|
* A schema representing the structure of an HTTP request and response for a given method.
|
|
182
178
|
*
|
|
183
|
-
* @see {@link https://zimic.dev/docs/http/guides/schemas Declaring schemas}
|
|
184
179
|
* @see {@link https://zimic.dev/docs/http/api/http-schema `HttpSchema` API reference}
|
|
185
180
|
*/
|
|
186
181
|
export interface HttpMethodSchema {
|
|
@@ -191,7 +186,6 @@ export interface HttpMethodSchema {
|
|
|
191
186
|
/**
|
|
192
187
|
* A schema representing the structure of HTTP request and response by method.
|
|
193
188
|
*
|
|
194
|
-
* @see {@link https://zimic.dev/docs/http/guides/schemas Declaring schemas}
|
|
195
189
|
* @see {@link https://zimic.dev/docs/http/api/http-schema `HttpSchema` API reference}
|
|
196
190
|
*/
|
|
197
191
|
export interface HttpMethodsSchema {
|
|
@@ -208,78 +202,44 @@ interface BaseHttpSchema {
|
|
|
208
202
|
[path: string]: HttpMethodsSchema;
|
|
209
203
|
}
|
|
210
204
|
|
|
211
|
-
/**
|
|
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}
|
|
214
|
-
*/
|
|
205
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-schema `HttpSchema` API reference} */
|
|
215
206
|
export type HttpSchema<Schema extends BaseHttpSchema = BaseHttpSchema> = Branded<Schema, 'HttpSchema'>;
|
|
216
207
|
|
|
217
208
|
export namespace HttpSchema {
|
|
218
|
-
/**
|
|
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}
|
|
221
|
-
*/
|
|
209
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-schema#httpschemamethods `HttpSchema.Methods` API reference} */
|
|
222
210
|
export type Methods<Schema extends HttpMethodsSchema> = Schema;
|
|
223
211
|
|
|
224
|
-
/**
|
|
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}
|
|
227
|
-
*/
|
|
212
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-schema#httpschemamethod `HttpSchema.Method` API reference} */
|
|
228
213
|
export type Method<Schema extends HttpMethodSchema> = Schema;
|
|
229
214
|
|
|
230
|
-
/**
|
|
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}
|
|
233
|
-
*/
|
|
215
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-schema#httpschemarequest `HttpSchema.Request` API reference} */
|
|
234
216
|
export type Request<Schema extends HttpRequestSchema> = Schema;
|
|
235
217
|
|
|
236
|
-
/**
|
|
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}
|
|
239
|
-
*/
|
|
218
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-schema#httpschemaresponsebystatuscode `HttpSchema.ResponseByStatusCode` API reference} */
|
|
240
219
|
export type ResponseByStatusCode<Schema extends HttpResponseSchemaByStatusCode> = Schema;
|
|
241
220
|
|
|
242
|
-
/**
|
|
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}
|
|
245
|
-
*/
|
|
221
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-schema#httpschemaresponse `HttpSchema.Response` API reference} */
|
|
246
222
|
export type Response<Schema extends HttpResponseSchema> = Schema;
|
|
247
223
|
|
|
248
|
-
/**
|
|
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}
|
|
251
|
-
*/
|
|
224
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-schema#httpschemabody `HttpSchema.Body` API reference} */
|
|
252
225
|
export type Body<Schema extends HttpBody.Loose> = Schema;
|
|
253
226
|
|
|
254
|
-
/**
|
|
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}
|
|
257
|
-
*/
|
|
227
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-schema#httpschemaheaders `HttpSchema.Headers` API reference} */
|
|
258
228
|
export type Headers<Schema extends HttpHeadersSchema.Loose> = Schema;
|
|
259
229
|
|
|
260
|
-
/**
|
|
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}
|
|
263
|
-
*/
|
|
230
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-schema#httpschemasearchparams `HttpSchema.SearchParams` API reference} */
|
|
264
231
|
export type SearchParams<Schema extends HttpSearchParamsSchema.Loose> = Schema;
|
|
265
232
|
|
|
266
|
-
/**
|
|
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}
|
|
269
|
-
*/
|
|
233
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-schema#httpschemapathparams `HttpSchema.PathParams` API reference} */
|
|
270
234
|
export type PathParams<Schema extends HttpPathParamsSchema.Loose> = Schema;
|
|
271
235
|
|
|
272
|
-
/**
|
|
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}
|
|
275
|
-
*/
|
|
236
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-schema#httpschemaformdata `HttpSchema.FormData` API reference} */
|
|
276
237
|
export type FormData<Schema extends HttpFormDataSchema.Loose> = Schema;
|
|
277
238
|
}
|
|
278
239
|
|
|
279
240
|
/**
|
|
280
241
|
* Extracts the methods from an HTTP service schema.
|
|
281
242
|
*
|
|
282
|
-
* @see {@link https://zimic.dev/docs/http/guides/schemas Declaring schemas}
|
|
283
243
|
* @see {@link https://zimic.dev/docs/http/api/http-schema `HttpSchema` API reference}
|
|
284
244
|
*/
|
|
285
245
|
export type HttpSchemaMethod<Schema extends HttpSchema> = IfAny<
|
|
@@ -294,103 +254,19 @@ export type AllowAnyStringInPathParams<Path extends string> = Path extends `${in
|
|
|
294
254
|
? `${Prefix}${string}`
|
|
295
255
|
: Path;
|
|
296
256
|
|
|
297
|
-
/**
|
|
298
|
-
* Extracts the paths from an HTTP service schema. Optionally receives a second argument with one or more methods to
|
|
299
|
-
* filter the paths with. Only the methods defined in the schema are allowed.
|
|
300
|
-
*
|
|
301
|
-
* @example
|
|
302
|
-
* import { type HttpSchema, type HttpSchemaPath } from '@zimic/http';
|
|
303
|
-
*
|
|
304
|
-
* type Schema = HttpSchema<{
|
|
305
|
-
* '/users': {
|
|
306
|
-
* GET: {
|
|
307
|
-
* response: { 200: { body: User[] } };
|
|
308
|
-
* };
|
|
309
|
-
* };
|
|
310
|
-
* '/users/:userId': {
|
|
311
|
-
* DELETE: {
|
|
312
|
-
* response: { 200: { body: User } };
|
|
313
|
-
* };
|
|
314
|
-
* };
|
|
315
|
-
* }>;
|
|
316
|
-
*
|
|
317
|
-
* type Path = HttpSchemaPath<Schema>;
|
|
318
|
-
* // "/users" | "/users/:userId" | "/users/${string}"
|
|
319
|
-
*
|
|
320
|
-
* type GetPath = HttpSchemaPath<Schema, 'GET'>;
|
|
321
|
-
* // "/users"
|
|
322
|
-
*
|
|
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}
|
|
325
|
-
*/
|
|
257
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-schema#httpschemapath `HttpSchemaPath` API reference} */
|
|
326
258
|
export namespace HttpSchemaPath {
|
|
327
259
|
type LooseLiteral<Schema extends HttpSchema, Method extends HttpMethod = HttpMethod> = {
|
|
328
260
|
[Path in keyof Schema & string]: Method extends keyof Schema[Path] ? Path : never;
|
|
329
261
|
}[keyof Schema & string];
|
|
330
262
|
|
|
331
|
-
/**
|
|
332
|
-
* Extracts the literal paths from an HTTP service schema. Optionally receives a second argument with one or more
|
|
333
|
-
* methods to filter the paths with. Only the methods defined in the schema are allowed.
|
|
334
|
-
*
|
|
335
|
-
* @example
|
|
336
|
-
* import { type HttpSchema, type HttpSchemaPath } from '@zimic/http';
|
|
337
|
-
*
|
|
338
|
-
* type Schema = HttpSchema<{
|
|
339
|
-
* '/users': {
|
|
340
|
-
* GET: {
|
|
341
|
-
* response: { 200: { body: User[] } };
|
|
342
|
-
* };
|
|
343
|
-
* };
|
|
344
|
-
* '/users/:userId': {
|
|
345
|
-
* DELETE: {
|
|
346
|
-
* response: { 200: { body: User } };
|
|
347
|
-
* };
|
|
348
|
-
* };
|
|
349
|
-
* }>;
|
|
350
|
-
*
|
|
351
|
-
* type LiteralPath = HttpSchemaPath.Literal<Schema>;
|
|
352
|
-
* // "/users" | "/users/:userId"
|
|
353
|
-
*
|
|
354
|
-
* type LiteralGetPath = HttpSchemaPath.Literal<Schema, 'GET'>;
|
|
355
|
-
* // "/users"
|
|
356
|
-
*
|
|
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} `}
|
|
359
|
-
*/
|
|
263
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-schema#httpschemapathliteral `HttpSchemaPath.Literal` API reference} */
|
|
360
264
|
export type Literal<
|
|
361
265
|
Schema extends HttpSchema,
|
|
362
266
|
Method extends HttpSchemaMethod<Schema> = HttpSchemaMethod<Schema>,
|
|
363
267
|
> = LooseLiteral<Schema, Method>;
|
|
364
268
|
|
|
365
|
-
/**
|
|
366
|
-
* Extracts the non-literal paths from an HTTP service schema. Optionally receives a second argument with one or more
|
|
367
|
-
* methods to filter the paths with. Only the methods defined in the schema are allowed.
|
|
368
|
-
*
|
|
369
|
-
* @example
|
|
370
|
-
* import { type HttpSchema, type HttpSchemaPath } from '@zimic/http';
|
|
371
|
-
*
|
|
372
|
-
* type Schema = HttpSchema<{
|
|
373
|
-
* '/users': {
|
|
374
|
-
* GET: {
|
|
375
|
-
* response: { 200: { body: User[] } };
|
|
376
|
-
* };
|
|
377
|
-
* };
|
|
378
|
-
* '/users/:userId': {
|
|
379
|
-
* DELETE: {
|
|
380
|
-
* response: { 200: { body: User } };
|
|
381
|
-
* };
|
|
382
|
-
* };
|
|
383
|
-
* }>;
|
|
384
|
-
*
|
|
385
|
-
* type NonLiteralPath = HttpSchemaPath.NonLiteral<Schema>;
|
|
386
|
-
* // "/users" | "/users/${string}"
|
|
387
|
-
*
|
|
388
|
-
* type NonLiteralGetPath = HttpSchemaPath.NonLiteral<Schema, 'GET'>;
|
|
389
|
-
* // "/users"
|
|
390
|
-
*
|
|
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} `}
|
|
393
|
-
*/
|
|
269
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-schema#httpschemapathnonliteral `HttpSchemaPath.NonLiteral` API reference} */
|
|
394
270
|
export type NonLiteral<
|
|
395
271
|
Schema extends HttpSchema,
|
|
396
272
|
Method extends HttpSchemaMethod<Schema> = HttpSchemaMethod<Schema>,
|
|
@@ -439,34 +315,7 @@ type RecursiveInferPathParams<Path extends string> = Path extends `${infer _Pref
|
|
|
439
315
|
? { [Name in ParamName]: string }
|
|
440
316
|
: {};
|
|
441
317
|
|
|
442
|
-
/**
|
|
443
|
-
* Infers the path parameters schema from a path string, optionally validating it against an {@link HttpSchema}.
|
|
444
|
-
*
|
|
445
|
-
* If the first argument is a {@link HttpSchema} (recommended), the second argument is checked to be a valid path in that
|
|
446
|
-
* schema.
|
|
447
|
-
*
|
|
448
|
-
* @example
|
|
449
|
-
* import { HttpSchema, InferPathParams } from '@zimic/http';
|
|
450
|
-
*
|
|
451
|
-
* type Schema = HttpSchema<{
|
|
452
|
-
* '/users/:userId': {
|
|
453
|
-
* GET: {
|
|
454
|
-
* response: { 200: { body: User } };
|
|
455
|
-
* };
|
|
456
|
-
* };
|
|
457
|
-
* }>;
|
|
458
|
-
*
|
|
459
|
-
* // Using a schema to validate the path (recommended):
|
|
460
|
-
* type PathParams = InferPathParams<Schema, '/users/:userId'>;
|
|
461
|
-
* // { userId: string }
|
|
462
|
-
*
|
|
463
|
-
* @example
|
|
464
|
-
* import { InferPathParams } from '@zimic/http';
|
|
465
|
-
*
|
|
466
|
-
* // Without using a schema to validate the path (works as `PathParamsSchemaFromPath`):
|
|
467
|
-
* type PathParams = InferPathParams<'/users/:userId'>;
|
|
468
|
-
* // { userId: string }
|
|
469
|
-
*/
|
|
318
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-schema#inferpathparams `InferPathParams` API reference} */
|
|
470
319
|
export type InferPathParams<
|
|
471
320
|
PathOrSchema extends string | HttpSchema,
|
|
472
321
|
OptionalPath extends PathOrSchema extends HttpSchema ? HttpSchemaPath.Literal<PathOrSchema> : never = never,
|
|
@@ -484,39 +333,7 @@ type OmitPastHttpStatusCodes<
|
|
|
484
333
|
? Omit<Schema, keyof UnionToIntersection<PastSchemas[number]>>
|
|
485
334
|
: Schema;
|
|
486
335
|
|
|
487
|
-
/**
|
|
488
|
-
* Merges multiple HTTP response schemas by status code into a single schema. When there are duplicate status codes, the
|
|
489
|
-
* first declaration takes precedence.
|
|
490
|
-
*
|
|
491
|
-
* @example
|
|
492
|
-
* import { type HttpSchema, type HttpStatusCode, MergeHttpResponsesByStatusCode } from '@zimic/http';
|
|
493
|
-
*
|
|
494
|
-
* // Overriding the 400 status code with a more specific schema
|
|
495
|
-
* // and using a generic schema for all other client errors.
|
|
496
|
-
* type MergedResponseByStatusCode = MergeHttpResponsesByStatusCode<
|
|
497
|
-
* [
|
|
498
|
-
* {
|
|
499
|
-
* 400: { body: { message: string; issues: string[] } };
|
|
500
|
-
* },
|
|
501
|
-
* {
|
|
502
|
-
* [StatusCode in HttpStatusCode.ClientError]: { body: { message: string } };
|
|
503
|
-
* },
|
|
504
|
-
* ]
|
|
505
|
-
* >;
|
|
506
|
-
* // {
|
|
507
|
-
* // 400: { body: { message: string; issues: string[] } };
|
|
508
|
-
* // 401: { body: { message: string}; };
|
|
509
|
-
* // 402: { body: { message: string}; };
|
|
510
|
-
* // 403: { body: { message: string}; };
|
|
511
|
-
* // ...
|
|
512
|
-
* // }
|
|
513
|
-
*
|
|
514
|
-
* type Schema = HttpSchema<{
|
|
515
|
-
* '/users': {
|
|
516
|
-
* GET: { response: MergedResponseByStatusCode };
|
|
517
|
-
* };
|
|
518
|
-
* }>;
|
|
519
|
-
*/
|
|
336
|
+
/** @see {@link https://zimic.dev/docs/http/api/http-schema#mergehttpresponsesbystatuscode `MergeHttpResponsesByStatusCode` API reference} */
|
|
520
337
|
export type MergeHttpResponsesByStatusCode<
|
|
521
338
|
Schemas extends HttpResponseSchemaByStatusCode[],
|
|
522
339
|
PastSchemas extends HttpResponseSchemaByStatusCode[] = [],
|