express-zod-api 16.1.0 → 16.2.0-beta1
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/CHANGELOG.md +69 -1
- package/LICENSE +1 -1
- package/README.md +40 -3
- package/dist/index.cjs +7 -7
- package/dist/index.d.cts +147 -245
- package/dist/index.d.ts +147 -245
- package/dist/index.js +7 -7
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -3,15 +3,42 @@ import express, { Request, Response, NextFunction, RequestHandler, IRouter } fro
|
|
|
3
3
|
import fileUpload, { UploadedFile } from 'express-fileupload';
|
|
4
4
|
import https, { ServerOptions } from 'node:https';
|
|
5
5
|
import { z, ZodTypeDef, ZodType, ParseInput, ParseReturnType, ZodError } from 'zod';
|
|
6
|
-
import { HttpError } from 'http-errors';
|
|
7
6
|
import Winston from 'winston';
|
|
7
|
+
import { HttpError } from 'http-errors';
|
|
8
8
|
import { ListenOptions } from 'node:net';
|
|
9
9
|
import * as qs from 'qs';
|
|
10
10
|
import * as express_serve_static_core from 'express-serve-static-core';
|
|
11
11
|
import http from 'node:http';
|
|
12
|
-
import {
|
|
12
|
+
import { OpenApiBuilder, SecuritySchemeType, SchemaObject, ReferenceObject, SecuritySchemeObject } from 'openapi3-ts/oas31';
|
|
13
13
|
import ts from 'typescript';
|
|
14
14
|
|
|
15
|
+
interface ApiResponse<S extends z.ZodTypeAny> {
|
|
16
|
+
schema: S;
|
|
17
|
+
/**
|
|
18
|
+
* @default 200 for a positive response
|
|
19
|
+
* @default 400 for a negative response
|
|
20
|
+
* @override statusCodes
|
|
21
|
+
* */
|
|
22
|
+
statusCode?: number;
|
|
23
|
+
/**
|
|
24
|
+
* @default [200] for positive response
|
|
25
|
+
* @default [400] for negative response
|
|
26
|
+
* */
|
|
27
|
+
statusCodes?: [number, ...number[]];
|
|
28
|
+
/**
|
|
29
|
+
* @default "application/json"
|
|
30
|
+
* @override mimeTypes
|
|
31
|
+
* */
|
|
32
|
+
mimeType?: string;
|
|
33
|
+
/** @default [ "application/json" ] */
|
|
34
|
+
mimeTypes?: [string, ...string[]];
|
|
35
|
+
}
|
|
36
|
+
type MultipleApiResponses = [
|
|
37
|
+
ApiResponse<z.ZodTypeAny>,
|
|
38
|
+
...ApiResponse<z.ZodTypeAny>[]
|
|
39
|
+
];
|
|
40
|
+
type NormalizedResponse = Required<Pick<ApiResponse<z.ZodTypeAny>, "schema" | "statusCodes" | "mimeTypes">>;
|
|
41
|
+
|
|
15
42
|
type LogicalOr<T> = {
|
|
16
43
|
or: T[];
|
|
17
44
|
};
|
|
@@ -182,112 +209,6 @@ type WithMeta<T extends z.ZodTypeAny> = T & {
|
|
|
182
209
|
};
|
|
183
210
|
declare const withMeta: <T extends z.ZodTypeAny>(schema: T) => WithMeta<T>;
|
|
184
211
|
|
|
185
|
-
interface ApiResponse<S extends z.ZodTypeAny> {
|
|
186
|
-
schema: S;
|
|
187
|
-
/**
|
|
188
|
-
* @default 200 for a positive response
|
|
189
|
-
* @default 400 for a negative response
|
|
190
|
-
* */
|
|
191
|
-
statusCode?: number;
|
|
192
|
-
/**
|
|
193
|
-
* @default "application/json"
|
|
194
|
-
* @override mimeTypes
|
|
195
|
-
* */
|
|
196
|
-
mimeType?: string;
|
|
197
|
-
/** @default [ "application/json" ] */
|
|
198
|
-
mimeTypes?: [string, ...string[]];
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
declare const zodDateInKind = "ZodDateIn";
|
|
202
|
-
interface ZodDateInDef extends ZodTypeDef {
|
|
203
|
-
typeName: typeof zodDateInKind;
|
|
204
|
-
}
|
|
205
|
-
declare class ZodDateIn extends ZodType<Date, ZodDateInDef, string> {
|
|
206
|
-
_parse(input: ParseInput): ParseReturnType<Date>;
|
|
207
|
-
static create: () => ZodDateIn;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
declare const zodDateOutKind = "ZodDateOut";
|
|
211
|
-
interface ZodDateOutDef extends ZodTypeDef {
|
|
212
|
-
typeName: typeof zodDateOutKind;
|
|
213
|
-
}
|
|
214
|
-
declare class ZodDateOut extends ZodType<string, ZodDateOutDef, Date> {
|
|
215
|
-
_parse(input: ParseInput): ParseReturnType<string>;
|
|
216
|
-
static create: () => ZodDateOut;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
declare const zodFileKind = "ZodFile";
|
|
220
|
-
interface ZodFileDef<T extends string | Buffer = string | Buffer> extends ZodTypeDef {
|
|
221
|
-
typeName: typeof zodFileKind;
|
|
222
|
-
type: T;
|
|
223
|
-
encoding?: "binary" | "base64";
|
|
224
|
-
message?: string;
|
|
225
|
-
}
|
|
226
|
-
declare class ZodFile<T extends string | Buffer = string | Buffer> extends ZodType<T, ZodFileDef<T>, T> {
|
|
227
|
-
_parse(input: ParseInput): ParseReturnType<T>;
|
|
228
|
-
string: (message?: ErrMessage) => ZodFile<string>;
|
|
229
|
-
buffer: (message?: ErrMessage) => ZodFile<Buffer>;
|
|
230
|
-
binary: (message?: ErrMessage) => ZodFile<T>;
|
|
231
|
-
base64: (message?: ErrMessage) => ZodFile<T>;
|
|
232
|
-
get isBinary(): boolean;
|
|
233
|
-
get isBase64(): boolean;
|
|
234
|
-
get isString(): boolean;
|
|
235
|
-
get isBuffer(): boolean;
|
|
236
|
-
static create: () => ZodFile<string>;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
declare const zodUploadKind = "ZodUpload";
|
|
240
|
-
interface ZodUploadDef extends ZodTypeDef {
|
|
241
|
-
typeName: typeof zodUploadKind;
|
|
242
|
-
}
|
|
243
|
-
declare class ZodUpload extends ZodType<UploadedFile, ZodUploadDef> {
|
|
244
|
-
_parse(input: ParseInput): ParseReturnType<UploadedFile>;
|
|
245
|
-
static create: () => ZodUpload;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
interface OpenAPIContext extends FlatObject {
|
|
249
|
-
isResponse: boolean;
|
|
250
|
-
serializer: (schema: z.ZodTypeAny) => string;
|
|
251
|
-
getRef: (name: string) => ReferenceObject | undefined;
|
|
252
|
-
makeRef: (name: string, schema: SchemaObject | ReferenceObject) => ReferenceObject;
|
|
253
|
-
path: string;
|
|
254
|
-
method: Method;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
/** @desc An error related to the wrong Routing declaration */
|
|
258
|
-
declare class RoutingError extends Error {
|
|
259
|
-
name: string;
|
|
260
|
-
}
|
|
261
|
-
/**
|
|
262
|
-
* @desc An error related to the generating of the documentation
|
|
263
|
-
* */
|
|
264
|
-
declare class DocumentationError extends Error {
|
|
265
|
-
name: string;
|
|
266
|
-
constructor({ message, method, path, isResponse, }: {
|
|
267
|
-
message: string;
|
|
268
|
-
} & Pick<OpenAPIContext, "path" | "method" | "isResponse">);
|
|
269
|
-
}
|
|
270
|
-
/** @desc An error related to the input and output schemas declaration */
|
|
271
|
-
declare class IOSchemaError extends Error {
|
|
272
|
-
name: string;
|
|
273
|
-
}
|
|
274
|
-
/** @desc An error of validating the Endpoint handler's returns against the Endpoint output schema */
|
|
275
|
-
declare class OutputValidationError extends IOSchemaError {
|
|
276
|
-
name: string;
|
|
277
|
-
readonly originalError: ZodError;
|
|
278
|
-
constructor(originalError: ZodError);
|
|
279
|
-
}
|
|
280
|
-
/** @desc An error of validating the input sources against the Middleware or Endpoint input schema */
|
|
281
|
-
declare class InputValidationError extends IOSchemaError {
|
|
282
|
-
name: string;
|
|
283
|
-
readonly originalError: ZodError;
|
|
284
|
-
constructor(originalError: ZodError);
|
|
285
|
-
}
|
|
286
|
-
declare class MissingPeerError extends Error {
|
|
287
|
-
name: string;
|
|
288
|
-
constructor(module: string | string[]);
|
|
289
|
-
}
|
|
290
|
-
|
|
291
212
|
interface ResultHandlerParams<RES> {
|
|
292
213
|
/** null in case of failure to parse or to find the matching endpoint (error: not found) */
|
|
293
214
|
input: FlatObject | null;
|
|
@@ -304,8 +225,14 @@ interface ResultHandlerDefinition<POS extends z.ZodTypeAny, NEG extends z.ZodTyp
|
|
|
304
225
|
getNegativeResponse: () => NEG | ApiResponse<NEG>;
|
|
305
226
|
handler: ResultHandler<z.output<POS> | z.output<NEG>>;
|
|
306
227
|
}
|
|
307
|
-
|
|
308
|
-
|
|
228
|
+
interface StatusDependingDefinition<POS extends MultipleApiResponses, NEG extends MultipleApiResponses> {
|
|
229
|
+
getPositiveResponse: (output: IOSchema) => POS;
|
|
230
|
+
getNegativeResponse: () => NEG;
|
|
231
|
+
handler: ResultHandler<z.output<POS[number]["schema"]> | z.output<NEG[number]["schema"]>>;
|
|
232
|
+
}
|
|
233
|
+
type AnyResultHandlerDefinition = ResultHandlerDefinition<z.ZodTypeAny, z.ZodTypeAny> | StatusDependingDefinition<MultipleApiResponses, MultipleApiResponses>;
|
|
234
|
+
declare function createResultHandler<POS extends MultipleApiResponses, NEG extends MultipleApiResponses>(definition: StatusDependingDefinition<POS, NEG>): typeof definition;
|
|
235
|
+
declare function createResultHandler<POS extends z.ZodTypeAny, NEG extends z.ZodTypeAny>(definition: ResultHandlerDefinition<POS, NEG>): typeof definition;
|
|
309
236
|
declare const defaultResultHandler: ResultHandlerDefinition<z.ZodObject<{
|
|
310
237
|
status: z.ZodLiteral<"success">;
|
|
311
238
|
data: IOSchema;
|
|
@@ -451,21 +378,21 @@ declare abstract class AbstractEndpoint {
|
|
|
451
378
|
abstract getSchema(variant: IOVariant): IOSchema;
|
|
452
379
|
abstract getSchema(variant: ResponseVariant): z.ZodTypeAny;
|
|
453
380
|
abstract getMimeTypes(variant: MimeVariant): string[];
|
|
454
|
-
abstract
|
|
381
|
+
abstract getResponses(variant: ResponseVariant): NormalizedResponse[];
|
|
455
382
|
abstract getSecurity(): LogicalContainer<Security>;
|
|
456
383
|
abstract getScopes(): string[];
|
|
457
384
|
abstract getTags(): string[];
|
|
458
385
|
abstract _setSiblingMethods(methods: Method[]): void;
|
|
459
386
|
abstract getOperationId(method: Method): string | undefined;
|
|
460
387
|
}
|
|
461
|
-
declare class Endpoint<IN extends IOSchema, OUT extends IOSchema, OPT extends FlatObject,
|
|
388
|
+
declare class Endpoint<IN extends IOSchema, OUT extends IOSchema, OPT extends FlatObject, SCO extends string, TAG extends string> extends AbstractEndpoint {
|
|
462
389
|
#private;
|
|
463
390
|
constructor({ methods, inputSchema, outputSchema, handler, resultHandler, getOperationId, scopes, middlewares, tags, description: long, shortDescription: short, }: {
|
|
464
391
|
middlewares?: AnyMiddlewareDef[];
|
|
465
392
|
inputSchema: IN;
|
|
466
393
|
outputSchema: OUT;
|
|
467
394
|
handler: Handler<z.output<IN>, z.input<OUT>, OPT>;
|
|
468
|
-
resultHandler:
|
|
395
|
+
resultHandler: AnyResultHandlerDefinition;
|
|
469
396
|
description?: string;
|
|
470
397
|
shortDescription?: string;
|
|
471
398
|
getOperationId?: (method: Method) => string | undefined;
|
|
@@ -482,10 +409,9 @@ declare class Endpoint<IN extends IOSchema, OUT extends IOSchema, OPT extends Fl
|
|
|
482
409
|
getMethods(): Method[];
|
|
483
410
|
getSchema(variant: "input"): IN;
|
|
484
411
|
getSchema(variant: "output"): OUT;
|
|
485
|
-
getSchema(variant:
|
|
486
|
-
getSchema(variant: "negative"): NEG;
|
|
412
|
+
getSchema(variant: ResponseVariant): z.ZodTypeAny;
|
|
487
413
|
getMimeTypes(variant: MimeVariant): string[];
|
|
488
|
-
|
|
414
|
+
getResponses(variant: ResponseVariant): Required<Pick<ApiResponse<z.ZodTypeAny>, "schema" | "statusCodes" | "mimeTypes">>[];
|
|
489
415
|
getSecurity(): LogicalContainer<Security>;
|
|
490
416
|
getScopes(): SCO[];
|
|
491
417
|
getTags(): TAG[];
|
|
@@ -617,145 +543,29 @@ type BuildProps<IN extends IOSchema, OUT extends IOSchema, MIN extends IOSchema<
|
|
|
617
543
|
} | {
|
|
618
544
|
tag?: TAG;
|
|
619
545
|
});
|
|
620
|
-
declare class EndpointsFactory<
|
|
546
|
+
declare class EndpointsFactory<IN extends IOSchema<"strip"> | null = null, OUT extends FlatObject = {}, SCO extends string = string, TAG extends string = string> {
|
|
621
547
|
#private;
|
|
622
|
-
protected resultHandler:
|
|
548
|
+
protected resultHandler: AnyResultHandlerDefinition;
|
|
623
549
|
protected middlewares: AnyMiddlewareDef[];
|
|
624
550
|
/** @desc Consider using the "config" prop with the "tags" option to enforce constraints on tagging the endpoints */
|
|
625
|
-
constructor(resultHandler:
|
|
551
|
+
constructor(resultHandler: AnyResultHandlerDefinition);
|
|
626
552
|
constructor(params: {
|
|
627
|
-
resultHandler:
|
|
553
|
+
resultHandler: AnyResultHandlerDefinition;
|
|
628
554
|
config?: CommonConfig<TAG>;
|
|
629
555
|
});
|
|
630
|
-
addMiddleware<AIN extends IOSchema<"strip">, AOUT extends FlatObject, ASCO extends string>(subject: MiddlewareDefinition<AIN, OUT, AOUT, ASCO>): EndpointsFactory<
|
|
631
|
-
use: <R extends Request<express_serve_static_core.ParamsDictionary, any, any, qs.ParsedQs, Record<string, any>>, S extends Response<any, Record<string, any>>, AOUT extends FlatObject = {}>(middleware: ExpressMiddleware<R, S>, features?: ExpressMiddlewareFeatures<R, S, AOUT> | undefined) => EndpointsFactory<
|
|
632
|
-
addExpressMiddleware<R extends Request, S extends Response, AOUT extends FlatObject = {}>(middleware: ExpressMiddleware<R, S>, features?: ExpressMiddlewareFeatures<R, S, AOUT>): EndpointsFactory<
|
|
633
|
-
addOptions<AOUT extends FlatObject>(options: AOUT): EndpointsFactory<
|
|
634
|
-
build<BIN extends IOSchema, BOUT extends IOSchema>({ input, handler, output: outputSchema, description, shortDescription, operationId, ...rest }: BuildProps<BIN, BOUT, IN, OUT, SCO, TAG>): Endpoint<ProbableIntersection<IN, BIN>, BOUT, OUT,
|
|
556
|
+
addMiddleware<AIN extends IOSchema<"strip">, AOUT extends FlatObject, ASCO extends string>(subject: MiddlewareDefinition<AIN, OUT, AOUT, ASCO>): EndpointsFactory<ProbableIntersection<IN, AIN>, OUT & AOUT, SCO & ASCO, TAG>;
|
|
557
|
+
use: <R extends Request<express_serve_static_core.ParamsDictionary, any, any, qs.ParsedQs, Record<string, any>>, S extends Response<any, Record<string, any>>, AOUT extends FlatObject = {}>(middleware: ExpressMiddleware<R, S>, features?: ExpressMiddlewareFeatures<R, S, AOUT> | undefined) => EndpointsFactory<IN, OUT & AOUT, SCO, TAG>;
|
|
558
|
+
addExpressMiddleware<R extends Request, S extends Response, AOUT extends FlatObject = {}>(middleware: ExpressMiddleware<R, S>, features?: ExpressMiddlewareFeatures<R, S, AOUT>): EndpointsFactory<IN, OUT & AOUT, SCO, TAG>;
|
|
559
|
+
addOptions<AOUT extends FlatObject>(options: AOUT): EndpointsFactory<IN, OUT & AOUT, SCO, TAG>;
|
|
560
|
+
build<BIN extends IOSchema, BOUT extends IOSchema>({ input, handler, output: outputSchema, description, shortDescription, operationId, ...rest }: BuildProps<BIN, BOUT, IN, OUT, SCO, TAG>): Endpoint<ProbableIntersection<IN, BIN>, BOUT, OUT, SCO, TAG>;
|
|
635
561
|
}
|
|
636
|
-
declare const defaultEndpointsFactory: EndpointsFactory<
|
|
637
|
-
status: z.ZodLiteral<"success">;
|
|
638
|
-
data: IOSchema;
|
|
639
|
-
}, "strip", z.ZodTypeAny, {
|
|
640
|
-
status: "success";
|
|
641
|
-
data?: unknown;
|
|
642
|
-
}, {
|
|
643
|
-
status: "success";
|
|
644
|
-
data?: unknown;
|
|
645
|
-
}> & {
|
|
646
|
-
_def: z.ZodObjectDef<{
|
|
647
|
-
status: z.ZodLiteral<"success">;
|
|
648
|
-
data: IOSchema;
|
|
649
|
-
}, "strip", z.ZodTypeAny> & MetaDef<z.ZodObject<{
|
|
650
|
-
status: z.ZodLiteral<"success">;
|
|
651
|
-
data: IOSchema;
|
|
652
|
-
}, "strip", z.ZodTypeAny, {
|
|
653
|
-
status: "success";
|
|
654
|
-
data?: unknown;
|
|
655
|
-
}, {
|
|
656
|
-
status: "success";
|
|
657
|
-
data?: unknown;
|
|
658
|
-
}>>;
|
|
659
|
-
example: (example: {
|
|
660
|
-
status: "success";
|
|
661
|
-
data?: unknown;
|
|
662
|
-
}) => z.ZodObject<{
|
|
663
|
-
status: z.ZodLiteral<"success">;
|
|
664
|
-
data: IOSchema;
|
|
665
|
-
}, "strip", z.ZodTypeAny, {
|
|
666
|
-
status: "success";
|
|
667
|
-
data?: unknown;
|
|
668
|
-
}, {
|
|
669
|
-
status: "success";
|
|
670
|
-
data?: unknown;
|
|
671
|
-
}> & any;
|
|
672
|
-
}, z.ZodObject<{
|
|
673
|
-
status: z.ZodLiteral<"error">;
|
|
674
|
-
error: z.ZodObject<{
|
|
675
|
-
message: z.ZodString;
|
|
676
|
-
}, "strip", z.ZodTypeAny, {
|
|
677
|
-
message: string;
|
|
678
|
-
}, {
|
|
679
|
-
message: string;
|
|
680
|
-
}>;
|
|
681
|
-
}, "strip", z.ZodTypeAny, {
|
|
682
|
-
status: "error";
|
|
683
|
-
error: {
|
|
684
|
-
message: string;
|
|
685
|
-
};
|
|
686
|
-
}, {
|
|
687
|
-
status: "error";
|
|
688
|
-
error: {
|
|
689
|
-
message: string;
|
|
690
|
-
};
|
|
691
|
-
}> & {
|
|
692
|
-
_def: z.ZodObjectDef<{
|
|
693
|
-
status: z.ZodLiteral<"error">;
|
|
694
|
-
error: z.ZodObject<{
|
|
695
|
-
message: z.ZodString;
|
|
696
|
-
}, "strip", z.ZodTypeAny, {
|
|
697
|
-
message: string;
|
|
698
|
-
}, {
|
|
699
|
-
message: string;
|
|
700
|
-
}>;
|
|
701
|
-
}, "strip", z.ZodTypeAny> & MetaDef<z.ZodObject<{
|
|
702
|
-
status: z.ZodLiteral<"error">;
|
|
703
|
-
error: z.ZodObject<{
|
|
704
|
-
message: z.ZodString;
|
|
705
|
-
}, "strip", z.ZodTypeAny, {
|
|
706
|
-
message: string;
|
|
707
|
-
}, {
|
|
708
|
-
message: string;
|
|
709
|
-
}>;
|
|
710
|
-
}, "strip", z.ZodTypeAny, {
|
|
711
|
-
status: "error";
|
|
712
|
-
error: {
|
|
713
|
-
message: string;
|
|
714
|
-
};
|
|
715
|
-
}, {
|
|
716
|
-
status: "error";
|
|
717
|
-
error: {
|
|
718
|
-
message: string;
|
|
719
|
-
};
|
|
720
|
-
}>>;
|
|
721
|
-
example: (example: {
|
|
722
|
-
status: "error";
|
|
723
|
-
error: {
|
|
724
|
-
message: string;
|
|
725
|
-
};
|
|
726
|
-
}) => z.ZodObject<{
|
|
727
|
-
status: z.ZodLiteral<"error">;
|
|
728
|
-
error: z.ZodObject<{
|
|
729
|
-
message: z.ZodString;
|
|
730
|
-
}, "strip", z.ZodTypeAny, {
|
|
731
|
-
message: string;
|
|
732
|
-
}, {
|
|
733
|
-
message: string;
|
|
734
|
-
}>;
|
|
735
|
-
}, "strip", z.ZodTypeAny, {
|
|
736
|
-
status: "error";
|
|
737
|
-
error: {
|
|
738
|
-
message: string;
|
|
739
|
-
};
|
|
740
|
-
}, {
|
|
741
|
-
status: "error";
|
|
742
|
-
error: {
|
|
743
|
-
message: string;
|
|
744
|
-
};
|
|
745
|
-
}> & any;
|
|
746
|
-
}, null, {}, string, string>;
|
|
562
|
+
declare const defaultEndpointsFactory: EndpointsFactory<null, {}, string, string>;
|
|
747
563
|
/**
|
|
748
564
|
* @deprecated Resist the urge of using it: this factory is designed only to simplify the migration of legacy APIs.
|
|
749
565
|
* @desc Responding with array is a bad practice keeping your endpoints from evolving without breaking changes.
|
|
750
566
|
* @desc The result handler of this factory expects your endpoint to have the property 'items' in the output schema
|
|
751
567
|
*/
|
|
752
|
-
declare const arrayEndpointsFactory: EndpointsFactory<
|
|
753
|
-
_def: z.ZodArrayDef<z.ZodTypeAny> & MetaDef<z.ZodArray<z.ZodTypeAny, "many">>;
|
|
754
|
-
example: (example: any[]) => z.ZodArray<z.ZodTypeAny, "many"> & any;
|
|
755
|
-
}, z.ZodString & {
|
|
756
|
-
_def: z.ZodStringDef & MetaDef<z.ZodString>;
|
|
757
|
-
example: (example: string) => z.ZodString & any;
|
|
758
|
-
}, null, {}, string, string>;
|
|
568
|
+
declare const arrayEndpointsFactory: EndpointsFactory<null, {}, string, string>;
|
|
759
569
|
|
|
760
570
|
declare class DependsOnMethod {
|
|
761
571
|
readonly endpoints: Partial<Record<Method, AbstractEndpoint>>;
|
|
@@ -787,7 +597,9 @@ declare const createServer: (config: ServerConfig, routing: Routing) => Promise<
|
|
|
787
597
|
|
|
788
598
|
type Component = "positiveResponse" | "negativeResponse" | "requestParameter" | "requestBody";
|
|
789
599
|
/** @desc user defined function that creates a component description from its properties */
|
|
790
|
-
type Descriptor = (props: Record<"method" | "path" | "operationId", string>
|
|
600
|
+
type Descriptor = (props: Record<"method" | "path" | "operationId", string> & {
|
|
601
|
+
statusCode?: number;
|
|
602
|
+
}) => string;
|
|
791
603
|
interface DocumentationParams {
|
|
792
604
|
title: string;
|
|
793
605
|
version: string;
|
|
@@ -820,6 +632,96 @@ declare class Documentation extends OpenApiBuilder {
|
|
|
820
632
|
constructor({ routing, config, title, version, serverUrl, descriptions, hasSummaryFromDescription, composition, serializer, }: DocumentationParams);
|
|
821
633
|
}
|
|
822
634
|
|
|
635
|
+
declare const zodDateInKind = "ZodDateIn";
|
|
636
|
+
interface ZodDateInDef extends ZodTypeDef {
|
|
637
|
+
typeName: typeof zodDateInKind;
|
|
638
|
+
}
|
|
639
|
+
declare class ZodDateIn extends ZodType<Date, ZodDateInDef, string> {
|
|
640
|
+
_parse(input: ParseInput): ParseReturnType<Date>;
|
|
641
|
+
static create: () => ZodDateIn;
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
declare const zodDateOutKind = "ZodDateOut";
|
|
645
|
+
interface ZodDateOutDef extends ZodTypeDef {
|
|
646
|
+
typeName: typeof zodDateOutKind;
|
|
647
|
+
}
|
|
648
|
+
declare class ZodDateOut extends ZodType<string, ZodDateOutDef, Date> {
|
|
649
|
+
_parse(input: ParseInput): ParseReturnType<string>;
|
|
650
|
+
static create: () => ZodDateOut;
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
declare const zodFileKind = "ZodFile";
|
|
654
|
+
interface ZodFileDef<T extends string | Buffer = string | Buffer> extends ZodTypeDef {
|
|
655
|
+
typeName: typeof zodFileKind;
|
|
656
|
+
type: T;
|
|
657
|
+
encoding?: "binary" | "base64";
|
|
658
|
+
message?: string;
|
|
659
|
+
}
|
|
660
|
+
declare class ZodFile<T extends string | Buffer = string | Buffer> extends ZodType<T, ZodFileDef<T>, T> {
|
|
661
|
+
_parse(input: ParseInput): ParseReturnType<T>;
|
|
662
|
+
string: (message?: ErrMessage) => ZodFile<string>;
|
|
663
|
+
buffer: (message?: ErrMessage) => ZodFile<Buffer>;
|
|
664
|
+
binary: (message?: ErrMessage) => ZodFile<T>;
|
|
665
|
+
base64: (message?: ErrMessage) => ZodFile<T>;
|
|
666
|
+
get isBinary(): boolean;
|
|
667
|
+
get isBase64(): boolean;
|
|
668
|
+
get isString(): boolean;
|
|
669
|
+
get isBuffer(): boolean;
|
|
670
|
+
static create: () => ZodFile<string>;
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
declare const zodUploadKind = "ZodUpload";
|
|
674
|
+
interface ZodUploadDef extends ZodTypeDef {
|
|
675
|
+
typeName: typeof zodUploadKind;
|
|
676
|
+
}
|
|
677
|
+
declare class ZodUpload extends ZodType<UploadedFile, ZodUploadDef> {
|
|
678
|
+
_parse(input: ParseInput): ParseReturnType<UploadedFile>;
|
|
679
|
+
static create: () => ZodUpload;
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
interface OpenAPIContext extends FlatObject {
|
|
683
|
+
isResponse: boolean;
|
|
684
|
+
serializer: (schema: z.ZodTypeAny) => string;
|
|
685
|
+
getRef: (name: string) => ReferenceObject | undefined;
|
|
686
|
+
makeRef: (name: string, schema: SchemaObject | ReferenceObject) => ReferenceObject;
|
|
687
|
+
path: string;
|
|
688
|
+
method: Method;
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
/** @desc An error related to the wrong Routing declaration */
|
|
692
|
+
declare class RoutingError extends Error {
|
|
693
|
+
name: string;
|
|
694
|
+
}
|
|
695
|
+
/**
|
|
696
|
+
* @desc An error related to the generating of the documentation
|
|
697
|
+
* */
|
|
698
|
+
declare class DocumentationError extends Error {
|
|
699
|
+
name: string;
|
|
700
|
+
constructor({ message, method, path, isResponse, }: {
|
|
701
|
+
message: string;
|
|
702
|
+
} & Pick<OpenAPIContext, "path" | "method" | "isResponse">);
|
|
703
|
+
}
|
|
704
|
+
/** @desc An error related to the input and output schemas declaration */
|
|
705
|
+
declare class IOSchemaError extends Error {
|
|
706
|
+
name: string;
|
|
707
|
+
}
|
|
708
|
+
/** @desc An error of validating the Endpoint handler's returns against the Endpoint output schema */
|
|
709
|
+
declare class OutputValidationError extends IOSchemaError {
|
|
710
|
+
name: string;
|
|
711
|
+
readonly originalError: ZodError;
|
|
712
|
+
constructor(originalError: ZodError);
|
|
713
|
+
}
|
|
714
|
+
/** @desc An error of validating the input sources against the Middleware or Endpoint input schema */
|
|
715
|
+
declare class InputValidationError extends IOSchemaError {
|
|
716
|
+
name: string;
|
|
717
|
+
readonly originalError: ZodError;
|
|
718
|
+
constructor(originalError: ZodError);
|
|
719
|
+
}
|
|
720
|
+
declare class MissingPeerError extends Error {
|
|
721
|
+
name: string;
|
|
722
|
+
constructor(module: string | string[]);
|
|
723
|
+
}
|
|
724
|
+
|
|
823
725
|
/**
|
|
824
726
|
* @desc Using module augmentation approach you can set the Mock type of your actual testing framework.
|
|
825
727
|
* @example declare module "express-zod-api" { interface MockOverrides extends Mock {} }
|
|
@@ -993,4 +895,4 @@ declare namespace proprietarySchemas {
|
|
|
993
895
|
export { proprietarySchemas_dateIn as dateIn, proprietarySchemas_dateOut as dateOut, proprietarySchemas_file as file, proprietarySchemas_raw as raw, proprietarySchemas_upload as upload };
|
|
994
896
|
}
|
|
995
897
|
|
|
996
|
-
export { AbstractEndpoint, type AppConfig, type BasicSecurity, type BearerSecurity, type CommonConfig, type CookieSecurity, type CustomHeaderSecurity, DependsOnMethod, Documentation, DocumentationError, EndpointsFactory, type FlatObject, type IOSchema, type InputSecurity, InputValidationError, Integration, type LoggerOverrides, type Metadata, type Method, type MiddlewareDefinition, MissingPeerError, type MockOverrides, type OAuth2Security, type OpenIdSecurity, OutputValidationError, type ResultHandlerDefinition, type Routing, RoutingError, ServeStatic, type ServerConfig, type ZodDateInDef, type ZodDateOutDef, type ZodFileDef, type ZodUploadDef, arrayEndpointsFactory, arrayResultHandler, attachRouting, createConfig, createLogger, createMiddleware, createResultHandler, createServer, defaultEndpointsFactory, defaultResultHandler, proprietarySchemas as ez, getExamples, getMessageFromError, getStatusCodeFromError, testEndpoint, withMeta };
|
|
898
|
+
export { AbstractEndpoint, type ApiResponse, type AppConfig, type BasicSecurity, type BearerSecurity, type CommonConfig, type CookieSecurity, type CustomHeaderSecurity, DependsOnMethod, Documentation, DocumentationError, EndpointsFactory, type FlatObject, type IOSchema, type InputSecurity, InputValidationError, Integration, type LoggerOverrides, type Metadata, type Method, type MiddlewareDefinition, MissingPeerError, type MockOverrides, type NormalizedResponse, type OAuth2Security, type OpenIdSecurity, OutputValidationError, type ResultHandlerDefinition, type Routing, RoutingError, ServeStatic, type ServerConfig, type StatusDependingDefinition, type ZodDateInDef, type ZodDateOutDef, type ZodFileDef, type ZodUploadDef, arrayEndpointsFactory, arrayResultHandler, attachRouting, createConfig, createLogger, createMiddleware, createResultHandler, createServer, defaultEndpointsFactory, defaultResultHandler, proprietarySchemas as ez, getExamples, getMessageFromError, getStatusCodeFromError, testEndpoint, withMeta };
|