express-zod-api 9.2.1 → 10.0.0-beta2
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 +62 -0
- package/README.md +28 -20
- package/SECURITY.md +14 -13
- package/dist/esm/index.js +58 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +1 -0
- package/dist/index.d.ts +776 -21
- package/dist/index.js +55 -69
- package/dist/index.js.map +1 -1
- package/package.json +31 -25
- package/dist/api-response.d.ts +0 -16
- package/dist/api-response.js +0 -3
- package/dist/api-response.js.map +0 -1
- package/dist/client-helpers.d.ts +0 -23
- package/dist/client-helpers.js +0 -71
- package/dist/client-helpers.js.map +0 -1
- package/dist/client.d.ts +0 -15
- package/dist/client.js +0 -120
- package/dist/client.js.map +0 -1
- package/dist/common-helpers.d.ts +0 -46
- package/dist/common-helpers.js +0 -207
- package/dist/common-helpers.js.map +0 -1
- package/dist/config-type.d.ts +0 -59
- package/dist/config-type.js +0 -11
- package/dist/config-type.js.map +0 -1
- package/dist/date-in-schema.d.ts +0 -11
- package/dist/date-in-schema.js +0 -46
- package/dist/date-in-schema.js.map +0 -1
- package/dist/date-out-schema.d.ts +0 -10
- package/dist/date-out-schema.js +0 -31
- package/dist/date-out-schema.js.map +0 -1
- package/dist/depends-on-method.d.ts +0 -10
- package/dist/depends-on-method.js +0 -32
- package/dist/depends-on-method.js.map +0 -1
- package/dist/endpoint.d.ts +0 -98
- package/dist/endpoint.js +0 -261
- package/dist/endpoint.js.map +0 -1
- package/dist/endpoints-factory.d.ts +0 -161
- package/dist/endpoints-factory.js +0 -68
- package/dist/endpoints-factory.js.map +0 -1
- package/dist/errors.d.ts +0 -35
- package/dist/errors.js +0 -64
- package/dist/errors.js.map +0 -1
- package/dist/extend-zod.d.ts +0 -22
- package/dist/extend-zod.js +0 -33
- package/dist/extend-zod.js.map +0 -1
- package/dist/file-schema.d.ts +0 -23
- package/dist/file-schema.js +0 -55
- package/dist/file-schema.js.map +0 -1
- package/dist/io-schema.d.ts +0 -16
- package/dist/io-schema.js +0 -21
- package/dist/io-schema.js.map +0 -1
- package/dist/logger.d.ts +0 -3
- package/dist/logger.js +0 -54
- package/dist/logger.js.map +0 -1
- package/dist/logical-container.d.ts +0 -16
- package/dist/logical-container.js +0 -85
- package/dist/logical-container.js.map +0 -1
- package/dist/metadata.d.ts +0 -27
- package/dist/metadata.js +0 -58
- package/dist/metadata.js.map +0 -1
- package/dist/method.d.ts +0 -8
- package/dist/method.js +0 -5
- package/dist/method.js.map +0 -1
- package/dist/middleware.d.ts +0 -32
- package/dist/middleware.js +0 -16
- package/dist/middleware.js.map +0 -1
- package/dist/mime.d.ts +0 -2
- package/dist/mime.js +0 -10
- package/dist/mime.js.map +0 -1
- package/dist/mock.d.ts +0 -38
- package/dist/mock.js +0 -66
- package/dist/mock.js.map +0 -1
- package/dist/open-api-helpers.d.ts +0 -83
- package/dist/open-api-helpers.js +0 -621
- package/dist/open-api-helpers.js.map +0 -1
- package/dist/open-api.d.ts +0 -25
- package/dist/open-api.js +0 -98
- package/dist/open-api.js.map +0 -1
- package/dist/result-handler.d.ts +0 -151
- package/dist/result-handler.js +0 -71
- package/dist/result-handler.js.map +0 -1
- package/dist/routing-walker.d.ts +0 -12
- package/dist/routing-walker.js +0 -55
- package/dist/routing-walker.js.map +0 -1
- package/dist/routing.d.ts +0 -15
- package/dist/routing.js +0 -25
- package/dist/routing.js.map +0 -1
- package/dist/schema-walker.d.ts +0 -23
- package/dist/schema-walker.js +0 -26
- package/dist/schema-walker.js.map +0 -1
- package/dist/security.d.ts +0 -72
- package/dist/security.js +0 -3
- package/dist/security.js.map +0 -1
- package/dist/serve-static.d.ts +0 -9
- package/dist/serve-static.js +0 -17
- package/dist/serve-static.js.map +0 -1
- package/dist/server.d.ts +0 -20
- package/dist/server.js +0 -131
- package/dist/server.js.map +0 -1
- package/dist/startup-logo.d.ts +0 -1
- package/dist/startup-logo.js +0 -27
- package/dist/startup-logo.js.map +0 -1
- package/dist/upload-schema.d.ts +0 -11
- package/dist/upload-schema.js +0 -42
- package/dist/upload-schema.js.map +0 -1
- package/dist/zts-helpers.d.ts +0 -37
- package/dist/zts-helpers.js +0 -60
- package/dist/zts-helpers.js.map +0 -1
- package/dist/zts.d.ts +0 -31
- package/dist/zts.js +0 -147
- package/dist/zts.js.map +0 -1
- package/dist-esm/api-response.js +0 -2
- package/dist-esm/api-response.js.map +0 -1
- package/dist-esm/client-helpers.js +0 -48
- package/dist-esm/client-helpers.js.map +0 -1
- package/dist-esm/client.js +0 -113
- package/dist-esm/client.js.map +0 -1
- package/dist-esm/common-helpers.js +0 -188
- package/dist-esm/common-helpers.js.map +0 -1
- package/dist-esm/config-type.js +0 -7
- package/dist-esm/config-type.js.map +0 -1
- package/dist-esm/date-in-schema.js +0 -42
- package/dist-esm/date-in-schema.js.map +0 -1
- package/dist-esm/date-out-schema.js +0 -27
- package/dist-esm/date-out-schema.js.map +0 -1
- package/dist-esm/depends-on-method.js +0 -28
- package/dist-esm/depends-on-method.js.map +0 -1
- package/dist-esm/endpoint.js +0 -256
- package/dist-esm/endpoint.js.map +0 -1
- package/dist-esm/endpoints-factory.js +0 -64
- package/dist-esm/endpoints-factory.js.map +0 -1
- package/dist-esm/errors.js +0 -54
- package/dist-esm/errors.js.map +0 -1
- package/dist-esm/extend-zod.js +0 -16
- package/dist-esm/extend-zod.js.map +0 -1
- package/dist-esm/file-schema.js +0 -51
- package/dist-esm/file-schema.js.map +0 -1
- package/dist-esm/index.js +0 -19
- package/dist-esm/index.js.map +0 -1
- package/dist-esm/io-schema.js +0 -17
- package/dist-esm/io-schema.js.map +0 -1
- package/dist-esm/logger.js +0 -47
- package/dist-esm/logger.js.map +0 -1
- package/dist-esm/logical-container.js +0 -78
- package/dist-esm/logical-container.js.map +0 -1
- package/dist-esm/metadata.js +0 -51
- package/dist-esm/metadata.js.map +0 -1
- package/dist-esm/method.js +0 -2
- package/dist-esm/method.js.map +0 -1
- package/dist-esm/middleware.js +0 -12
- package/dist-esm/middleware.js.map +0 -1
- package/dist-esm/mime.js +0 -4
- package/dist-esm/mime.js.map +0 -1
- package/dist-esm/mock.js +0 -57
- package/dist-esm/mock.js.map +0 -1
- package/dist-esm/open-api-helpers.js +0 -575
- package/dist-esm/open-api-helpers.js.map +0 -1
- package/dist-esm/open-api.js +0 -94
- package/dist-esm/open-api.js.map +0 -1
- package/dist-esm/package.json +0 -1
- package/dist-esm/result-handler.js +0 -66
- package/dist-esm/result-handler.js.map +0 -1
- package/dist-esm/routing-walker.js +0 -51
- package/dist-esm/routing-walker.js.map +0 -1
- package/dist-esm/routing.js +0 -21
- package/dist-esm/routing.js.map +0 -1
- package/dist-esm/schema-walker.js +0 -22
- package/dist-esm/schema-walker.js.map +0 -1
- package/dist-esm/security.js +0 -2
- package/dist-esm/security.js.map +0 -1
- package/dist-esm/serve-static.js +0 -10
- package/dist-esm/serve-static.js.map +0 -1
- package/dist-esm/server.js +0 -98
- package/dist-esm/server.js.map +0 -1
- package/dist-esm/startup-logo.js +0 -23
- package/dist-esm/startup-logo.js.map +0 -1
- package/dist-esm/upload-schema.js +0 -38
- package/dist-esm/upload-schema.js.map +0 -1
- package/dist-esm/zts-helpers.js +0 -50
- package/dist-esm/zts-helpers.js.map +0 -1
- package/dist-esm/zts.js +0 -140
- package/dist-esm/zts.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,21 +1,776 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
import compression from 'compression';
|
|
2
|
+
import { NextHandleFunction } from 'connect';
|
|
3
|
+
import express, { Request, Response, Express } from 'express';
|
|
4
|
+
import fileUpload, { UploadedFile } from 'express-fileupload';
|
|
5
|
+
import https, { ServerOptions } from 'https';
|
|
6
|
+
import winston, { Logger } from 'winston';
|
|
7
|
+
import { z, ZodError, ZodType, ParseInput, ParseReturnType, ZodTypeDef } from 'zod';
|
|
8
|
+
import { HttpError } from 'http-errors';
|
|
9
|
+
export { default as createHttpError } from 'http-errors';
|
|
10
|
+
import * as qs from 'qs';
|
|
11
|
+
import * as express_serve_static_core from 'express-serve-static-core';
|
|
12
|
+
import * as http from 'http';
|
|
13
|
+
import { OpenApiBuilder, SecuritySchemeType, SecuritySchemeObject } from 'openapi3-ts';
|
|
14
|
+
import ts from 'typescript';
|
|
15
|
+
|
|
16
|
+
type LogicalOr<T> = {
|
|
17
|
+
or: T[];
|
|
18
|
+
};
|
|
19
|
+
type LogicalAnd<T> = {
|
|
20
|
+
and: T[];
|
|
21
|
+
};
|
|
22
|
+
type LogicalContainer<T> = LogicalOr<T | LogicalAnd<T>> | LogicalAnd<T | LogicalOr<T>> | T;
|
|
23
|
+
|
|
24
|
+
interface BasicSecurity {
|
|
25
|
+
type: "basic";
|
|
26
|
+
}
|
|
27
|
+
interface BearerSecurity {
|
|
28
|
+
type: "bearer";
|
|
29
|
+
format?: "JWT" | string;
|
|
30
|
+
}
|
|
31
|
+
interface InputSecurity<K extends string> {
|
|
32
|
+
type: "input";
|
|
33
|
+
name: K;
|
|
34
|
+
}
|
|
35
|
+
interface CustomHeaderSecurity {
|
|
36
|
+
type: "header";
|
|
37
|
+
name: string;
|
|
38
|
+
}
|
|
39
|
+
interface CookieSecurity {
|
|
40
|
+
type: "cookie";
|
|
41
|
+
name: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* @see https://swagger.io/docs/specification/authentication/openid-connect-discovery/
|
|
45
|
+
* @desc available scopes has to be provided via the specified URL
|
|
46
|
+
*/
|
|
47
|
+
interface OpenIdSecurity {
|
|
48
|
+
type: "openid";
|
|
49
|
+
url: string;
|
|
50
|
+
}
|
|
51
|
+
interface AuthUrl {
|
|
52
|
+
/**
|
|
53
|
+
* @desc The authorization URL to use for this flow. Can be relative to the API server URL.
|
|
54
|
+
* @see https://swagger.io/docs/specification/api-host-and-base-path/
|
|
55
|
+
*/
|
|
56
|
+
authorizationUrl: string;
|
|
57
|
+
}
|
|
58
|
+
interface TokenUrl {
|
|
59
|
+
/** @desc The token URL to use for this flow. Can be relative to the API server URL. */
|
|
60
|
+
tokenUrl: string;
|
|
61
|
+
}
|
|
62
|
+
interface RefreshUrl {
|
|
63
|
+
/** @desc The URL to be used for obtaining refresh tokens. Can be relative to the API server URL. */
|
|
64
|
+
refreshUrl?: string;
|
|
65
|
+
}
|
|
66
|
+
interface Scopes<K extends string> {
|
|
67
|
+
/** @desc The available scopes for the OAuth2 security and their short descriptions. Optional. */
|
|
68
|
+
scopes?: Record<K, string>;
|
|
69
|
+
}
|
|
70
|
+
type AuthCodeFlow<S extends string> = AuthUrl & TokenUrl & RefreshUrl & Scopes<S>;
|
|
71
|
+
type ImplicitFlow<S extends string> = AuthUrl & RefreshUrl & Scopes<S>;
|
|
72
|
+
type PasswordFlow<S extends string> = TokenUrl & RefreshUrl & Scopes<S>;
|
|
73
|
+
type ClientCredFlow<S extends string> = TokenUrl & RefreshUrl & Scopes<S>;
|
|
74
|
+
/**
|
|
75
|
+
* @see https://swagger.io/docs/specification/authentication/oauth2/
|
|
76
|
+
*/
|
|
77
|
+
interface OAuth2Security<S extends string> {
|
|
78
|
+
type: "oauth2";
|
|
79
|
+
flows?: {
|
|
80
|
+
/** @desc Authorization Code flow (previously called accessCode in OpenAPI 2.0) */
|
|
81
|
+
authorizationCode?: AuthCodeFlow<S>;
|
|
82
|
+
/** @desc Implicit flow */
|
|
83
|
+
implicit?: ImplicitFlow<S>;
|
|
84
|
+
/** @desc Resource Owner Password flow */
|
|
85
|
+
password?: PasswordFlow<S>;
|
|
86
|
+
/** @desc Client Credentials flow (previously called application in OpenAPI 2.0) */
|
|
87
|
+
clientCredentials?: ClientCredFlow<S>;
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* @desc K is an optional input field used by InputSecurity
|
|
92
|
+
* @desc S is an optional union of scopes used by OAuth2Security
|
|
93
|
+
* */
|
|
94
|
+
type Security<K extends string = string, S extends string = string> = BasicSecurity | BearerSecurity | InputSecurity<K> | CustomHeaderSecurity | CookieSecurity | OpenIdSecurity | OAuth2Security<S>;
|
|
95
|
+
|
|
96
|
+
interface MiddlewareParams<IN, OPT> {
|
|
97
|
+
input: IN;
|
|
98
|
+
options: OPT;
|
|
99
|
+
request: Request;
|
|
100
|
+
response: Response;
|
|
101
|
+
logger: Logger;
|
|
102
|
+
}
|
|
103
|
+
type Middleware<IN, OPT, OUT> = (params: MiddlewareParams<IN, OPT>) => Promise<OUT>;
|
|
104
|
+
interface MiddlewareCreationProps<IN extends IOSchema<"strip">, OPT, OUT extends FlatObject, SCO extends string> {
|
|
105
|
+
input: IN;
|
|
106
|
+
security?: LogicalContainer<Security<keyof z.input<IN> & string, SCO>>;
|
|
107
|
+
middleware: Middleware<z.output<IN>, OPT, OUT>;
|
|
108
|
+
}
|
|
109
|
+
interface MiddlewareDefinition<IN extends IOSchema<"strip">, OPT, OUT extends FlatObject, SCO extends string> extends MiddlewareCreationProps<IN, OPT, OUT, SCO> {
|
|
110
|
+
type: "proprietary" | "express";
|
|
111
|
+
}
|
|
112
|
+
type AnyMiddlewareDef = MiddlewareDefinition<any, any, any, any>;
|
|
113
|
+
declare const createMiddleware: <IN extends IOSchema<"strip">, OPT, OUT extends FlatObject, SCO extends string>(props: MiddlewareCreationProps<IN, OPT, OUT, SCO>) => MiddlewareDefinition<IN, OPT, OUT, SCO>;
|
|
114
|
+
type ExpressMiddleware<R extends Request, S extends Response> = (request: R, response: S, next: (error?: any) => void) => void | Promise<void>;
|
|
115
|
+
interface ExpressMiddlewareFeatures<R extends Request, S extends Response, OUT extends FlatObject> {
|
|
116
|
+
provider?: (request: R, response: S) => OUT | Promise<OUT>;
|
|
117
|
+
transformer?: (err: Error) => HttpError | Error;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
type UnknownKeysParam = "passthrough" | "strict" | "strip";
|
|
121
|
+
type Refined<T extends z.ZodTypeAny> = T extends z.ZodType<infer O> ? z.ZodEffects<T | Refined<T>, O, O> : never;
|
|
122
|
+
/**
|
|
123
|
+
* @desc The type allowed on the top level of Middlewares and Endpoints
|
|
124
|
+
* @param U — only "strip" is allowed for Middlewares due to intersection issue (Zod) #600
|
|
125
|
+
* */
|
|
126
|
+
type IOSchema<U extends UnknownKeysParam = any> = z.ZodObject<any, U> | z.ZodUnion<[IOSchema<U>, ...IOSchema<U>[]]> | z.ZodIntersection<IOSchema<U>, IOSchema<U>> | z.ZodDiscriminatedUnion<string, z.ZodObject<any, U>[]> | Refined<z.ZodObject<any, U>>;
|
|
127
|
+
type ProbableIntersection<A extends IOSchema<"strip"> | null, B extends IOSchema> = A extends null ? B : A extends IOSchema<"strip"> ? z.ZodIntersection<A, B> : never;
|
|
128
|
+
|
|
129
|
+
type Method = "get" | "post" | "put" | "delete" | "patch";
|
|
130
|
+
type MethodsDefinition<M extends Method> = {
|
|
131
|
+
methods: M[];
|
|
132
|
+
} | {
|
|
133
|
+
method: M;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
type FlatObject = Record<string, any>;
|
|
137
|
+
declare function getMessageFromError(error: Error): string;
|
|
138
|
+
declare function getStatusCodeFromError(error: Error): number;
|
|
139
|
+
type ErrMessage = Exclude<Parameters<typeof z.ZodString.prototype.email>[0], undefined>;
|
|
140
|
+
|
|
141
|
+
declare const metaProp = "expressZodApiMeta";
|
|
142
|
+
type MetaProp = typeof metaProp;
|
|
143
|
+
type MetaDef<T extends z.ZodTypeAny> = {
|
|
144
|
+
[K in MetaProp]: {
|
|
145
|
+
examples: z.input<T>[];
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
type ExampleSetter<T extends z.ZodTypeAny> = (example: z.input<T>) => WithMeta<T>;
|
|
149
|
+
/**
|
|
150
|
+
* @desc fixes the incompatibility of the ZodObject.keyof() method introduced in v3.17.9
|
|
151
|
+
* @todo remove it if/when it will be compatible
|
|
152
|
+
*/
|
|
153
|
+
type MetaFixForStrippedObject<T> = T extends z.ZodObject<any> ? T & {
|
|
154
|
+
keyof: z.ZodObject<any>["keyof"];
|
|
155
|
+
} : T;
|
|
156
|
+
type WithMeta<T extends z.ZodTypeAny> = MetaFixForStrippedObject<T> & {
|
|
157
|
+
_def: T["_def"] & MetaDef<T>;
|
|
158
|
+
example: ExampleSetter<T>;
|
|
159
|
+
};
|
|
160
|
+
declare const withMeta: <T extends z.ZodTypeAny>(schema: T) => WithMeta<T>;
|
|
161
|
+
|
|
162
|
+
interface ApiResponse<S extends z.ZodTypeAny> {
|
|
163
|
+
schema: S;
|
|
164
|
+
/**
|
|
165
|
+
* @default 200 for a positive response
|
|
166
|
+
* @default 400 for a negative response
|
|
167
|
+
* */
|
|
168
|
+
statusCode?: number;
|
|
169
|
+
/**
|
|
170
|
+
* @default "application/json"
|
|
171
|
+
* @override mimeTypes
|
|
172
|
+
* */
|
|
173
|
+
mimeType?: string;
|
|
174
|
+
/** @default [ "application/json" ] */
|
|
175
|
+
mimeTypes?: [string, ...string[]];
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** @desc An error related to the wrong Routing declaration */
|
|
179
|
+
declare class RoutingError extends Error {
|
|
180
|
+
name: string;
|
|
181
|
+
}
|
|
182
|
+
/** @desc An error related to the issues of using DependsOnMethod class */
|
|
183
|
+
declare class DependsOnMethodError extends RoutingError {
|
|
184
|
+
name: string;
|
|
185
|
+
}
|
|
186
|
+
/** @desc An error related to the generating of the documentation */
|
|
187
|
+
declare class OpenAPIError extends Error {
|
|
188
|
+
name: string;
|
|
189
|
+
}
|
|
190
|
+
/** @desc An error related to the input and output schemas declaration */
|
|
191
|
+
declare class IOSchemaError extends Error {
|
|
192
|
+
name: string;
|
|
193
|
+
}
|
|
194
|
+
/** @desc An error of validating the Endpoint handler's returns against the Endpoint output schema */
|
|
195
|
+
declare class OutputValidationError extends IOSchemaError {
|
|
196
|
+
name: string;
|
|
197
|
+
readonly originalError: ZodError;
|
|
198
|
+
constructor(originalError: ZodError);
|
|
199
|
+
}
|
|
200
|
+
/** @desc An error of validating the input sources against the Middleware or Endpoint input schema */
|
|
201
|
+
declare class InputValidationError extends IOSchemaError {
|
|
202
|
+
name: string;
|
|
203
|
+
readonly originalError: ZodError;
|
|
204
|
+
constructor(originalError: ZodError);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
interface ResultHandlerParams<RES> {
|
|
208
|
+
error: Error | null;
|
|
209
|
+
input: any;
|
|
210
|
+
output: any;
|
|
211
|
+
request: Request;
|
|
212
|
+
response: Response<RES>;
|
|
213
|
+
logger: Logger;
|
|
214
|
+
}
|
|
215
|
+
type ResultHandler<RES> = (params: ResultHandlerParams<RES>) => void | Promise<void>;
|
|
216
|
+
interface ResultHandlerDefinition<POS extends z.ZodTypeAny, NEG extends z.ZodTypeAny> {
|
|
217
|
+
getPositiveResponse: (output: IOSchema) => POS | ApiResponse<POS>;
|
|
218
|
+
getNegativeResponse: () => NEG | ApiResponse<NEG>;
|
|
219
|
+
handler: ResultHandler<z.output<POS> | z.output<NEG>>;
|
|
220
|
+
}
|
|
221
|
+
declare const createResultHandler: <POS extends z.ZodTypeAny, NEG extends z.ZodTypeAny>(definition: ResultHandlerDefinition<POS, NEG>) => ResultHandlerDefinition<POS, NEG>;
|
|
222
|
+
declare const defaultResultHandler: ResultHandlerDefinition<z.ZodObject<{
|
|
223
|
+
status: z.ZodLiteral<"success">;
|
|
224
|
+
data: IOSchema<any>;
|
|
225
|
+
}, "strip", z.ZodTypeAny, {
|
|
226
|
+
status: "success";
|
|
227
|
+
data?: unknown;
|
|
228
|
+
}, {
|
|
229
|
+
status: "success";
|
|
230
|
+
data?: unknown;
|
|
231
|
+
}> & {
|
|
232
|
+
keyof: () => z.ZodEnum<never>;
|
|
233
|
+
} & {
|
|
234
|
+
_def: z.ZodObjectDef<{
|
|
235
|
+
status: z.ZodLiteral<"success">;
|
|
236
|
+
data: IOSchema<any>;
|
|
237
|
+
}, "strip", z.ZodTypeAny> & MetaDef<z.ZodObject<{
|
|
238
|
+
status: z.ZodLiteral<"success">;
|
|
239
|
+
data: IOSchema<any>;
|
|
240
|
+
}, "strip", z.ZodTypeAny, {
|
|
241
|
+
status: "success";
|
|
242
|
+
data?: unknown;
|
|
243
|
+
}, {
|
|
244
|
+
status: "success";
|
|
245
|
+
data?: unknown;
|
|
246
|
+
}>>;
|
|
247
|
+
example: (example: {
|
|
248
|
+
status: "success";
|
|
249
|
+
data?: unknown;
|
|
250
|
+
}) => z.ZodObject<{
|
|
251
|
+
status: z.ZodLiteral<"success">;
|
|
252
|
+
data: IOSchema<any>;
|
|
253
|
+
}, "strip", z.ZodTypeAny, {
|
|
254
|
+
status: "success";
|
|
255
|
+
data?: unknown;
|
|
256
|
+
}, {
|
|
257
|
+
status: "success";
|
|
258
|
+
data?: unknown;
|
|
259
|
+
}> & {
|
|
260
|
+
keyof: () => z.ZodEnum<never>;
|
|
261
|
+
} & any;
|
|
262
|
+
}, z.ZodObject<{
|
|
263
|
+
status: z.ZodLiteral<"error">;
|
|
264
|
+
error: z.ZodObject<{
|
|
265
|
+
message: z.ZodString;
|
|
266
|
+
}, "strip", z.ZodTypeAny, {
|
|
267
|
+
message: string;
|
|
268
|
+
}, {
|
|
269
|
+
message: string;
|
|
270
|
+
}>;
|
|
271
|
+
}, "strip", z.ZodTypeAny, {
|
|
272
|
+
status: "error";
|
|
273
|
+
error: {
|
|
274
|
+
message: string;
|
|
275
|
+
};
|
|
276
|
+
}, {
|
|
277
|
+
status: "error";
|
|
278
|
+
error: {
|
|
279
|
+
message: string;
|
|
280
|
+
};
|
|
281
|
+
}> & {
|
|
282
|
+
keyof: () => z.ZodEnum<never>;
|
|
283
|
+
} & {
|
|
284
|
+
_def: z.ZodObjectDef<{
|
|
285
|
+
status: z.ZodLiteral<"error">;
|
|
286
|
+
error: z.ZodObject<{
|
|
287
|
+
message: z.ZodString;
|
|
288
|
+
}, "strip", z.ZodTypeAny, {
|
|
289
|
+
message: string;
|
|
290
|
+
}, {
|
|
291
|
+
message: string;
|
|
292
|
+
}>;
|
|
293
|
+
}, "strip", z.ZodTypeAny> & MetaDef<z.ZodObject<{
|
|
294
|
+
status: z.ZodLiteral<"error">;
|
|
295
|
+
error: z.ZodObject<{
|
|
296
|
+
message: z.ZodString;
|
|
297
|
+
}, "strip", z.ZodTypeAny, {
|
|
298
|
+
message: string;
|
|
299
|
+
}, {
|
|
300
|
+
message: string;
|
|
301
|
+
}>;
|
|
302
|
+
}, "strip", z.ZodTypeAny, {
|
|
303
|
+
status: "error";
|
|
304
|
+
error: {
|
|
305
|
+
message: string;
|
|
306
|
+
};
|
|
307
|
+
}, {
|
|
308
|
+
status: "error";
|
|
309
|
+
error: {
|
|
310
|
+
message: string;
|
|
311
|
+
};
|
|
312
|
+
}>>;
|
|
313
|
+
example: (example: {
|
|
314
|
+
status: "error";
|
|
315
|
+
error: {
|
|
316
|
+
message: string;
|
|
317
|
+
};
|
|
318
|
+
}) => z.ZodObject<{
|
|
319
|
+
status: z.ZodLiteral<"error">;
|
|
320
|
+
error: z.ZodObject<{
|
|
321
|
+
message: z.ZodString;
|
|
322
|
+
}, "strip", z.ZodTypeAny, {
|
|
323
|
+
message: string;
|
|
324
|
+
}, {
|
|
325
|
+
message: string;
|
|
326
|
+
}>;
|
|
327
|
+
}, "strip", z.ZodTypeAny, {
|
|
328
|
+
status: "error";
|
|
329
|
+
error: {
|
|
330
|
+
message: string;
|
|
331
|
+
};
|
|
332
|
+
}, {
|
|
333
|
+
status: "error";
|
|
334
|
+
error: {
|
|
335
|
+
message: string;
|
|
336
|
+
};
|
|
337
|
+
}> & {
|
|
338
|
+
keyof: () => z.ZodEnum<never>;
|
|
339
|
+
} & any;
|
|
340
|
+
}>;
|
|
341
|
+
|
|
342
|
+
type Handler<IN, OUT, OPT> = (params: {
|
|
343
|
+
input: IN;
|
|
344
|
+
options: OPT;
|
|
345
|
+
logger: Logger;
|
|
346
|
+
}) => Promise<OUT>;
|
|
347
|
+
type DescriptionVariant = "short" | "long";
|
|
348
|
+
type IOVariant = "input" | "output";
|
|
349
|
+
type ResponseVariant = "positive" | "negative";
|
|
350
|
+
type MimeVariant = Extract<IOVariant, "input"> | ResponseVariant;
|
|
351
|
+
declare abstract class AbstractEndpoint {
|
|
352
|
+
abstract execute(params: {
|
|
353
|
+
request: Request;
|
|
354
|
+
response: Response;
|
|
355
|
+
logger: Logger;
|
|
356
|
+
config: CommonConfig;
|
|
357
|
+
}): Promise<void>;
|
|
358
|
+
abstract getDescription(variant: DescriptionVariant): string | undefined;
|
|
359
|
+
abstract getMethods(): Method[];
|
|
360
|
+
abstract getSchema(variant: IOVariant): IOSchema;
|
|
361
|
+
abstract getSchema(variant: ResponseVariant): z.ZodTypeAny;
|
|
362
|
+
abstract getMimeTypes(variant: MimeVariant): string[];
|
|
363
|
+
abstract getStatusCode(variant: ResponseVariant): number;
|
|
364
|
+
abstract getSecurity(): LogicalContainer<Security>;
|
|
365
|
+
abstract getScopes(): string[];
|
|
366
|
+
abstract getTags(): string[];
|
|
367
|
+
abstract _setSiblingMethods(methods: Method[]): void;
|
|
368
|
+
}
|
|
369
|
+
type EndpointProps<IN extends IOSchema, OUT extends IOSchema, OPT extends FlatObject, M extends Method, POS extends z.ZodTypeAny, NEG extends z.ZodTypeAny, SCO extends string, TAG extends string> = {
|
|
370
|
+
middlewares: AnyMiddlewareDef[];
|
|
371
|
+
inputSchema: IN;
|
|
372
|
+
outputSchema: OUT;
|
|
373
|
+
handler: Handler<z.output<IN>, z.input<OUT>, OPT>;
|
|
374
|
+
resultHandler: ResultHandlerDefinition<POS, NEG>;
|
|
375
|
+
description?: string;
|
|
376
|
+
shortDescription?: string;
|
|
377
|
+
} & ({
|
|
378
|
+
scopes?: SCO[];
|
|
379
|
+
} | {
|
|
380
|
+
scope?: SCO;
|
|
381
|
+
}) & ({
|
|
382
|
+
tags?: TAG[];
|
|
383
|
+
} | {
|
|
384
|
+
tag?: TAG;
|
|
385
|
+
}) & MethodsDefinition<M>;
|
|
386
|
+
declare class Endpoint<IN extends IOSchema, OUT extends IOSchema, OPT extends FlatObject, M extends Method, POS extends z.ZodTypeAny, NEG extends z.ZodTypeAny, SCO extends string, TAG extends string> extends AbstractEndpoint {
|
|
387
|
+
#private;
|
|
388
|
+
protected readonly descriptions: Record<DescriptionVariant, string | undefined>;
|
|
389
|
+
protected readonly methods: M[];
|
|
390
|
+
protected siblingMethods: Method[];
|
|
391
|
+
protected readonly middlewares: AnyMiddlewareDef[];
|
|
392
|
+
protected readonly mimeTypes: Record<MimeVariant, string[]>;
|
|
393
|
+
protected readonly statusCodes: Record<ResponseVariant, number>;
|
|
394
|
+
protected readonly handler: Handler<z.output<IN>, z.input<OUT>, OPT>;
|
|
395
|
+
protected readonly resultHandler: ResultHandlerDefinition<POS, NEG>;
|
|
396
|
+
protected readonly schemas: {
|
|
397
|
+
input: IN;
|
|
398
|
+
output: OUT;
|
|
399
|
+
positive: POS;
|
|
400
|
+
negative: NEG;
|
|
401
|
+
};
|
|
402
|
+
protected readonly scopes: SCO[];
|
|
403
|
+
protected readonly tags: TAG[];
|
|
404
|
+
constructor({ middlewares, inputSchema, outputSchema, handler, resultHandler, description, shortDescription, ...rest }: EndpointProps<IN, OUT, OPT, M, POS, NEG, SCO, TAG>);
|
|
405
|
+
/**
|
|
406
|
+
* @desc Sets the other methods supported by the same path. Used by Routing in DependsOnMethod case, for options.
|
|
407
|
+
* @deprecated This method is for internal needs of the library, please avoid using it.
|
|
408
|
+
* */
|
|
409
|
+
_setSiblingMethods(methods: Method[]): void;
|
|
410
|
+
getDescription(variant: DescriptionVariant): string | undefined;
|
|
411
|
+
getMethods(): M[];
|
|
412
|
+
getSchema(variant: "input"): IN;
|
|
413
|
+
getSchema(variant: "output"): OUT;
|
|
414
|
+
getSchema(variant: "positive"): POS;
|
|
415
|
+
getSchema(variant: "negative"): NEG;
|
|
416
|
+
getMimeTypes(variant: MimeVariant): string[];
|
|
417
|
+
getStatusCode(variant: ResponseVariant): number;
|
|
418
|
+
getSecurity(): LogicalContainer<Security<string, string>>;
|
|
419
|
+
getScopes(): SCO[];
|
|
420
|
+
getTags(): TAG[];
|
|
421
|
+
execute({ request, response, logger, config, }: {
|
|
422
|
+
request: Request;
|
|
423
|
+
response: Response;
|
|
424
|
+
logger: Logger;
|
|
425
|
+
config: CommonConfig;
|
|
426
|
+
}): Promise<void>;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
declare const loggerLevels: {
|
|
430
|
+
silent: boolean;
|
|
431
|
+
warn: boolean;
|
|
432
|
+
debug: boolean;
|
|
433
|
+
};
|
|
434
|
+
interface LoggerConfig {
|
|
435
|
+
level: keyof typeof loggerLevels;
|
|
436
|
+
color: boolean;
|
|
437
|
+
}
|
|
438
|
+
type UploadOptions = Pick<fileUpload.Options, "createParentPath" | "uriDecodeFileNames" | "safeFileNames" | "preserveExtension" | "useTempFiles" | "tempFileDir" | "debug" | "uploadTimeout">;
|
|
439
|
+
type CompressionOptions = Pick<compression.CompressionOptions, "threshold" | "level" | "strategy" | "chunkSize" | "memLevel">;
|
|
440
|
+
interface ServerConfig {
|
|
441
|
+
server: {
|
|
442
|
+
listen: number | string;
|
|
443
|
+
jsonParser?: NextHandleFunction;
|
|
444
|
+
upload?: boolean | UploadOptions;
|
|
445
|
+
compression?: boolean | CompressionOptions;
|
|
446
|
+
};
|
|
447
|
+
https?: {
|
|
448
|
+
options: ServerOptions;
|
|
449
|
+
listen: number | string;
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
interface AppConfig {
|
|
453
|
+
app: Express;
|
|
454
|
+
}
|
|
455
|
+
type InputSource = keyof Pick<Request, "query" | "body" | "files" | "params">;
|
|
456
|
+
type InputSources = Record<Method, InputSource[]>;
|
|
457
|
+
type Headers = Record<string, string>;
|
|
458
|
+
type HeadersProvider = (params: {
|
|
459
|
+
defaultHeaders: Headers;
|
|
460
|
+
request: Request;
|
|
461
|
+
endpoint: AbstractEndpoint;
|
|
462
|
+
logger: Logger;
|
|
463
|
+
}) => Headers | Promise<Headers>;
|
|
464
|
+
type TagsConfig<TAG extends string> = Record<TAG, string | {
|
|
465
|
+
description: string;
|
|
466
|
+
url?: string;
|
|
467
|
+
}>;
|
|
468
|
+
interface CommonConfig<TAG extends string = string> {
|
|
469
|
+
cors: boolean | HeadersProvider;
|
|
470
|
+
errorHandler?: ResultHandlerDefinition<any, any>;
|
|
471
|
+
logger: LoggerConfig | Logger;
|
|
472
|
+
startupLogo?: boolean;
|
|
473
|
+
inputSources?: Partial<InputSources>;
|
|
474
|
+
tags?: TagsConfig<TAG>;
|
|
475
|
+
}
|
|
476
|
+
declare const createConfig: <TAG extends string, T extends (ServerConfig | AppConfig) & CommonConfig<TAG>>(config: T) => T;
|
|
477
|
+
|
|
478
|
+
type BuildProps<IN extends IOSchema, OUT extends IOSchema, MIN extends IOSchema<"strip"> | null, OPT extends FlatObject, M extends Method, SCO extends string, TAG extends string> = {
|
|
479
|
+
input: IN;
|
|
480
|
+
output: OUT;
|
|
481
|
+
handler: Handler<z.output<ProbableIntersection<MIN, IN>>, z.input<OUT>, OPT>;
|
|
482
|
+
description?: string;
|
|
483
|
+
shortDescription?: string;
|
|
484
|
+
} & ({
|
|
485
|
+
scopes?: SCO[];
|
|
486
|
+
} | {
|
|
487
|
+
scope?: SCO;
|
|
488
|
+
}) & ({
|
|
489
|
+
tags?: TAG[];
|
|
490
|
+
} | {
|
|
491
|
+
tag?: TAG;
|
|
492
|
+
}) & MethodsDefinition<M>;
|
|
493
|
+
declare class EndpointsFactory<POS extends z.ZodTypeAny, NEG extends z.ZodTypeAny, IN extends IOSchema<"strip"> | null = null, OUT extends FlatObject = {}, SCO extends string = string, TAG extends string = string> {
|
|
494
|
+
#private;
|
|
495
|
+
protected resultHandler: ResultHandlerDefinition<POS, NEG>;
|
|
496
|
+
protected middlewares: AnyMiddlewareDef[];
|
|
497
|
+
constructor(resultHandler: ResultHandlerDefinition<POS, NEG>);
|
|
498
|
+
/** @desc Consider using the "config" prop with the "tags" option to enforce constraints on tagging the endpoints */
|
|
499
|
+
constructor(params: {
|
|
500
|
+
resultHandler: ResultHandlerDefinition<POS, NEG>;
|
|
501
|
+
config?: CommonConfig<TAG>;
|
|
502
|
+
});
|
|
503
|
+
addMiddleware<AIN extends IOSchema<"strip">, AOUT extends FlatObject, ASCO extends string>(subject: MiddlewareDefinition<AIN, OUT, AOUT, ASCO>): EndpointsFactory<POS, NEG, ProbableIntersection<IN, AIN>, OUT & AOUT, SCO & ASCO, TAG>;
|
|
504
|
+
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<POS, NEG, IN, OUT & AOUT, SCO, TAG>;
|
|
505
|
+
addExpressMiddleware<R extends Request, S extends Response, AOUT extends FlatObject = {}>(middleware: ExpressMiddleware<R, S>, features?: ExpressMiddlewareFeatures<R, S, AOUT>): EndpointsFactory<POS, NEG, IN, OUT & AOUT, SCO, TAG>;
|
|
506
|
+
addOptions<AOUT extends FlatObject>(options: AOUT): EndpointsFactory<POS, NEG, IN, OUT & AOUT, SCO, TAG>;
|
|
507
|
+
build<BIN extends IOSchema, BOUT extends IOSchema, M extends Method>({ input, handler, output: outputSchema, ...rest }: BuildProps<BIN, BOUT, IN, OUT, M, SCO, TAG>): Endpoint<ProbableIntersection<IN, BIN>, BOUT, OUT, M, POS, NEG, SCO, TAG>;
|
|
508
|
+
}
|
|
509
|
+
declare const defaultEndpointsFactory: EndpointsFactory<z.ZodObject<{
|
|
510
|
+
status: z.ZodLiteral<"success">;
|
|
511
|
+
data: IOSchema<any>;
|
|
512
|
+
}, "strip", z.ZodTypeAny, {
|
|
513
|
+
status: "success";
|
|
514
|
+
data?: unknown;
|
|
515
|
+
}, {
|
|
516
|
+
status: "success";
|
|
517
|
+
data?: unknown;
|
|
518
|
+
}> & {
|
|
519
|
+
keyof: () => z.ZodEnum<never>;
|
|
520
|
+
} & {
|
|
521
|
+
_def: z.ZodObjectDef<{
|
|
522
|
+
status: z.ZodLiteral<"success">;
|
|
523
|
+
data: IOSchema<any>;
|
|
524
|
+
}, "strip", z.ZodTypeAny> & MetaDef<z.ZodObject<{
|
|
525
|
+
status: z.ZodLiteral<"success">;
|
|
526
|
+
data: IOSchema<any>;
|
|
527
|
+
}, "strip", z.ZodTypeAny, {
|
|
528
|
+
status: "success";
|
|
529
|
+
data?: unknown;
|
|
530
|
+
}, {
|
|
531
|
+
status: "success";
|
|
532
|
+
data?: unknown;
|
|
533
|
+
}>>;
|
|
534
|
+
example: (example: {
|
|
535
|
+
status: "success";
|
|
536
|
+
data?: unknown;
|
|
537
|
+
}) => z.ZodObject<{
|
|
538
|
+
status: z.ZodLiteral<"success">;
|
|
539
|
+
data: IOSchema<any>;
|
|
540
|
+
}, "strip", z.ZodTypeAny, {
|
|
541
|
+
status: "success";
|
|
542
|
+
data?: unknown;
|
|
543
|
+
}, {
|
|
544
|
+
status: "success";
|
|
545
|
+
data?: unknown;
|
|
546
|
+
}> & {
|
|
547
|
+
keyof: () => z.ZodEnum<never>;
|
|
548
|
+
} & any;
|
|
549
|
+
}, z.ZodObject<{
|
|
550
|
+
status: z.ZodLiteral<"error">;
|
|
551
|
+
error: z.ZodObject<{
|
|
552
|
+
message: z.ZodString;
|
|
553
|
+
}, "strip", z.ZodTypeAny, {
|
|
554
|
+
message: string;
|
|
555
|
+
}, {
|
|
556
|
+
message: string;
|
|
557
|
+
}>;
|
|
558
|
+
}, "strip", z.ZodTypeAny, {
|
|
559
|
+
status: "error";
|
|
560
|
+
error: {
|
|
561
|
+
message: string;
|
|
562
|
+
};
|
|
563
|
+
}, {
|
|
564
|
+
status: "error";
|
|
565
|
+
error: {
|
|
566
|
+
message: string;
|
|
567
|
+
};
|
|
568
|
+
}> & {
|
|
569
|
+
keyof: () => z.ZodEnum<never>;
|
|
570
|
+
} & {
|
|
571
|
+
_def: z.ZodObjectDef<{
|
|
572
|
+
status: z.ZodLiteral<"error">;
|
|
573
|
+
error: z.ZodObject<{
|
|
574
|
+
message: z.ZodString;
|
|
575
|
+
}, "strip", z.ZodTypeAny, {
|
|
576
|
+
message: string;
|
|
577
|
+
}, {
|
|
578
|
+
message: string;
|
|
579
|
+
}>;
|
|
580
|
+
}, "strip", z.ZodTypeAny> & MetaDef<z.ZodObject<{
|
|
581
|
+
status: z.ZodLiteral<"error">;
|
|
582
|
+
error: z.ZodObject<{
|
|
583
|
+
message: z.ZodString;
|
|
584
|
+
}, "strip", z.ZodTypeAny, {
|
|
585
|
+
message: string;
|
|
586
|
+
}, {
|
|
587
|
+
message: string;
|
|
588
|
+
}>;
|
|
589
|
+
}, "strip", z.ZodTypeAny, {
|
|
590
|
+
status: "error";
|
|
591
|
+
error: {
|
|
592
|
+
message: string;
|
|
593
|
+
};
|
|
594
|
+
}, {
|
|
595
|
+
status: "error";
|
|
596
|
+
error: {
|
|
597
|
+
message: string;
|
|
598
|
+
};
|
|
599
|
+
}>>;
|
|
600
|
+
example: (example: {
|
|
601
|
+
status: "error";
|
|
602
|
+
error: {
|
|
603
|
+
message: string;
|
|
604
|
+
};
|
|
605
|
+
}) => z.ZodObject<{
|
|
606
|
+
status: z.ZodLiteral<"error">;
|
|
607
|
+
error: z.ZodObject<{
|
|
608
|
+
message: z.ZodString;
|
|
609
|
+
}, "strip", z.ZodTypeAny, {
|
|
610
|
+
message: string;
|
|
611
|
+
}, {
|
|
612
|
+
message: string;
|
|
613
|
+
}>;
|
|
614
|
+
}, "strip", z.ZodTypeAny, {
|
|
615
|
+
status: "error";
|
|
616
|
+
error: {
|
|
617
|
+
message: string;
|
|
618
|
+
};
|
|
619
|
+
}, {
|
|
620
|
+
status: "error";
|
|
621
|
+
error: {
|
|
622
|
+
message: string;
|
|
623
|
+
};
|
|
624
|
+
}> & {
|
|
625
|
+
keyof: () => z.ZodEnum<never>;
|
|
626
|
+
} & any;
|
|
627
|
+
}, null, {}, string, string>;
|
|
628
|
+
|
|
629
|
+
declare function createLogger(loggerConfig: LoggerConfig): winston.Logger;
|
|
630
|
+
|
|
631
|
+
declare class DependsOnMethod {
|
|
632
|
+
readonly methods: {
|
|
633
|
+
[K in Method]?: Endpoint<any, any, any, K, any, any, any, any> | Endpoint<any, any, any, Method, any, any, any, any>;
|
|
634
|
+
};
|
|
635
|
+
constructor(methods: {
|
|
636
|
+
[K in Method]?: Endpoint<any, any, any, K, any, any, any, any> | Endpoint<any, any, any, Method, any, any, any, any>;
|
|
637
|
+
});
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
type OriginalStatic = typeof express.static;
|
|
641
|
+
type StaticHandler = ReturnType<OriginalStatic>;
|
|
642
|
+
declare class ServeStatic {
|
|
643
|
+
params: Parameters<OriginalStatic>;
|
|
644
|
+
constructor(...params: Parameters<OriginalStatic>);
|
|
645
|
+
apply(path: string, cb: (path: string, handler: StaticHandler) => void): void;
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
interface Routing {
|
|
649
|
+
[SEGMENT: string]: Routing | DependsOnMethod | AbstractEndpoint | ServeStatic;
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
declare function attachRouting(config: AppConfig & CommonConfig, routing: Routing): {
|
|
653
|
+
notFoundHandler: express.RequestHandler<express_serve_static_core.ParamsDictionary, any, any, qs.ParsedQs, Record<string, any>>;
|
|
654
|
+
logger: Logger;
|
|
655
|
+
};
|
|
656
|
+
declare function createServer(config: ServerConfig & CommonConfig, routing: Routing): {
|
|
657
|
+
app: express_serve_static_core.Express;
|
|
658
|
+
httpServer: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
|
|
659
|
+
httpsServer: https.Server<typeof http.IncomingMessage, typeof http.ServerResponse> | undefined;
|
|
660
|
+
logger: Logger;
|
|
661
|
+
};
|
|
662
|
+
|
|
663
|
+
interface GeneratorParams {
|
|
664
|
+
title: string;
|
|
665
|
+
version: string;
|
|
666
|
+
serverUrl: string;
|
|
667
|
+
routing: Routing;
|
|
668
|
+
config: CommonConfig;
|
|
669
|
+
/** @default Successful response */
|
|
670
|
+
successfulResponseDescription?: string;
|
|
671
|
+
/** @default Error response */
|
|
672
|
+
errorResponseDescription?: string;
|
|
673
|
+
/** @default true */
|
|
674
|
+
hasSummaryFromDescription?: boolean;
|
|
675
|
+
}
|
|
676
|
+
declare class OpenAPI extends OpenApiBuilder {
|
|
677
|
+
protected lastSecuritySchemaIds: Partial<Record<SecuritySchemeType, number>>;
|
|
678
|
+
protected lastOperationIdSuffixes: Record<string, number>;
|
|
679
|
+
protected ensureUniqOperationId(path: string, method: Method): string;
|
|
680
|
+
protected ensureUniqSecuritySchemaName(subject: SecuritySchemeObject): string;
|
|
681
|
+
constructor({ routing, config, title, version, serverUrl, successfulResponseDescription, errorResponseDescription, hasSummaryFromDescription, }: GeneratorParams);
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
interface TestEndpointProps<REQ, RES, LOG> {
|
|
685
|
+
endpoint: AbstractEndpoint;
|
|
686
|
+
requestProps?: REQ;
|
|
687
|
+
responseProps?: RES;
|
|
688
|
+
configProps?: Partial<CommonConfig>;
|
|
689
|
+
loggerProps?: LOG;
|
|
690
|
+
/** @deprecated for testing purposes only */
|
|
691
|
+
__noJest?: boolean;
|
|
692
|
+
}
|
|
693
|
+
/**
|
|
694
|
+
* @description You need to install Jest and probably @types/jest to use this method
|
|
695
|
+
*/
|
|
696
|
+
declare const testEndpoint: <REQ extends Partial<Record<keyof Request<express_serve_static_core.ParamsDictionary, any, any, qs.ParsedQs, Record<string, any>>, any>> | undefined = undefined, RES extends Partial<Record<keyof Response<any, Record<string, any>>, any>> | undefined = undefined, LOG extends Partial<Record<keyof Logger, any>> | undefined = undefined>({ endpoint, requestProps, responseProps, configProps, loggerProps, __noJest, }: TestEndpointProps<REQ, RES, LOG>) => Promise<{
|
|
697
|
+
requestMock: {
|
|
698
|
+
method: string;
|
|
699
|
+
} & Record<"header", jest.Mock<any, any, any>> & (REQ extends undefined ? {} : REQ);
|
|
700
|
+
responseMock: {
|
|
701
|
+
writableEnded: boolean;
|
|
702
|
+
statusCode: number;
|
|
703
|
+
statusMessage: string;
|
|
704
|
+
} & Record<"status" | "set" | "json" | "end", jest.Mock<any, any, any>> & (RES extends undefined ? {} : RES);
|
|
705
|
+
loggerMock: Record<"error" | "warn" | "debug" | "info", jest.Mock<any, any, any>> & (LOG extends undefined ? {} : LOG);
|
|
706
|
+
}>;
|
|
707
|
+
|
|
708
|
+
interface Registry {
|
|
709
|
+
[METHOD_PATH: string]: Record<"in" | "out", string> & {
|
|
710
|
+
isJson: boolean;
|
|
711
|
+
};
|
|
712
|
+
}
|
|
713
|
+
declare class Client {
|
|
714
|
+
protected agg: ts.Node[];
|
|
715
|
+
protected registry: Registry;
|
|
716
|
+
protected paths: string[];
|
|
717
|
+
constructor(routing: Routing);
|
|
718
|
+
print(printerOptions?: ts.PrinterOptions): string;
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
declare const zodDateInKind = "ZodDateIn";
|
|
722
|
+
interface ZodDateInDef extends ZodTypeDef {
|
|
723
|
+
typeName: typeof zodDateInKind;
|
|
724
|
+
}
|
|
725
|
+
declare class ZodDateIn extends ZodType<Date, ZodDateInDef, string> {
|
|
726
|
+
_parse(input: ParseInput): ParseReturnType<Date>;
|
|
727
|
+
static create: () => ZodDateIn;
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
declare const zodDateOutKind = "ZodDateOut";
|
|
731
|
+
interface ZodDateOutDef extends ZodTypeDef {
|
|
732
|
+
typeName: typeof zodDateOutKind;
|
|
733
|
+
}
|
|
734
|
+
declare class ZodDateOut extends ZodType<string, ZodDateOutDef, Date> {
|
|
735
|
+
_parse(input: ParseInput): ParseReturnType<string>;
|
|
736
|
+
static create: () => ZodDateOut;
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
declare const zodFileKind = "ZodFile";
|
|
740
|
+
declare type ZodFileCheck = {
|
|
741
|
+
kind: "binary";
|
|
742
|
+
message?: string;
|
|
743
|
+
} | {
|
|
744
|
+
kind: "base64";
|
|
745
|
+
message?: string;
|
|
746
|
+
};
|
|
747
|
+
interface ZodFileDef extends ZodTypeDef {
|
|
748
|
+
checks: ZodFileCheck[];
|
|
749
|
+
typeName: typeof zodFileKind;
|
|
750
|
+
}
|
|
751
|
+
declare class ZodFile extends ZodType<string, ZodFileDef> {
|
|
752
|
+
_parse(input: ParseInput): ParseReturnType<string>;
|
|
753
|
+
binary: (message?: ErrMessage) => ZodFile;
|
|
754
|
+
base64: (message?: ErrMessage) => ZodFile;
|
|
755
|
+
get isBinary(): boolean;
|
|
756
|
+
get isBase64(): boolean;
|
|
757
|
+
static create: () => ZodFile;
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
declare const zodUploadKind = "ZodUpload";
|
|
761
|
+
interface ZodUploadDef extends ZodTypeDef {
|
|
762
|
+
typeName: typeof zodUploadKind;
|
|
763
|
+
}
|
|
764
|
+
declare class ZodUpload extends ZodType<UploadedFile, ZodUploadDef> {
|
|
765
|
+
_parse(input: ParseInput): ParseReturnType<UploadedFile>;
|
|
766
|
+
static create: () => ZodUpload;
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
declare namespace ez {
|
|
770
|
+
const file: () => ZodFile;
|
|
771
|
+
const upload: () => ZodUpload;
|
|
772
|
+
const dateIn: () => ZodDateIn;
|
|
773
|
+
const dateOut: () => ZodDateOut;
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
export { AbstractEndpoint, Client, DependsOnMethod, DependsOnMethodError, EndpointsFactory, FlatObject, IOSchema, InputValidationError, LoggerConfig, Method, OpenAPI, OpenAPIError, OutputValidationError, Routing, RoutingError, ServeStatic, attachRouting, createConfig, createLogger, createMiddleware, createResultHandler, createServer, defaultEndpointsFactory, defaultResultHandler, ez, getMessageFromError, getStatusCodeFromError, testEndpoint, withMeta };
|