express-zod-api 25.2.0-beta.2 → 25.3.0-beta.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/CHANGELOG.md +4 -0
- package/dist/index.d.ts +752 -630
- package/dist/index.js +11 -13
- package/package.json +3 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,23 +1,25 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import
|
|
17
|
-
import {
|
|
18
|
-
import
|
|
19
|
-
import * as
|
|
1
|
+
import "@express-zod-api/zod-plugin";
|
|
2
|
+
import * as zod0 from "zod";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { HttpError } from "http-errors";
|
|
5
|
+
import "ansis";
|
|
6
|
+
import * as express0 from "express";
|
|
7
|
+
import express, { IRouter, NextFunction, Request, RequestHandler, Response } from "express";
|
|
8
|
+
import http from "node:http";
|
|
9
|
+
import https, { ServerOptions } from "node:https";
|
|
10
|
+
import { OpenApiBuilder, ReferenceObject, SchemaObject, TagObject } from "openapi3-ts/oas31";
|
|
11
|
+
import * as node_mocks_http0 from "node-mocks-http";
|
|
12
|
+
import { RequestOptions, ResponseOptions } from "node-mocks-http";
|
|
13
|
+
import ts from "typescript";
|
|
14
|
+
import compression from "compression";
|
|
15
|
+
import * as express_fileupload0 from "express-fileupload";
|
|
16
|
+
import fileUpload from "express-fileupload";
|
|
17
|
+
import { ListenOptions } from "node:net";
|
|
18
|
+
import * as express_serve_static_core0 from "express-serve-static-core";
|
|
19
|
+
import * as qs0 from "qs";
|
|
20
|
+
import * as zod_v4_core0 from "zod/v4/core";
|
|
20
21
|
|
|
22
|
+
//#region src/method.d.ts
|
|
21
23
|
declare const methods: ("get" | "post" | "put" | "delete" | "patch")[];
|
|
22
24
|
declare const clientMethods: ("get" | "post" | "put" | "delete" | "patch" | "head")[];
|
|
23
25
|
/**
|
|
@@ -32,19 +34,31 @@ type Method = (typeof methods)[number];
|
|
|
32
34
|
* @example Method | "head"
|
|
33
35
|
* */
|
|
34
36
|
type ClientMethod = (typeof clientMethods)[number];
|
|
35
|
-
|
|
37
|
+
/**
|
|
38
|
+
* @desc Methods supported in CORS headers
|
|
39
|
+
* @see makeCorsHeaders
|
|
40
|
+
* @see createWrongMethodHandler
|
|
41
|
+
* @example ClientMethod | "options"
|
|
42
|
+
* */
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/api-response.d.ts
|
|
36
45
|
/** @public this is the user facing configuration */
|
|
37
46
|
interface ApiResponse<S extends z.ZodType> {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
47
|
+
schema: S;
|
|
48
|
+
/** @default 200 for a positive and 400 for a negative response */
|
|
49
|
+
statusCode?: number | [number, ...number[]];
|
|
50
|
+
/**
|
|
51
|
+
* @example null is for no content, such as 204 and 302
|
|
52
|
+
* @default "application/json"
|
|
53
|
+
* */
|
|
54
|
+
mimeType?: string | [string, ...string[]] | null;
|
|
46
55
|
}
|
|
47
|
-
|
|
56
|
+
/**
|
|
57
|
+
* @private This is what the framework entities operate
|
|
58
|
+
* @see normalize
|
|
59
|
+
* */
|
|
60
|
+
//#endregion
|
|
61
|
+
//#region src/common-helpers.d.ts
|
|
48
62
|
/** @since zod 3.25.61 output type fixed */
|
|
49
63
|
declare const emptySchema: z.ZodObject<{}, z.core.$strip>;
|
|
50
64
|
type EmptySchema = typeof emptySchema;
|
|
@@ -58,16 +72,19 @@ type NoNever<T, F> = [T] extends [never] ? F : T;
|
|
|
58
72
|
* @example declare module "express-zod-api" { interface TagOverrides { users: unknown } }
|
|
59
73
|
* @link https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation
|
|
60
74
|
* */
|
|
61
|
-
interface TagOverrides {
|
|
62
|
-
}
|
|
75
|
+
interface TagOverrides {}
|
|
63
76
|
type Tag = NoNever<keyof TagOverrides, string>;
|
|
64
|
-
|
|
77
|
+
/** @see https://expressjs.com/en/guide/routing.html */
|
|
65
78
|
|
|
79
|
+
declare const getMessageFromError: (error: Error) => string;
|
|
80
|
+
/** Faster replacement to instanceof for code operating core types (traversing schemas) */
|
|
81
|
+
//#endregion
|
|
82
|
+
//#region src/logger-helpers.d.ts
|
|
66
83
|
declare const severity: {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
84
|
+
debug: number;
|
|
85
|
+
info: number;
|
|
86
|
+
warn: number;
|
|
87
|
+
error: number;
|
|
71
88
|
};
|
|
72
89
|
type Severity = keyof typeof severity;
|
|
73
90
|
/** @desc You can use any logger compatible with this type. */
|
|
@@ -77,125 +94,136 @@ type AbstractLogger = Record<Severity, (message: string, meta?: any) => any>;
|
|
|
77
94
|
* @example declare module "express-zod-api" { interface LoggerOverrides extends winston.Logger {} }
|
|
78
95
|
* @link https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation
|
|
79
96
|
* */
|
|
80
|
-
interface LoggerOverrides {
|
|
81
|
-
}
|
|
97
|
+
interface LoggerOverrides {}
|
|
82
98
|
type ActualLogger = AbstractLogger & LoggerOverrides;
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
99
|
+
//#endregion
|
|
100
|
+
//#region src/builtin-logger.d.ts
|
|
101
|
+
interface Context$1 extends FlatObject {
|
|
102
|
+
requestId?: string;
|
|
86
103
|
}
|
|
87
104
|
interface BuiltinLoggerConfig {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
105
|
+
/**
|
|
106
|
+
* @desc The minimal severity to log or "silent" to disable logging
|
|
107
|
+
* @example "debug" also enables pretty output for inspected entities
|
|
108
|
+
* */
|
|
109
|
+
level: "silent" | "warn" | "info" | "debug";
|
|
110
|
+
/** @desc Enables colors on printed severity and inspected entities */
|
|
111
|
+
color: boolean;
|
|
112
|
+
/**
|
|
113
|
+
* @desc Control how deeply entities should be inspected
|
|
114
|
+
* @example null
|
|
115
|
+
* @example Infinity
|
|
116
|
+
* */
|
|
117
|
+
depth: number | null;
|
|
118
|
+
/**
|
|
119
|
+
* @desc Context: the metadata applicable for each logged entry, used by .child() method
|
|
120
|
+
* @see childLoggerProvider
|
|
121
|
+
* */
|
|
122
|
+
ctx: Context$1;
|
|
106
123
|
}
|
|
107
124
|
interface ProfilerOptions {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
125
|
+
message: string;
|
|
126
|
+
/** @default "debug" */
|
|
127
|
+
severity?: Severity | ((ms: number) => Severity);
|
|
128
|
+
/** @default formatDuration - adaptive units and limited fraction */
|
|
129
|
+
formatter?: (ms: number) => string | number;
|
|
113
130
|
}
|
|
114
131
|
/** @desc Built-in console logger with optional colorful inspections */
|
|
115
132
|
declare class BuiltinLogger implements AbstractLogger {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
133
|
+
protected readonly config: BuiltinLoggerConfig;
|
|
134
|
+
/** @example new BuiltinLogger({ level: "debug", color: true, depth: 4 }) */
|
|
135
|
+
constructor({
|
|
136
|
+
color,
|
|
137
|
+
level,
|
|
138
|
+
depth,
|
|
139
|
+
ctx
|
|
140
|
+
}?: Partial<BuiltinLoggerConfig>);
|
|
141
|
+
protected format(subject: unknown): string;
|
|
142
|
+
protected print(method: Severity, message: string, meta?: unknown): void;
|
|
143
|
+
debug(message: string, meta?: unknown): void;
|
|
144
|
+
info(message: string, meta?: unknown): void;
|
|
145
|
+
warn(message: string, meta?: unknown): void;
|
|
146
|
+
error(message: string, meta?: unknown): void;
|
|
147
|
+
child(ctx: Context$1): BuiltinLogger;
|
|
148
|
+
/**
|
|
149
|
+
* @desc The argument used for instance created by .child() method
|
|
150
|
+
* @see ChildLoggerProvider
|
|
151
|
+
* */
|
|
152
|
+
get ctx(): Context$1;
|
|
153
|
+
/** @desc Measures the duration until you invoke the returned callback */
|
|
154
|
+
profile(message: string): () => void;
|
|
155
|
+
profile(options: ProfilerOptions): () => void;
|
|
134
156
|
}
|
|
135
|
-
|
|
157
|
+
//#endregion
|
|
158
|
+
//#region src/io-schema.d.ts
|
|
136
159
|
type Base$1 = object & {
|
|
137
|
-
|
|
160
|
+
[Symbol.iterator]?: never;
|
|
138
161
|
};
|
|
139
162
|
/** @desc The type allowed on the top level of Middlewares and Endpoints */
|
|
140
163
|
type IOSchema = z.ZodType<Base$1>;
|
|
141
164
|
/** EndpointsFactory schema extended type when adding a Middleware */
|
|
142
165
|
type Extension<Current extends IOSchema | undefined, Inc extends IOSchema | undefined> = Current extends IOSchema ? Inc extends IOSchema ? z.ZodIntersection<Current, Inc> : Current : Inc;
|
|
166
|
+
/** Makes a schema for EndpointsFactory extended with a Middleware */
|
|
167
|
+
|
|
143
168
|
/** The Endpoint input schema type, condition wrapped into schema to make it z.output-compatible */
|
|
144
169
|
type FinalInputSchema<FIN extends IOSchema | undefined, BIN extends IOSchema> = z.ZodIntersection<FIN extends IOSchema ? FIN : BIN, BIN>;
|
|
145
|
-
|
|
170
|
+
/** Makes the Endpoint input schema */
|
|
171
|
+
//#endregion
|
|
172
|
+
//#region src/logical-container.d.ts
|
|
146
173
|
type LogicalOr<T> = {
|
|
147
|
-
|
|
174
|
+
or: T[];
|
|
148
175
|
};
|
|
149
176
|
type LogicalAnd<T> = {
|
|
150
|
-
|
|
177
|
+
and: T[];
|
|
151
178
|
};
|
|
152
179
|
type LogicalContainer<T> = LogicalOr<T | LogicalAnd<T>> | LogicalAnd<T | LogicalOr<T>> | T;
|
|
153
|
-
|
|
180
|
+
//#endregion
|
|
181
|
+
//#region src/security.d.ts
|
|
154
182
|
interface BasicSecurity {
|
|
155
|
-
|
|
183
|
+
type: "basic";
|
|
156
184
|
}
|
|
157
185
|
interface BearerSecurity {
|
|
158
|
-
|
|
159
|
-
|
|
186
|
+
type: "bearer";
|
|
187
|
+
format?: "JWT" | string;
|
|
160
188
|
}
|
|
161
189
|
interface InputSecurity<K extends string> {
|
|
162
|
-
|
|
163
|
-
|
|
190
|
+
type: "input";
|
|
191
|
+
name: K;
|
|
164
192
|
}
|
|
165
193
|
interface HeaderSecurity {
|
|
166
|
-
|
|
167
|
-
|
|
194
|
+
type: "header";
|
|
195
|
+
name: string;
|
|
168
196
|
}
|
|
169
197
|
interface CookieSecurity {
|
|
170
|
-
|
|
171
|
-
|
|
198
|
+
type: "cookie";
|
|
199
|
+
name: string;
|
|
172
200
|
}
|
|
173
201
|
/**
|
|
174
202
|
* @see https://swagger.io/docs/specification/authentication/openid-connect-discovery/
|
|
175
203
|
* @desc available scopes has to be provided via the specified URL
|
|
176
204
|
*/
|
|
177
205
|
interface OpenIdSecurity {
|
|
178
|
-
|
|
179
|
-
|
|
206
|
+
type: "openid";
|
|
207
|
+
url: string;
|
|
180
208
|
}
|
|
181
209
|
interface AuthUrl {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
210
|
+
/**
|
|
211
|
+
* @desc The authorization URL to use for this flow. Can be relative to the API server URL.
|
|
212
|
+
* @see https://swagger.io/docs/specification/api-host-and-base-path/
|
|
213
|
+
*/
|
|
214
|
+
authorizationUrl: string;
|
|
187
215
|
}
|
|
188
216
|
interface TokenUrl {
|
|
189
|
-
|
|
190
|
-
|
|
217
|
+
/** @desc The token URL to use for this flow. Can be relative to the API server URL. */
|
|
218
|
+
tokenUrl: string;
|
|
191
219
|
}
|
|
192
220
|
interface RefreshUrl {
|
|
193
|
-
|
|
194
|
-
|
|
221
|
+
/** @desc The URL to be used for obtaining refresh tokens. Can be relative to the API server URL. */
|
|
222
|
+
refreshUrl?: string;
|
|
195
223
|
}
|
|
196
224
|
interface Scopes<K extends string> {
|
|
197
|
-
|
|
198
|
-
|
|
225
|
+
/** @desc The available scopes for the OAuth2 security and their short descriptions. Optional. */
|
|
226
|
+
scopes?: Record<K, string>;
|
|
199
227
|
}
|
|
200
228
|
type AuthCodeFlow<S extends string> = AuthUrl & TokenUrl & RefreshUrl & Scopes<S>;
|
|
201
229
|
type ImplicitFlow<S extends string> = AuthUrl & RefreshUrl & Scopes<S>;
|
|
@@ -205,17 +233,17 @@ type ClientCredFlow<S extends string> = TokenUrl & RefreshUrl & Scopes<S>;
|
|
|
205
233
|
* @see https://swagger.io/docs/specification/authentication/oauth2/
|
|
206
234
|
*/
|
|
207
235
|
interface OAuth2Security<S extends string> {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
236
|
+
type: "oauth2";
|
|
237
|
+
flows?: {
|
|
238
|
+
/** @desc Authorization Code flow (previously called accessCode in OpenAPI 2.0) */
|
|
239
|
+
authorizationCode?: AuthCodeFlow<S>;
|
|
240
|
+
/** @desc Implicit flow */
|
|
241
|
+
implicit?: ImplicitFlow<S>;
|
|
242
|
+
/** @desc Resource Owner Password flow */
|
|
243
|
+
password?: PasswordFlow<S>;
|
|
244
|
+
/** @desc Client Credentials flow (previously called application in OpenAPI 2.0) */
|
|
245
|
+
clientCredentials?: ClientCredFlow<S>;
|
|
246
|
+
};
|
|
219
247
|
}
|
|
220
248
|
/**
|
|
221
249
|
* @desc Middleware security schema descriptor
|
|
@@ -223,122 +251,139 @@ interface OAuth2Security<S extends string> {
|
|
|
223
251
|
* @param S is an optional union of scopes used by OAuth2Security
|
|
224
252
|
* */
|
|
225
253
|
type Security<K extends string = string, S extends string = string> = BasicSecurity | BearerSecurity | InputSecurity<K> | HeaderSecurity | CookieSecurity | OpenIdSecurity | OAuth2Security<S>;
|
|
226
|
-
|
|
254
|
+
//#endregion
|
|
255
|
+
//#region src/middleware.d.ts
|
|
227
256
|
type Handler$2<IN, OPT, OUT> = (params: {
|
|
228
|
-
|
|
229
|
-
|
|
257
|
+
/** @desc The inputs from the enabled input sources validated against the input schema of the Middleware */
|
|
258
|
+
input: IN;
|
|
259
|
+
/**
|
|
260
|
+
* @desc The returns of the previously executed Middlewares (typed when chaining Middlewares)
|
|
261
|
+
* @link https://github.com/RobinTail/express-zod-api/discussions/1250
|
|
262
|
+
* */
|
|
263
|
+
options: OPT;
|
|
264
|
+
/** @link https://expressjs.com/en/5x/api.html#req */
|
|
265
|
+
request: Request;
|
|
266
|
+
/** @link https://expressjs.com/en/5x/api.html#res */
|
|
267
|
+
response: Response;
|
|
268
|
+
/** @desc The instance of the configured logger */
|
|
269
|
+
logger: ActualLogger;
|
|
270
|
+
}) => Promise<OUT>;
|
|
271
|
+
declare abstract class AbstractMiddleware {
|
|
272
|
+
abstract execute(params: {
|
|
273
|
+
input: unknown;
|
|
274
|
+
options: FlatObject;
|
|
275
|
+
request: Request;
|
|
276
|
+
response: Response;
|
|
277
|
+
logger: ActualLogger;
|
|
278
|
+
}): Promise<FlatObject>;
|
|
279
|
+
}
|
|
280
|
+
declare class Middleware<OPT extends FlatObject, OUT extends FlatObject, SCO extends string, IN extends IOSchema | undefined = undefined> extends AbstractMiddleware {
|
|
281
|
+
#private;
|
|
282
|
+
constructor({
|
|
283
|
+
input,
|
|
284
|
+
security,
|
|
285
|
+
handler
|
|
286
|
+
}: {
|
|
230
287
|
/**
|
|
231
|
-
* @desc
|
|
232
|
-
* @
|
|
288
|
+
* @desc Input schema of the Middleware, combining properties from all the enabled input sources
|
|
289
|
+
* @default undefined
|
|
290
|
+
* @see defaultInputSources
|
|
233
291
|
* */
|
|
292
|
+
input?: IN;
|
|
293
|
+
/** @desc Declaration of the security schemas implemented within the handler */
|
|
294
|
+
security?: LogicalContainer<Security<Extract<keyof z.input<IN>, string>, SCO>>;
|
|
295
|
+
/** @desc The handler returning options available to Endpoints */
|
|
296
|
+
handler: Handler$2<z.output<IN>, OPT, OUT>;
|
|
297
|
+
});
|
|
298
|
+
/** @throws InputValidationError */
|
|
299
|
+
execute({
|
|
300
|
+
input,
|
|
301
|
+
...rest
|
|
302
|
+
}: {
|
|
303
|
+
input: unknown;
|
|
234
304
|
options: OPT;
|
|
235
|
-
/** @link https://expressjs.com/en/5x/api.html#req */
|
|
236
305
|
request: Request;
|
|
237
|
-
/** @link https://expressjs.com/en/5x/api.html#res */
|
|
238
306
|
response: Response;
|
|
239
|
-
/** @desc The instance of the configured logger */
|
|
240
307
|
logger: ActualLogger;
|
|
241
|
-
})
|
|
242
|
-
declare abstract class AbstractMiddleware {
|
|
243
|
-
abstract execute(params: {
|
|
244
|
-
input: unknown;
|
|
245
|
-
options: FlatObject;
|
|
246
|
-
request: Request;
|
|
247
|
-
response: Response;
|
|
248
|
-
logger: ActualLogger;
|
|
249
|
-
}): Promise<FlatObject>;
|
|
250
|
-
}
|
|
251
|
-
declare class Middleware<OPT extends FlatObject, OUT extends FlatObject, SCO extends string, IN extends IOSchema | undefined = undefined> extends AbstractMiddleware {
|
|
252
|
-
#private;
|
|
253
|
-
constructor({ input, security, handler, }: {
|
|
254
|
-
/**
|
|
255
|
-
* @desc Input schema of the Middleware, combining properties from all the enabled input sources
|
|
256
|
-
* @default undefined
|
|
257
|
-
* @see defaultInputSources
|
|
258
|
-
* */
|
|
259
|
-
input?: IN;
|
|
260
|
-
/** @desc Declaration of the security schemas implemented within the handler */
|
|
261
|
-
security?: LogicalContainer<Security<Extract<keyof z.input<IN>, string>, SCO>>;
|
|
262
|
-
/** @desc The handler returning options available to Endpoints */
|
|
263
|
-
handler: Handler$2<z.output<IN>, OPT, OUT>;
|
|
264
|
-
});
|
|
265
|
-
/** @throws InputValidationError */
|
|
266
|
-
execute({ input, ...rest }: {
|
|
267
|
-
input: unknown;
|
|
268
|
-
options: OPT;
|
|
269
|
-
request: Request;
|
|
270
|
-
response: Response;
|
|
271
|
-
logger: ActualLogger;
|
|
272
|
-
}): Promise<OUT>;
|
|
308
|
+
}): Promise<OUT>;
|
|
273
309
|
}
|
|
274
310
|
declare class ExpressMiddleware<R extends Request, S extends Response, OUT extends FlatObject> extends Middleware<FlatObject, OUT, string> {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
311
|
+
constructor(nativeMw: (request: R, response: S, next: NextFunction) => any, {
|
|
312
|
+
provider,
|
|
313
|
+
transformer
|
|
314
|
+
}?: {
|
|
315
|
+
provider?: (request: R, response: S) => OUT | Promise<OUT>;
|
|
316
|
+
transformer?: (err: Error) => Error;
|
|
317
|
+
});
|
|
279
318
|
}
|
|
280
|
-
|
|
319
|
+
//#endregion
|
|
320
|
+
//#region src/depends-on-method.d.ts
|
|
281
321
|
declare class DependsOnMethod extends Routable {
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
322
|
+
#private;
|
|
323
|
+
constructor(endpoints: Partial<Record<Method, AbstractEndpoint>>);
|
|
324
|
+
deprecated(): this;
|
|
285
325
|
}
|
|
286
|
-
|
|
287
|
-
|
|
326
|
+
//#endregion
|
|
327
|
+
//#region src/serve-static.d.ts
|
|
328
|
+
type OriginalStatic = typeof express.static;
|
|
288
329
|
declare class ServeStatic {
|
|
289
|
-
|
|
290
|
-
|
|
330
|
+
#private;
|
|
331
|
+
constructor(...params: Parameters<OriginalStatic>);
|
|
291
332
|
}
|
|
292
|
-
|
|
333
|
+
//#endregion
|
|
334
|
+
//#region src/result-helpers.d.ts
|
|
293
335
|
type ResultSchema<R extends Result> = R extends Result<infer S> ? S : never;
|
|
294
336
|
type DiscriminatedResult = {
|
|
295
|
-
|
|
296
|
-
|
|
337
|
+
output: FlatObject;
|
|
338
|
+
error: null;
|
|
297
339
|
} | {
|
|
298
|
-
|
|
299
|
-
|
|
340
|
+
output: null;
|
|
341
|
+
error: Error;
|
|
300
342
|
};
|
|
343
|
+
/** @throws ResultHandlerError when Result is an empty array */
|
|
344
|
+
|
|
301
345
|
/**
|
|
302
346
|
* @example InputValidationError —> BadRequest(400)
|
|
303
347
|
* @example Error —> InternalServerError(500)
|
|
304
348
|
* */
|
|
305
349
|
declare const ensureHttpError: (error: Error) => HttpError;
|
|
306
|
-
|
|
350
|
+
//#endregion
|
|
351
|
+
//#region src/result-handler.d.ts
|
|
307
352
|
type Handler$1<RES = unknown> = (params: DiscriminatedResult & {
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
353
|
+
/** null in case of failure to parse or to find the matching endpoint (error: not found) */
|
|
354
|
+
input: FlatObject | null;
|
|
355
|
+
/** can be empty: check presence of the required property using "in" operator */
|
|
356
|
+
options: FlatObject;
|
|
357
|
+
request: Request;
|
|
358
|
+
response: Response<RES>;
|
|
359
|
+
logger: ActualLogger;
|
|
315
360
|
}) => void | Promise<void>;
|
|
316
361
|
type Result<S extends z.ZodType = z.ZodType> = S | ApiResponse<S> | ApiResponse<S>[];
|
|
317
362
|
type LazyResult<R extends Result, A extends unknown[] = []> = (...args: A) => R;
|
|
318
363
|
declare abstract class AbstractResultHandler {
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
364
|
+
#private;
|
|
365
|
+
protected constructor(handler: Handler$1);
|
|
366
|
+
execute(...params: Parameters<Handler$1>): void | Promise<void>;
|
|
322
367
|
}
|
|
323
368
|
declare class ResultHandler<POS extends Result, NEG extends Result> extends AbstractResultHandler {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
369
|
+
#private;
|
|
370
|
+
constructor(params: {
|
|
371
|
+
/** @desc A description of the API response in case of success (schema, status code, MIME type) */
|
|
372
|
+
positive: POS | LazyResult<POS, [IOSchema]>;
|
|
373
|
+
/** @desc A description of the API response in case of error (schema, status code, MIME type) */
|
|
374
|
+
negative: NEG | LazyResult<NEG>;
|
|
375
|
+
/** @desc The actual implementation to transmit the response in any case */
|
|
376
|
+
handler: Handler$1<z.output<ResultSchema<POS> | ResultSchema<NEG>>>;
|
|
377
|
+
});
|
|
333
378
|
}
|
|
334
379
|
declare const defaultResultHandler: ResultHandler<z.ZodObject<{
|
|
335
|
-
|
|
336
|
-
|
|
380
|
+
status: z.ZodLiteral<"success">;
|
|
381
|
+
data: IOSchema;
|
|
337
382
|
}, z.core.$strip>, z.ZodObject<{
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
383
|
+
status: z.ZodLiteral<"error">;
|
|
384
|
+
error: z.ZodObject<{
|
|
385
|
+
message: z.ZodString;
|
|
386
|
+
}, z.core.$strip>;
|
|
342
387
|
}, z.core.$strip>>;
|
|
343
388
|
/**
|
|
344
389
|
* @deprecated Resist the urge of using it: this handler is designed only to simplify the migration of legacy APIs.
|
|
@@ -346,13 +391,15 @@ declare const defaultResultHandler: ResultHandler<z.ZodObject<{
|
|
|
346
391
|
* @desc This handler expects your endpoint to have the property 'items' in the output object schema
|
|
347
392
|
* */
|
|
348
393
|
declare const arrayResultHandler: ResultHandler<z.ZodArray<z.core.$ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>> | z.ZodArray<z.ZodAny>, {
|
|
349
|
-
|
|
350
|
-
|
|
394
|
+
schema: z.ZodString;
|
|
395
|
+
mimeType: string;
|
|
351
396
|
}>;
|
|
352
|
-
|
|
397
|
+
//#endregion
|
|
398
|
+
//#region src/server-helpers.d.ts
|
|
353
399
|
/** @desc Returns child logger for the given request (if configured) or the configured logger otherwise */
|
|
354
400
|
type GetLogger = (request?: Request) => ActualLogger;
|
|
355
|
-
|
|
401
|
+
//#endregion
|
|
402
|
+
//#region src/routing.d.ts
|
|
356
403
|
/**
|
|
357
404
|
* @example { v1: { books: { ":bookId": getBookEndpoint } } }
|
|
358
405
|
* @example { "v1/books/:bookId": getBookEndpoint }
|
|
@@ -360,273 +407,293 @@ type GetLogger = (request?: Request) => ActualLogger;
|
|
|
360
407
|
* @example { v1: { "patch /books/:bookId": changeBookEndpoint } }
|
|
361
408
|
* */
|
|
362
409
|
interface Routing {
|
|
363
|
-
|
|
410
|
+
[K: string]: Routing | DependsOnMethod | AbstractEndpoint | ServeStatic;
|
|
364
411
|
}
|
|
365
|
-
|
|
412
|
+
//#endregion
|
|
413
|
+
//#region src/routable.d.ts
|
|
366
414
|
declare abstract class Routable {
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
415
|
+
/** @desc Marks the route as deprecated (makes a copy of the endpoint) */
|
|
416
|
+
abstract deprecated(): this;
|
|
417
|
+
/** @desc Enables nested routes within the path assigned to the subject */
|
|
418
|
+
nest(routing: Routing): Routing;
|
|
371
419
|
}
|
|
372
|
-
|
|
420
|
+
//#endregion
|
|
421
|
+
//#region src/endpoint.d.ts
|
|
373
422
|
type Handler<IN, OUT, OPT> = (params: {
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
423
|
+
/** @desc The inputs from the enabled input sources validated against the final input schema (incl. Middlewares) */
|
|
424
|
+
input: IN;
|
|
425
|
+
/** @desc The returns of the assigned Middlewares */
|
|
426
|
+
options: OPT;
|
|
427
|
+
/** @desc The instance of the configured logger */
|
|
428
|
+
logger: ActualLogger;
|
|
380
429
|
}) => Promise<OUT>;
|
|
381
430
|
declare abstract class AbstractEndpoint extends Routable {
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
431
|
+
abstract execute(params: {
|
|
432
|
+
request: Request;
|
|
433
|
+
response: Response;
|
|
434
|
+
logger: ActualLogger;
|
|
435
|
+
config: CommonConfig;
|
|
436
|
+
}): Promise<void>;
|
|
388
437
|
}
|
|
389
438
|
declare class Endpoint<IN extends IOSchema, OUT extends IOSchema, OPT extends FlatObject> extends AbstractEndpoint {
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
439
|
+
#private;
|
|
440
|
+
constructor(def: {
|
|
441
|
+
deprecated?: boolean;
|
|
442
|
+
middlewares?: AbstractMiddleware[];
|
|
443
|
+
inputSchema: IN;
|
|
444
|
+
outputSchema: OUT;
|
|
445
|
+
handler: Handler<z.output<IN>, z.input<OUT>, OPT>;
|
|
446
|
+
resultHandler: AbstractResultHandler;
|
|
447
|
+
description?: string;
|
|
448
|
+
shortDescription?: string;
|
|
449
|
+
getOperationId?: (method: ClientMethod) => string | undefined;
|
|
450
|
+
methods?: Method[];
|
|
451
|
+
scopes?: string[];
|
|
452
|
+
tags?: string[];
|
|
453
|
+
});
|
|
454
|
+
deprecated(): this;
|
|
455
|
+
execute({
|
|
456
|
+
request,
|
|
457
|
+
response,
|
|
458
|
+
logger,
|
|
459
|
+
config
|
|
460
|
+
}: {
|
|
461
|
+
request: Request;
|
|
462
|
+
response: Response;
|
|
463
|
+
logger: ActualLogger;
|
|
464
|
+
config: CommonConfig;
|
|
465
|
+
}): Promise<undefined>;
|
|
412
466
|
}
|
|
413
|
-
|
|
467
|
+
//#endregion
|
|
468
|
+
//#region src/config-type.d.ts
|
|
414
469
|
type InputSource = keyof Pick<Request, "query" | "body" | "files" | "params" | "headers">;
|
|
415
470
|
type InputSources = Record<Method, InputSource[]>;
|
|
416
471
|
type Headers = Record<string, string>;
|
|
417
472
|
type HeadersProvider = (params: {
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
473
|
+
/** @desc The default headers to be overridden. */
|
|
474
|
+
defaultHeaders: Headers;
|
|
475
|
+
request: Request;
|
|
476
|
+
endpoint: AbstractEndpoint;
|
|
477
|
+
logger: ActualLogger;
|
|
423
478
|
}) => Headers | Promise<Headers>;
|
|
424
479
|
type ChildLoggerProvider = (params: {
|
|
425
|
-
|
|
426
|
-
|
|
480
|
+
request: Request;
|
|
481
|
+
parent: ActualLogger;
|
|
427
482
|
}) => ActualLogger | Promise<ActualLogger>;
|
|
428
483
|
type LogAccess = (request: Request, logger: ActualLogger) => void;
|
|
429
484
|
interface CommonConfig {
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
485
|
+
/**
|
|
486
|
+
* @desc Enables cross-origin resource sharing.
|
|
487
|
+
* @link https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
|
|
488
|
+
* @desc You can override the default CORS headers by setting up a provider function here.
|
|
489
|
+
*/
|
|
490
|
+
cors: boolean | HeadersProvider;
|
|
491
|
+
/**
|
|
492
|
+
* @desc How to respond to a request that uses a wrong method to an existing endpoint
|
|
493
|
+
* @example 404 — Not found
|
|
494
|
+
* @example 405 — Method not allowed, incl. the "Allow" header with a list of methods
|
|
495
|
+
* @default 405
|
|
496
|
+
* */
|
|
497
|
+
wrongMethodBehavior?: 404 | 405;
|
|
498
|
+
/**
|
|
499
|
+
* @desc The ResultHandler to use for handling routing, parsing and upload errors
|
|
500
|
+
* @default defaultResultHandler
|
|
501
|
+
* @see defaultResultHandler
|
|
502
|
+
*/
|
|
503
|
+
errorHandler?: AbstractResultHandler;
|
|
504
|
+
/**
|
|
505
|
+
* @desc Built-in logger configuration or an instance of any compatible logger.
|
|
506
|
+
* @example { level: "debug", color: true }
|
|
507
|
+
* @default { level: NODE_ENV === "production" ? "warn" : "debug", color: isSupported(), depth: 2 }
|
|
508
|
+
* */
|
|
509
|
+
logger?: Partial<BuiltinLoggerConfig> | AbstractLogger;
|
|
510
|
+
/**
|
|
511
|
+
* @desc A child logger returned by this function can override the logger in all handlers for each request
|
|
512
|
+
* @example ({ parent }) => parent.child({ requestId: uuid() })
|
|
513
|
+
* */
|
|
514
|
+
childLoggerProvider?: ChildLoggerProvider;
|
|
515
|
+
/**
|
|
516
|
+
* @desc The function for producing access logs
|
|
517
|
+
* @default ({ method, path }, logger) => logger.debug(`${method}: ${path}`)
|
|
518
|
+
* @example null — disables the feature
|
|
519
|
+
* */
|
|
520
|
+
accessLogger?: null | LogAccess;
|
|
521
|
+
/**
|
|
522
|
+
* @desc You can disable the startup logo.
|
|
523
|
+
* @default true
|
|
524
|
+
*/
|
|
525
|
+
startupLogo?: boolean;
|
|
526
|
+
/**
|
|
527
|
+
* @desc Which properties of request are combined into the input for endpoints and middlewares.
|
|
528
|
+
* @desc The order matters: priority from lowest to highest
|
|
529
|
+
* @default defaultInputSources
|
|
530
|
+
* @see defaultInputSources
|
|
531
|
+
*/
|
|
532
|
+
inputSources?: Partial<InputSources>;
|
|
478
533
|
}
|
|
479
534
|
type BeforeUpload = (params: {
|
|
480
|
-
|
|
481
|
-
|
|
535
|
+
request: Request;
|
|
536
|
+
logger: ActualLogger;
|
|
482
537
|
}) => void | Promise<void>;
|
|
483
|
-
type UploadOptions = Pick<
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
538
|
+
type UploadOptions = Pick<fileUpload.Options, "createParentPath" | "uriDecodeFileNames" | "safeFileNames" | "preserveExtension" | "useTempFiles" | "tempFileDir" | "debug" | "uploadTimeout" | "limits"> & {
|
|
539
|
+
/**
|
|
540
|
+
* @desc The error to throw when the file exceeds the configured fileSize limit (handled by errorHandler).
|
|
541
|
+
* @see limits
|
|
542
|
+
* @override limitHandler
|
|
543
|
+
* @example createHttpError(413, "The file is too large")
|
|
544
|
+
* */
|
|
545
|
+
limitError?: Error;
|
|
546
|
+
/**
|
|
547
|
+
* @desc A handler to execute before uploading — it can be used for restrictions by throwing an error.
|
|
548
|
+
* @example ({ request }) => { throw createHttpError(403, "Not authorized"); }
|
|
549
|
+
* */
|
|
550
|
+
beforeUpload?: BeforeUpload;
|
|
496
551
|
};
|
|
497
552
|
type CompressionOptions = Pick<compression.CompressionOptions, "threshold" | "level" | "strategy" | "chunkSize" | "memLevel">;
|
|
498
553
|
interface GracefulOptions {
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
554
|
+
/**
|
|
555
|
+
* @desc Time given to drain ongoing requests before closing the server.
|
|
556
|
+
* @default 1000
|
|
557
|
+
* */
|
|
558
|
+
timeout?: number;
|
|
559
|
+
/**
|
|
560
|
+
* @desc Process event (Signal) that triggers the graceful shutdown.
|
|
561
|
+
* @see Signals
|
|
562
|
+
* @default [SIGINT, SIGTERM]
|
|
563
|
+
* */
|
|
564
|
+
events?: string[];
|
|
565
|
+
/** @desc The hook to call after the server was closed, but before terminating the process. */
|
|
566
|
+
beforeExit?: () => void | Promise<void>;
|
|
512
567
|
}
|
|
513
568
|
type BeforeRouting = (params: {
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
569
|
+
app: IRouter;
|
|
570
|
+
/** @desc Returns child logger for the given request (if configured) or the configured logger otherwise */
|
|
571
|
+
getLogger: GetLogger;
|
|
517
572
|
}) => void | Promise<void>;
|
|
518
573
|
interface HttpConfig {
|
|
519
|
-
|
|
520
|
-
|
|
574
|
+
/** @desc Port, UNIX socket or custom options. */
|
|
575
|
+
listen: number | string | ListenOptions;
|
|
521
576
|
}
|
|
522
577
|
interface HttpsConfig extends HttpConfig {
|
|
523
|
-
|
|
524
|
-
|
|
578
|
+
/** @desc At least "cert" and "key" options required. */
|
|
579
|
+
options: ServerOptions;
|
|
525
580
|
}
|
|
526
581
|
interface ServerConfig extends CommonConfig {
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
582
|
+
/** @desc HTTP server configuration. */
|
|
583
|
+
http?: HttpConfig;
|
|
584
|
+
/** @desc HTTPS server configuration. */
|
|
585
|
+
https?: HttpsConfig;
|
|
586
|
+
/**
|
|
587
|
+
* @desc Custom JSON parser.
|
|
588
|
+
* @default express.json()
|
|
589
|
+
* @link https://expressjs.com/en/5x/api.html#express.json
|
|
590
|
+
* */
|
|
591
|
+
jsonParser?: RequestHandler;
|
|
592
|
+
/**
|
|
593
|
+
* @desc Enable or configure uploads handling.
|
|
594
|
+
* @requires express-fileupload
|
|
595
|
+
* */
|
|
596
|
+
upload?: boolean | UploadOptions;
|
|
597
|
+
/**
|
|
598
|
+
* @desc Enable or configure response compression.
|
|
599
|
+
* @requires compression
|
|
600
|
+
*/
|
|
601
|
+
compression?: boolean | CompressionOptions;
|
|
602
|
+
/**
|
|
603
|
+
* @desc Custom raw parser (assigns Buffer to request body)
|
|
604
|
+
* @default express.raw()
|
|
605
|
+
* @link https://expressjs.com/en/5x/api.html#express.raw
|
|
606
|
+
* */
|
|
607
|
+
rawParser?: RequestHandler;
|
|
608
|
+
/**
|
|
609
|
+
* @desc Custom parser for URL Encoded requests used for submitting HTML forms
|
|
610
|
+
* @default express.urlencoded()
|
|
611
|
+
* @link https://expressjs.com/en/5x/api.html#express.urlencoded
|
|
612
|
+
* */
|
|
613
|
+
formParser?: RequestHandler;
|
|
614
|
+
/**
|
|
615
|
+
* @desc A code to execute before processing the Routing of your API (and before parsing).
|
|
616
|
+
* @desc This can be a good place for express middlewares establishing their own routes.
|
|
617
|
+
* @desc It can help to avoid making a DIY solution based on the attachRouting() approach.
|
|
618
|
+
* @example ({ app }) => { app.use('/docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument)); }
|
|
619
|
+
* */
|
|
620
|
+
beforeRouting?: BeforeRouting;
|
|
621
|
+
/**
|
|
622
|
+
* @desc Rejects new connections and attempts to finish ongoing ones in the specified time before exit.
|
|
623
|
+
* */
|
|
624
|
+
gracefulShutdown?: boolean | GracefulOptions;
|
|
570
625
|
}
|
|
571
626
|
interface AppConfig extends CommonConfig {
|
|
572
|
-
|
|
573
|
-
|
|
627
|
+
/** @desc Your custom express app or express router instead. */
|
|
628
|
+
app: IRouter;
|
|
574
629
|
}
|
|
575
630
|
declare function createConfig(config: ServerConfig): ServerConfig;
|
|
576
631
|
declare function createConfig(config: AppConfig): AppConfig;
|
|
577
|
-
|
|
632
|
+
//#endregion
|
|
633
|
+
//#region src/endpoints-factory.d.ts
|
|
578
634
|
interface BuildProps<IN extends IOSchema, OUT extends IOSchema | z.ZodVoid, MIN extends IOSchema | undefined, OPT extends FlatObject, SCO extends string> {
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
635
|
+
/**
|
|
636
|
+
* @desc Input schema of the Endpoint, combining properties from all the enabled input sources (path params, headers)
|
|
637
|
+
* @default z.object({})
|
|
638
|
+
* @see defaultInputSources
|
|
639
|
+
* */
|
|
640
|
+
input?: IN;
|
|
641
|
+
/** @desc The schema by which the returns of the Endpoint handler is validated */
|
|
642
|
+
output: OUT;
|
|
643
|
+
/** @desc The Endpoint handler receiving the validated inputs, returns of added Middlewares (options) and a logger */
|
|
644
|
+
handler: Handler<z.output<FinalInputSchema<MIN, IN>>, z.input<OUT>, OPT>;
|
|
645
|
+
/** @desc The operation description for the generated Documentation */
|
|
646
|
+
description?: string;
|
|
647
|
+
/** @desc The operation summary for the generated Documentation (50 symbols max) */
|
|
648
|
+
shortDescription?: string;
|
|
649
|
+
/** @desc The operation ID for the generated Documentation (must be unique) */
|
|
650
|
+
operationId?: string | ((method: ClientMethod) => string);
|
|
651
|
+
/**
|
|
652
|
+
* @desc HTTP method(s) this endpoint can handle
|
|
653
|
+
* @default "get" unless the Endpoint is assigned within DependsOnMethod
|
|
654
|
+
* @see DependsOnMethod
|
|
655
|
+
* */
|
|
656
|
+
method?: Method | [Method, ...Method[]];
|
|
657
|
+
/**
|
|
658
|
+
* @desc Scope(s) from the list of the ones defined by the added Middlewares having "oauth2" security type
|
|
659
|
+
* @see OAuth2Security
|
|
660
|
+
* */
|
|
661
|
+
scope?: SCO | SCO[];
|
|
662
|
+
/**
|
|
663
|
+
* @desc Tag(s) for generating Documentation. For establishing constraints:
|
|
664
|
+
* @see TagOverrides
|
|
665
|
+
* */
|
|
666
|
+
tag?: Tag | Tag[];
|
|
667
|
+
/** @desc Marks the operation deprecated in the generated Documentation */
|
|
668
|
+
deprecated?: boolean;
|
|
613
669
|
}
|
|
614
670
|
declare class EndpointsFactory<IN extends IOSchema | undefined = undefined, OUT extends FlatObject = EmptyObject, SCO extends string = string> {
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
671
|
+
#private;
|
|
672
|
+
protected resultHandler: AbstractResultHandler;
|
|
673
|
+
protected schema: IN;
|
|
674
|
+
protected middlewares: AbstractMiddleware[];
|
|
675
|
+
constructor(resultHandler: AbstractResultHandler);
|
|
676
|
+
addMiddleware<AOUT extends FlatObject, ASCO extends string, AIN extends IOSchema | undefined = undefined>(subject: Middleware<OUT, AOUT, ASCO, AIN> | ConstructorParameters<typeof Middleware<OUT, AOUT, ASCO, AIN>>[0]): EndpointsFactory<Extension<IN, AIN>, OUT & AOUT, SCO & ASCO>;
|
|
677
|
+
use: <R extends Request, S extends Response, AOUT extends FlatObject = Record<string, never>>(nativeMw: (request: R, response: S, next: express0.NextFunction) => any, params_1?: {
|
|
678
|
+
provider?: ((request: R, response: S) => AOUT | Promise<AOUT>) | undefined;
|
|
679
|
+
transformer?: (err: Error) => Error;
|
|
680
|
+
} | undefined) => EndpointsFactory<Extension<IN, undefined>, OUT & AOUT, SCO>;
|
|
681
|
+
addExpressMiddleware<R extends Request, S extends Response, AOUT extends FlatObject = EmptyObject>(...params: ConstructorParameters<typeof ExpressMiddleware<R, S, AOUT>>): EndpointsFactory<Extension<IN, undefined>, OUT & AOUT, SCO>;
|
|
682
|
+
addOptions<AOUT extends FlatObject>(getOptions: () => Promise<AOUT>): EndpointsFactory<Extension<IN, undefined>, OUT & AOUT, SCO>;
|
|
683
|
+
build<BOUT extends IOSchema, BIN extends IOSchema = EmptySchema>({
|
|
684
|
+
input,
|
|
685
|
+
output: outputSchema,
|
|
686
|
+
operationId,
|
|
687
|
+
scope,
|
|
688
|
+
tag,
|
|
689
|
+
method,
|
|
690
|
+
...rest
|
|
691
|
+
}: BuildProps<BIN, BOUT, IN, OUT, SCO>): Endpoint<FinalInputSchema<IN, BIN>, BOUT, OUT>;
|
|
692
|
+
/** @desc shorthand for returning {} while having output schema z.object({}) */
|
|
693
|
+
buildVoid<BIN extends IOSchema = EmptySchema>({
|
|
694
|
+
handler,
|
|
695
|
+
...rest
|
|
696
|
+
}: Omit<BuildProps<BIN, z.ZodVoid, IN, OUT, SCO>, "output">): Endpoint<FinalInputSchema<IN, BIN>, z.ZodObject<{}, z.core.$strip>, OUT>;
|
|
630
697
|
}
|
|
631
698
|
declare const defaultEndpointsFactory: EndpointsFactory<undefined, Record<string, never>, string>;
|
|
632
699
|
/**
|
|
@@ -635,277 +702,332 @@ declare const defaultEndpointsFactory: EndpointsFactory<undefined, Record<string
|
|
|
635
702
|
* @desc The result handler of this factory expects your endpoint to have the property 'items' in the output schema
|
|
636
703
|
*/
|
|
637
704
|
declare const arrayEndpointsFactory: EndpointsFactory<undefined, Record<string, never>, string>;
|
|
638
|
-
|
|
705
|
+
//#endregion
|
|
706
|
+
//#region src/server.d.ts
|
|
639
707
|
declare const attachRouting: (config: AppConfig, routing: Routing) => {
|
|
640
|
-
|
|
641
|
-
|
|
708
|
+
notFoundHandler: express.RequestHandler<express_serve_static_core0.ParamsDictionary, any, any, qs0.ParsedQs, Record<string, any>>;
|
|
709
|
+
logger: AbstractLogger | BuiltinLogger;
|
|
642
710
|
};
|
|
643
711
|
declare const createServer: (config: ServerConfig, routing: Routing) => Promise<{
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
712
|
+
app: express_serve_static_core0.Express;
|
|
713
|
+
logger: AbstractLogger | BuiltinLogger;
|
|
714
|
+
servers: (http.Server<typeof http.IncomingMessage, typeof http.ServerResponse> | https.Server<typeof http.IncomingMessage, typeof http.ServerResponse>)[];
|
|
647
715
|
}>;
|
|
648
|
-
|
|
716
|
+
//#endregion
|
|
717
|
+
//#region src/documentation-helpers.d.ts
|
|
649
718
|
interface ReqResCommons {
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
719
|
+
makeRef: (key: object | string, subject: SchemaObject | ReferenceObject, name?: string) => ReferenceObject;
|
|
720
|
+
path: string;
|
|
721
|
+
method: ClientMethod;
|
|
653
722
|
}
|
|
654
723
|
interface OpenAPIContext extends ReqResCommons {
|
|
655
|
-
|
|
724
|
+
isResponse: boolean;
|
|
656
725
|
}
|
|
657
726
|
type Depicter = (zodCtx: {
|
|
658
|
-
|
|
659
|
-
|
|
727
|
+
zodSchema: z.core.$ZodType;
|
|
728
|
+
jsonSchema: z.core.JSONSchema.BaseSchema;
|
|
660
729
|
}, oasCtx: OpenAPIContext) => z.core.JSONSchema.BaseSchema | SchemaObject;
|
|
661
730
|
/** @desc Using defaultIsHeader when returns null or undefined */
|
|
662
731
|
type IsHeader = (name: string, method: ClientMethod, path: string) => boolean | null | undefined;
|
|
663
732
|
type BrandHandling = Record<string | symbol, Depicter>;
|
|
664
733
|
declare const depictTags: (tags: Partial<Record<Tag, string | {
|
|
665
|
-
|
|
666
|
-
|
|
734
|
+
description: string;
|
|
735
|
+
url?: string;
|
|
667
736
|
}>>) => TagObject[];
|
|
668
|
-
|
|
737
|
+
//#endregion
|
|
738
|
+
//#region src/documentation.d.ts
|
|
669
739
|
type Component = "positiveResponse" | "negativeResponse" | "requestParameter" | "requestBody";
|
|
670
740
|
/** @desc user defined function that creates a component description from its properties */
|
|
671
741
|
type Descriptor = (props: Record<"method" | "path" | "operationId", string> & {
|
|
672
|
-
|
|
742
|
+
statusCode?: number;
|
|
673
743
|
}) => string;
|
|
674
744
|
interface DocumentationParams {
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
745
|
+
title: string;
|
|
746
|
+
version: string;
|
|
747
|
+
serverUrl: string | [string, ...string[]];
|
|
748
|
+
routing: Routing;
|
|
749
|
+
config: CommonConfig;
|
|
750
|
+
/**
|
|
751
|
+
* @desc Descriptions of various components based on their properties (method, path, operationId).
|
|
752
|
+
* @desc When composition set to "components", component name is generated from this description
|
|
753
|
+
* @default () => `${method} ${path} ${component}`
|
|
754
|
+
* */
|
|
755
|
+
descriptions?: Partial<Record<Component, Descriptor>>;
|
|
756
|
+
/** @default true */
|
|
757
|
+
hasSummaryFromDescription?: boolean;
|
|
758
|
+
/**
|
|
759
|
+
* @desc Depict the HEAD method for each Endpoint supporting the GET method (feature of Express)
|
|
760
|
+
* @default true
|
|
761
|
+
* */
|
|
762
|
+
hasHeadMethod?: boolean;
|
|
763
|
+
/** @default inline */
|
|
764
|
+
composition?: "inline" | "components";
|
|
765
|
+
/**
|
|
766
|
+
* @desc Handling rules for your own branded schemas.
|
|
767
|
+
* @desc Keys: brands (recommended to use unique symbols).
|
|
768
|
+
* @desc Values: functions having Zod context as first argument, second one is the framework context.
|
|
769
|
+
* @example { MyBrand: ( { zodSchema, jsonSchema } ) => ({ type: "object" })
|
|
770
|
+
*/
|
|
771
|
+
brandHandling?: BrandHandling;
|
|
772
|
+
/**
|
|
773
|
+
* @desc Ability to configure recognition of headers among other input data
|
|
774
|
+
* @desc Only applicable when "headers" is present within inputSources config option
|
|
775
|
+
* @see defaultIsHeader
|
|
776
|
+
* @link https://www.iana.org/assignments/http-fields/http-fields.xhtml
|
|
777
|
+
* */
|
|
778
|
+
isHeader?: IsHeader;
|
|
779
|
+
/**
|
|
780
|
+
* @desc Extended description of tags used in endpoints. For enforcing constraints:
|
|
781
|
+
* @see TagOverrides
|
|
782
|
+
* @example { users: "About users", files: { description: "About files", url: "https://example.com" } }
|
|
783
|
+
* */
|
|
784
|
+
tags?: Parameters<typeof depictTags>[0];
|
|
715
785
|
}
|
|
716
786
|
declare class Documentation extends OpenApiBuilder {
|
|
717
|
-
|
|
718
|
-
|
|
787
|
+
#private;
|
|
788
|
+
constructor({
|
|
789
|
+
routing,
|
|
790
|
+
config,
|
|
791
|
+
title,
|
|
792
|
+
version,
|
|
793
|
+
serverUrl,
|
|
794
|
+
descriptions,
|
|
795
|
+
brandHandling,
|
|
796
|
+
tags,
|
|
797
|
+
isHeader,
|
|
798
|
+
hasSummaryFromDescription,
|
|
799
|
+
hasHeadMethod,
|
|
800
|
+
composition
|
|
801
|
+
}: DocumentationParams);
|
|
719
802
|
}
|
|
720
|
-
|
|
803
|
+
//#endregion
|
|
804
|
+
//#region src/errors.d.ts
|
|
721
805
|
/** @desc An error related to the wrong Routing declaration */
|
|
722
806
|
declare class RoutingError extends Error {
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
807
|
+
name: string;
|
|
808
|
+
readonly cause: {
|
|
809
|
+
method: Method;
|
|
810
|
+
path: string;
|
|
811
|
+
};
|
|
812
|
+
constructor(message: string, method: Method, path: string);
|
|
729
813
|
}
|
|
730
814
|
/**
|
|
731
815
|
* @desc An error related to the generating of the documentation
|
|
732
816
|
* */
|
|
733
817
|
declare class DocumentationError extends Error {
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
818
|
+
name: string;
|
|
819
|
+
readonly cause: string;
|
|
820
|
+
constructor(message: string, {
|
|
821
|
+
method,
|
|
822
|
+
path,
|
|
823
|
+
isResponse
|
|
824
|
+
}: Pick<OpenAPIContext, "path" | "method" | "isResponse">);
|
|
737
825
|
}
|
|
738
826
|
/** @desc An error related to the input and output schemas declaration */
|
|
739
827
|
declare class IOSchemaError extends Error {
|
|
740
|
-
|
|
828
|
+
name: string;
|
|
741
829
|
}
|
|
742
830
|
/** @desc An error of validating the Endpoint handler's returns against the Endpoint output schema */
|
|
743
831
|
declare class OutputValidationError extends IOSchemaError {
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
832
|
+
readonly cause: z.ZodError;
|
|
833
|
+
name: string;
|
|
834
|
+
constructor(cause: z.ZodError);
|
|
747
835
|
}
|
|
748
836
|
/** @desc An error of validating the input sources against the Middleware or Endpoint input schema */
|
|
749
837
|
declare class InputValidationError extends IOSchemaError {
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
838
|
+
readonly cause: z.ZodError;
|
|
839
|
+
name: string;
|
|
840
|
+
constructor(cause: z.ZodError);
|
|
753
841
|
}
|
|
842
|
+
/** @desc An error related to the execution or incorrect configuration of ResultHandler */
|
|
843
|
+
|
|
754
844
|
declare class MissingPeerError extends Error {
|
|
755
|
-
|
|
756
|
-
|
|
845
|
+
name: string;
|
|
846
|
+
constructor(module: string);
|
|
757
847
|
}
|
|
758
|
-
|
|
848
|
+
//#endregion
|
|
849
|
+
//#region src/testing.d.ts
|
|
759
850
|
interface TestingProps<REQ, LOG> {
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
851
|
+
/**
|
|
852
|
+
* @desc Additional properties to set on Request mock
|
|
853
|
+
* @default { method: "GET", headers: { "content-type": "application/json" } }
|
|
854
|
+
* */
|
|
855
|
+
requestProps?: REQ;
|
|
856
|
+
/**
|
|
857
|
+
* @link https://www.npmjs.com/package/node-mocks-http
|
|
858
|
+
* @default { req: requestMock }
|
|
859
|
+
* */
|
|
860
|
+
responseOptions?: ResponseOptions;
|
|
861
|
+
/**
|
|
862
|
+
* @desc Additional properties to set on config mock
|
|
863
|
+
* @default { cors: false, logger }
|
|
864
|
+
* */
|
|
865
|
+
configProps?: Partial<CommonConfig>;
|
|
866
|
+
/**
|
|
867
|
+
* @desc Additional properties to set on logger mock
|
|
868
|
+
* @default { info, warn, error, debug }
|
|
869
|
+
* */
|
|
870
|
+
loggerProps?: LOG;
|
|
780
871
|
}
|
|
781
|
-
declare const testEndpoint: <LOG extends FlatObject, REQ extends RequestOptions>({
|
|
782
|
-
|
|
783
|
-
|
|
872
|
+
declare const testEndpoint: <LOG extends FlatObject, REQ extends RequestOptions>({
|
|
873
|
+
endpoint,
|
|
874
|
+
...rest
|
|
875
|
+
}: TestingProps<REQ, LOG> & {
|
|
876
|
+
/** @desc The endpoint to test */
|
|
877
|
+
endpoint: AbstractEndpoint;
|
|
784
878
|
}) => Promise<{
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
879
|
+
requestMock: node_mocks_http0.MockRequest<Request<express_serve_static_core0.ParamsDictionary, any, any, qs0.ParsedQs, Record<string, any>> & REQ>;
|
|
880
|
+
responseMock: node_mocks_http0.MockResponse<Response<any, Record<string, any>>>;
|
|
881
|
+
loggerMock: AbstractLogger & LOG & {
|
|
882
|
+
_getLogs: () => Record<"debug" | "info" | "warn" | "error", unknown[]>;
|
|
883
|
+
};
|
|
790
884
|
}>;
|
|
791
|
-
declare const testMiddleware: <LOG extends FlatObject, REQ extends RequestOptions>({
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
885
|
+
declare const testMiddleware: <LOG extends FlatObject, REQ extends RequestOptions>({
|
|
886
|
+
middleware,
|
|
887
|
+
options,
|
|
888
|
+
...rest
|
|
889
|
+
}: TestingProps<REQ, LOG> & {
|
|
890
|
+
/** @desc The middleware to test */
|
|
891
|
+
middleware: AbstractMiddleware;
|
|
892
|
+
/** @desc The aggregated output from previously executed middlewares */
|
|
893
|
+
options?: FlatObject;
|
|
796
894
|
}) => Promise<{
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
895
|
+
requestMock: node_mocks_http0.MockRequest<Request<express_serve_static_core0.ParamsDictionary, any, any, qs0.ParsedQs, Record<string, any>> & REQ>;
|
|
896
|
+
responseMock: node_mocks_http0.MockResponse<Response<any, Record<string, any>>>;
|
|
897
|
+
loggerMock: AbstractLogger & LOG & {
|
|
898
|
+
_getLogs: () => Record<"debug" | "info" | "warn" | "error", unknown[]>;
|
|
899
|
+
};
|
|
900
|
+
output: FlatObject;
|
|
803
901
|
}>;
|
|
804
|
-
|
|
902
|
+
//#endregion
|
|
903
|
+
//#region src/integration-base.d.ts
|
|
805
904
|
declare abstract class IntegrationBase {
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
905
|
+
#private;
|
|
906
|
+
private readonly serverUrl;
|
|
907
|
+
protected constructor(serverUrl: string);
|
|
809
908
|
}
|
|
810
|
-
|
|
909
|
+
//#endregion
|
|
910
|
+
//#region src/schema-walker.d.ts
|
|
811
911
|
interface NextHandlerInc<U> {
|
|
812
|
-
|
|
912
|
+
next: (schema: z.core.$ZodType) => U;
|
|
813
913
|
}
|
|
814
914
|
interface PrevInc<U> {
|
|
815
|
-
|
|
915
|
+
prev: U;
|
|
816
916
|
}
|
|
817
|
-
type SchemaHandler<U, Context extends FlatObject = EmptyObject, Variant extends "regular" | "each" | "last" = "regular"> = (schema: any,
|
|
917
|
+
type SchemaHandler<U, Context extends FlatObject = EmptyObject, Variant extends "regular" | "each" | "last" = "regular"> = (schema: any,
|
|
918
|
+
// eslint-disable-line @typescript-eslint/no-explicit-any -- for assignment compatibility
|
|
818
919
|
ctx: Context & (Variant extends "regular" ? NextHandlerInc<U> : Variant extends "each" ? PrevInc<U> : Context)) => U;
|
|
819
920
|
type HandlingRules<U, Context extends FlatObject = EmptyObject, K extends string | symbol = string | symbol> = Partial<Record<K, SchemaHandler<U, Context>>>;
|
|
820
|
-
|
|
921
|
+
/** @since 10.1.1 calling onEach _after_ handler and giving it the previously achieved result */
|
|
922
|
+
//#endregion
|
|
923
|
+
//#region src/zts-helpers.d.ts
|
|
821
924
|
interface ZTSContext extends FlatObject {
|
|
822
|
-
|
|
823
|
-
|
|
925
|
+
isResponse: boolean;
|
|
926
|
+
makeAlias: (key: object, produce: () => ts.TypeNode) => ts.TypeNode;
|
|
824
927
|
}
|
|
825
928
|
type Producer = SchemaHandler<ts.TypeNode, ZTSContext>;
|
|
826
|
-
|
|
929
|
+
//#endregion
|
|
930
|
+
//#region src/integration.d.ts
|
|
827
931
|
interface IntegrationParams {
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
932
|
+
routing: Routing;
|
|
933
|
+
/**
|
|
934
|
+
* @desc What should be generated
|
|
935
|
+
* @example "types" — types of your endpoint requests and responses (for a DIY solution)
|
|
936
|
+
* @example "client" — an entity for performing typed requests and receiving typed responses
|
|
937
|
+
* @default "client"
|
|
938
|
+
* */
|
|
939
|
+
variant?: "types" | "client";
|
|
940
|
+
/** @default Client */
|
|
941
|
+
clientClassName?: string;
|
|
942
|
+
/** @default Subscription */
|
|
943
|
+
subscriptionClassName?: string;
|
|
944
|
+
/**
|
|
945
|
+
* @desc The API URL to use in the generated code
|
|
946
|
+
* @default https://example.com
|
|
947
|
+
* */
|
|
948
|
+
serverUrl?: string;
|
|
949
|
+
/**
|
|
950
|
+
* @desc The schema to use for responses without body such as 204
|
|
951
|
+
* @default z.undefined()
|
|
952
|
+
* */
|
|
953
|
+
noContent?: z.ZodType;
|
|
954
|
+
/**
|
|
955
|
+
* @desc Depict the HEAD method for each Endpoint supporting the GET method (feature of Express)
|
|
956
|
+
* @default true
|
|
957
|
+
* */
|
|
958
|
+
hasHeadMethod?: boolean;
|
|
959
|
+
/**
|
|
960
|
+
* @desc Handling rules for your own branded schemas.
|
|
961
|
+
* @desc Keys: brands (recommended to use unique symbols).
|
|
962
|
+
* @desc Values: functions having schema as first argument that you should assign type to, second one is a context.
|
|
963
|
+
* @example { MyBrand: ( schema: typeof myBrandSchema, { next } ) => createKeywordTypeNode(SyntaxKind.AnyKeyword)
|
|
964
|
+
*/
|
|
965
|
+
brandHandling?: HandlingRules<ts.TypeNode, ZTSContext>;
|
|
862
966
|
}
|
|
863
967
|
interface FormattedPrintingOptions {
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
968
|
+
/** @desc Typescript printer options */
|
|
969
|
+
printerOptions?: ts.PrinterOptions;
|
|
970
|
+
/**
|
|
971
|
+
* @desc Typescript code formatter
|
|
972
|
+
* @default prettier.format
|
|
973
|
+
* */
|
|
974
|
+
format?: (program: string) => Promise<string>;
|
|
871
975
|
}
|
|
872
976
|
declare class Integration extends IntegrationBase {
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
977
|
+
#private;
|
|
978
|
+
constructor({
|
|
979
|
+
routing,
|
|
980
|
+
brandHandling,
|
|
981
|
+
variant,
|
|
982
|
+
clientClassName,
|
|
983
|
+
subscriptionClassName,
|
|
984
|
+
serverUrl,
|
|
985
|
+
noContent,
|
|
986
|
+
hasHeadMethod
|
|
987
|
+
}: IntegrationParams);
|
|
988
|
+
print(printerOptions?: ts.PrinterOptions): string;
|
|
989
|
+
printFormatted({
|
|
990
|
+
printerOptions,
|
|
991
|
+
format: userDefined
|
|
992
|
+
}?: FormattedPrintingOptions): Promise<string>;
|
|
877
993
|
}
|
|
878
|
-
|
|
994
|
+
//#endregion
|
|
995
|
+
//#region src/sse.d.ts
|
|
879
996
|
type EventsMap = Record<string, z.ZodType>;
|
|
880
997
|
interface Emitter<E extends EventsMap> extends FlatObject {
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
998
|
+
/** @desc Returns true when the connection was closed or terminated */
|
|
999
|
+
isClosed: () => boolean;
|
|
1000
|
+
/** @desc Sends an event to the stream according to the declared schema */
|
|
1001
|
+
emit: <K extends keyof E>(event: K, data: z.input<E[K]>) => void;
|
|
885
1002
|
}
|
|
886
1003
|
declare class EventStreamFactory<E extends EventsMap> extends EndpointsFactory<undefined, Emitter<E>> {
|
|
887
|
-
|
|
1004
|
+
constructor(events: E);
|
|
888
1005
|
}
|
|
889
|
-
|
|
1006
|
+
//#endregion
|
|
1007
|
+
//#region src/raw-schema.d.ts
|
|
890
1008
|
declare const base: z.ZodObject<{
|
|
891
|
-
|
|
1009
|
+
raw: z.core.$ZodBranded<z.ZodCustom<Buffer<ArrayBufferLike>, Buffer<ArrayBufferLike>>, symbol>;
|
|
892
1010
|
}, z.core.$strip>;
|
|
893
1011
|
type Base = ReturnType<typeof base.brand<symbol>>;
|
|
894
1012
|
declare const extended: <S extends z.core.$ZodShape>(extra: S) => z.core.$ZodBranded<z.ZodObject<("raw" & keyof S extends never ? {
|
|
895
|
-
|
|
1013
|
+
raw: z.core.$ZodBranded<z.ZodCustom<Buffer<ArrayBufferLike>, Buffer<ArrayBufferLike>>, symbol>;
|
|
896
1014
|
} & S : ({
|
|
897
|
-
|
|
898
|
-
} extends infer T_1 extends z.core.util.SomeObject ? { [K in keyof T_1 as K extends keyof S ? never : K]: T_1[K]
|
|
1015
|
+
raw: z.core.$ZodBranded<z.ZodCustom<Buffer<ArrayBufferLike>, Buffer<ArrayBufferLike>>, symbol>;
|
|
1016
|
+
} extends infer T_1 extends z.core.util.SomeObject ? { [K in keyof T_1 as K extends keyof S ? never : K]: T_1[K] } : never) & { [K_1 in keyof S]: S[K_1] }) extends infer T ? { [k in keyof T]: T[k] } : never, z.core.$strip>, symbol>;
|
|
899
1017
|
declare function raw(): Base;
|
|
900
1018
|
declare function raw<S extends z.core.$ZodShape>(extra: S): ReturnType<typeof extended<S>>;
|
|
901
|
-
|
|
1019
|
+
//#endregion
|
|
1020
|
+
//#region src/proprietary-schemas.d.ts
|
|
902
1021
|
declare const ez: {
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
1022
|
+
dateIn: ({
|
|
1023
|
+
examples,
|
|
1024
|
+
...rest
|
|
1025
|
+
}?: Parameters<zod0.ZodString["meta"]>[0]) => zod_v4_core0.$ZodBranded<zod0.ZodPipe<zod0.ZodPipe<zod0.ZodUnion<readonly [zod0.ZodISODate, zod0.ZodISODateTime, zod0.ZodISODateTime]>, zod0.ZodTransform<Date, string>>, zod0.ZodDate>, symbol>;
|
|
1026
|
+
dateOut: (meta?: Parameters<zod0.ZodString["meta"]>[0]) => zod_v4_core0.$ZodBranded<zod0.ZodPipe<zod0.ZodDate, zod0.ZodTransform<string, Date>>, symbol>;
|
|
1027
|
+
form: <S extends zod_v4_core0.$ZodShape>(base: S | zod0.ZodObject<S>) => zod_v4_core0.$ZodBranded<zod0.ZodObject<S, zod_v4_core0.$strip>, symbol>;
|
|
1028
|
+
upload: () => zod_v4_core0.$ZodBranded<zod0.ZodCustom<express_fileupload0.UploadedFile, express_fileupload0.UploadedFile>, symbol>;
|
|
1029
|
+
raw: typeof raw;
|
|
1030
|
+
buffer: () => zod_v4_core0.$ZodBranded<zod0.ZodCustom<Buffer<ArrayBufferLike>, Buffer<ArrayBufferLike>>, symbol>;
|
|
909
1031
|
};
|
|
910
|
-
|
|
911
|
-
export { type ApiResponse, type AppConfig, type BasicSecurity, type BearerSecurity, BuiltinLogger, type CommonConfig, type CookieSecurity, DependsOnMethod, type Depicter, Documentation, DocumentationError, EndpointsFactory, EventStreamFactory, type FlatObject, type HeaderSecurity, type IOSchema, type InputSecurity, InputValidationError, Integration, type LoggerOverrides, type Method, Middleware, MissingPeerError, type OAuth2Security, type OpenIdSecurity, OutputValidationError, type Producer, ResultHandler, type Routing, RoutingError, ServeStatic, type ServerConfig, type TagOverrides, arrayEndpointsFactory, arrayResultHandler, attachRouting, createConfig, createServer, defaultEndpointsFactory, defaultResultHandler, ensureHttpError, ez, getMessageFromError, testEndpoint, testMiddleware };
|
|
1032
|
+
//#endregion
|
|
1033
|
+
export { type ApiResponse, type AppConfig, type BasicSecurity, type BearerSecurity, BuiltinLogger, type CommonConfig, type CookieSecurity, DependsOnMethod, type Depicter, Documentation, DocumentationError, EndpointsFactory, EventStreamFactory, type FlatObject, type HeaderSecurity, type IOSchema, type InputSecurity, InputValidationError, Integration, type LoggerOverrides, type Method, Middleware, MissingPeerError, type OAuth2Security, type OpenIdSecurity, OutputValidationError, type Producer, ResultHandler, type Routing, RoutingError, ServeStatic, type ServerConfig, type TagOverrides, arrayEndpointsFactory, arrayResultHandler, attachRouting, createConfig, createServer, defaultEndpointsFactory, defaultResultHandler, ensureHttpError, ez, getMessageFromError, testEndpoint, testMiddleware };
|