express-zod-api 25.5.3 → 26.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +43 -0
- package/README.md +88 -98
- package/dist/index.d.ts +112 -105
- package/dist/index.js +6 -6
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -15,8 +15,8 @@ import compression from "compression";
|
|
|
15
15
|
import * as express_fileupload0 from "express-fileupload";
|
|
16
16
|
import fileUpload from "express-fileupload";
|
|
17
17
|
import { ListenOptions } from "node:net";
|
|
18
|
-
import * as
|
|
19
|
-
import * as
|
|
18
|
+
import * as express_serve_static_core0 from "express-serve-static-core";
|
|
19
|
+
import * as qs0 from "qs";
|
|
20
20
|
import * as zod_v4_core0 from "zod/v4/core";
|
|
21
21
|
|
|
22
22
|
//#region src/method.d.ts
|
|
@@ -37,8 +37,8 @@ type ClientMethod = (typeof clientMethods)[number];
|
|
|
37
37
|
//#endregion
|
|
38
38
|
//#region src/api-response.d.ts
|
|
39
39
|
/** @public this is the user facing configuration */
|
|
40
|
-
interface ApiResponse<S extends z.ZodType> {
|
|
41
|
-
schema: S;
|
|
40
|
+
interface ApiResponse<S$1 extends z.ZodType> {
|
|
41
|
+
schema: S$1;
|
|
42
42
|
/** @default 200 for a positive and 400 for a negative response */
|
|
43
43
|
statusCode?: number | [number, ...number[]];
|
|
44
44
|
/**
|
|
@@ -56,7 +56,7 @@ type EmptySchema = typeof emptySchema;
|
|
|
56
56
|
type EmptyObject = z.output<EmptySchema>;
|
|
57
57
|
type FlatObject = Record<string, unknown>;
|
|
58
58
|
/** @link https://stackoverflow.com/a/65492934 */
|
|
59
|
-
type NoNever<T, F> = [T] extends [never] ? F : T;
|
|
59
|
+
type NoNever<T$1, F> = [T$1] extends [never] ? F : T$1;
|
|
60
60
|
/**
|
|
61
61
|
* @desc Using module augmentation approach you can specify tags as the keys of this interface
|
|
62
62
|
* @example declare module "express-zod-api" { interface TagOverrides { users: unknown } }
|
|
@@ -85,7 +85,7 @@ interface LoggerOverrides {}
|
|
|
85
85
|
type ActualLogger = AbstractLogger & LoggerOverrides;
|
|
86
86
|
//#endregion
|
|
87
87
|
//#region src/builtin-logger.d.ts
|
|
88
|
-
interface Context
|
|
88
|
+
interface Context extends FlatObject {
|
|
89
89
|
requestId?: string;
|
|
90
90
|
}
|
|
91
91
|
interface BuiltinLoggerConfig {
|
|
@@ -106,7 +106,7 @@ interface BuiltinLoggerConfig {
|
|
|
106
106
|
* @desc Context: the metadata applicable for each logged entry, used by .child() method
|
|
107
107
|
* @see childLoggerProvider
|
|
108
108
|
* */
|
|
109
|
-
ctx: Context
|
|
109
|
+
ctx: Context;
|
|
110
110
|
}
|
|
111
111
|
interface ProfilerOptions {
|
|
112
112
|
message: string;
|
|
@@ -131,12 +131,12 @@ declare class BuiltinLogger implements AbstractLogger {
|
|
|
131
131
|
info(message: string, meta?: unknown): void;
|
|
132
132
|
warn(message: string, meta?: unknown): void;
|
|
133
133
|
error(message: string, meta?: unknown): void;
|
|
134
|
-
child(ctx: Context
|
|
134
|
+
child(ctx: Context): BuiltinLogger;
|
|
135
135
|
/**
|
|
136
136
|
* @desc The argument used for instance created by .child() method
|
|
137
137
|
* @see ChildLoggerProvider
|
|
138
138
|
* */
|
|
139
|
-
get ctx(): Context
|
|
139
|
+
get ctx(): Context;
|
|
140
140
|
/** @desc Measures the duration until you invoke the returned callback */
|
|
141
141
|
profile(message: string): () => void;
|
|
142
142
|
profile(options: ProfilerOptions): () => void;
|
|
@@ -154,13 +154,13 @@ type Extension<Current extends IOSchema | undefined, Inc extends IOSchema | unde
|
|
|
154
154
|
type FinalInputSchema<FIN extends IOSchema | undefined, BIN extends IOSchema> = z.ZodIntersection<FIN extends IOSchema ? FIN : BIN, BIN>;
|
|
155
155
|
//#endregion
|
|
156
156
|
//#region src/logical-container.d.ts
|
|
157
|
-
type LogicalOr<T> = {
|
|
158
|
-
or: T[];
|
|
157
|
+
type LogicalOr<T$1> = {
|
|
158
|
+
or: T$1[];
|
|
159
159
|
};
|
|
160
|
-
type LogicalAnd<T> = {
|
|
161
|
-
and: T[];
|
|
160
|
+
type LogicalAnd<T$1> = {
|
|
161
|
+
and: T$1[];
|
|
162
162
|
};
|
|
163
|
-
type LogicalContainer<T> = LogicalOr<T | LogicalAnd<T>> | LogicalAnd<T | LogicalOr<T>> | T;
|
|
163
|
+
type LogicalContainer<T$1> = LogicalOr<T$1 | LogicalAnd<T$1>> | LogicalAnd<T$1 | LogicalOr<T$1>> | T$1;
|
|
164
164
|
//#endregion
|
|
165
165
|
//#region src/security.d.ts
|
|
166
166
|
interface BasicSecurity {
|
|
@@ -170,9 +170,9 @@ interface BearerSecurity {
|
|
|
170
170
|
type: "bearer";
|
|
171
171
|
format?: "JWT" | string;
|
|
172
172
|
}
|
|
173
|
-
interface InputSecurity<K extends string> {
|
|
173
|
+
interface InputSecurity<K$1 extends string> {
|
|
174
174
|
type: "input";
|
|
175
|
-
name: K;
|
|
175
|
+
name: K$1;
|
|
176
176
|
}
|
|
177
177
|
interface HeaderSecurity {
|
|
178
178
|
type: "header";
|
|
@@ -205,28 +205,28 @@ interface RefreshUrl {
|
|
|
205
205
|
/** @desc The URL to be used for obtaining refresh tokens. Can be relative to the API server URL. */
|
|
206
206
|
refreshUrl?: string;
|
|
207
207
|
}
|
|
208
|
-
interface Scopes<K extends string> {
|
|
208
|
+
interface Scopes<K$1 extends string> {
|
|
209
209
|
/** @desc The available scopes for the OAuth2 security and their short descriptions. Optional. */
|
|
210
|
-
scopes?: Record<K, string>;
|
|
210
|
+
scopes?: Record<K$1, string>;
|
|
211
211
|
}
|
|
212
|
-
type AuthCodeFlow<S extends string> = AuthUrl & TokenUrl & RefreshUrl & Scopes<S>;
|
|
213
|
-
type ImplicitFlow<S extends string> = AuthUrl & RefreshUrl & Scopes<S>;
|
|
214
|
-
type PasswordFlow<S extends string> = TokenUrl & RefreshUrl & Scopes<S>;
|
|
215
|
-
type ClientCredFlow<S extends string> = TokenUrl & RefreshUrl & Scopes<S>;
|
|
212
|
+
type AuthCodeFlow<S$1 extends string> = AuthUrl & TokenUrl & RefreshUrl & Scopes<S$1>;
|
|
213
|
+
type ImplicitFlow<S$1 extends string> = AuthUrl & RefreshUrl & Scopes<S$1>;
|
|
214
|
+
type PasswordFlow<S$1 extends string> = TokenUrl & RefreshUrl & Scopes<S$1>;
|
|
215
|
+
type ClientCredFlow<S$1 extends string> = TokenUrl & RefreshUrl & Scopes<S$1>;
|
|
216
216
|
/**
|
|
217
217
|
* @see https://swagger.io/docs/specification/authentication/oauth2/
|
|
218
218
|
*/
|
|
219
|
-
interface OAuth2Security<S extends string> {
|
|
219
|
+
interface OAuth2Security<S$1 extends string> {
|
|
220
220
|
type: "oauth2";
|
|
221
221
|
flows?: {
|
|
222
222
|
/** @desc Authorization Code flow (previously called accessCode in OpenAPI 2.0) */
|
|
223
|
-
authorizationCode?: AuthCodeFlow<S>;
|
|
223
|
+
authorizationCode?: AuthCodeFlow<S$1>;
|
|
224
224
|
/** @desc Implicit flow */
|
|
225
|
-
implicit?: ImplicitFlow<S>;
|
|
225
|
+
implicit?: ImplicitFlow<S$1>;
|
|
226
226
|
/** @desc Resource Owner Password flow */
|
|
227
|
-
password?: PasswordFlow<S>;
|
|
227
|
+
password?: PasswordFlow<S$1>;
|
|
228
228
|
/** @desc Client Credentials flow (previously called application in OpenAPI 2.0) */
|
|
229
|
-
clientCredentials?: ClientCredFlow<S>;
|
|
229
|
+
clientCredentials?: ClientCredFlow<S$1>;
|
|
230
230
|
};
|
|
231
231
|
}
|
|
232
232
|
/**
|
|
@@ -234,34 +234,34 @@ interface OAuth2Security<S extends string> {
|
|
|
234
234
|
* @param K is an optional input field used by InputSecurity
|
|
235
235
|
* @param S is an optional union of scopes used by OAuth2Security
|
|
236
236
|
* */
|
|
237
|
-
type Security<K extends string = string, S extends string = string> = BasicSecurity | BearerSecurity | InputSecurity<K> | HeaderSecurity | CookieSecurity | OpenIdSecurity | OAuth2Security<S>;
|
|
237
|
+
type Security<K$1 extends string = string, S$1 extends string = string> = BasicSecurity | BearerSecurity | InputSecurity<K$1> | HeaderSecurity | CookieSecurity | OpenIdSecurity | OAuth2Security<S$1>;
|
|
238
238
|
//#endregion
|
|
239
239
|
//#region src/middleware.d.ts
|
|
240
|
-
type Handler$2<IN,
|
|
240
|
+
type Handler$2<IN, CTX, RET> = (params: {
|
|
241
241
|
/** @desc The inputs from the enabled input sources validated against the input schema of the Middleware */
|
|
242
242
|
input: IN;
|
|
243
243
|
/**
|
|
244
244
|
* @desc The returns of the previously executed Middlewares (typed when chaining Middlewares)
|
|
245
245
|
* @link https://github.com/RobinTail/express-zod-api/discussions/1250
|
|
246
246
|
* */
|
|
247
|
-
|
|
247
|
+
ctx: CTX;
|
|
248
248
|
/** @link https://expressjs.com/en/5x/api.html#req */
|
|
249
249
|
request: Request;
|
|
250
250
|
/** @link https://expressjs.com/en/5x/api.html#res */
|
|
251
251
|
response: Response;
|
|
252
252
|
/** @desc The instance of the configured logger */
|
|
253
253
|
logger: ActualLogger;
|
|
254
|
-
}) => Promise<
|
|
254
|
+
}) => Promise<RET>;
|
|
255
255
|
declare abstract class AbstractMiddleware {
|
|
256
256
|
abstract execute(params: {
|
|
257
257
|
input: unknown;
|
|
258
|
-
|
|
258
|
+
ctx: FlatObject;
|
|
259
259
|
request: Request;
|
|
260
260
|
response: Response;
|
|
261
261
|
logger: ActualLogger;
|
|
262
262
|
}): Promise<FlatObject>;
|
|
263
263
|
}
|
|
264
|
-
declare class Middleware<
|
|
264
|
+
declare class Middleware<CTX extends FlatObject, RET extends FlatObject, SCO extends string, IN extends IOSchema | undefined = undefined> extends AbstractMiddleware {
|
|
265
265
|
#private;
|
|
266
266
|
constructor({
|
|
267
267
|
input,
|
|
@@ -276,8 +276,8 @@ declare class Middleware<OPT extends FlatObject, OUT extends FlatObject, SCO ext
|
|
|
276
276
|
input?: IN;
|
|
277
277
|
/** @desc Declaration of the security schemas implemented within the handler */
|
|
278
278
|
security?: LogicalContainer<Security<Extract<keyof z.input<IN>, string>, SCO>>;
|
|
279
|
-
/** @desc The handler returning
|
|
280
|
-
handler: Handler$2<z.output<IN>,
|
|
279
|
+
/** @desc The handler returning a context available to Endpoints */
|
|
280
|
+
handler: Handler$2<z.output<IN>, CTX, RET>;
|
|
281
281
|
});
|
|
282
282
|
/** @throws InputValidationError */
|
|
283
283
|
execute({
|
|
@@ -285,36 +285,22 @@ declare class Middleware<OPT extends FlatObject, OUT extends FlatObject, SCO ext
|
|
|
285
285
|
...rest
|
|
286
286
|
}: {
|
|
287
287
|
input: unknown;
|
|
288
|
-
|
|
288
|
+
ctx: CTX;
|
|
289
289
|
request: Request;
|
|
290
290
|
response: Response;
|
|
291
291
|
logger: ActualLogger;
|
|
292
|
-
}): Promise<
|
|
292
|
+
}): Promise<RET>;
|
|
293
293
|
}
|
|
294
|
-
declare class ExpressMiddleware<R extends Request, S extends Response,
|
|
295
|
-
constructor(nativeMw: (request: R, response: S, next: NextFunction) => any, {
|
|
294
|
+
declare class ExpressMiddleware<R extends Request, S$1 extends Response, RET extends FlatObject> extends Middleware<FlatObject, RET, string> {
|
|
295
|
+
constructor(nativeMw: (request: R, response: S$1, next: NextFunction) => any, {
|
|
296
296
|
provider,
|
|
297
297
|
transformer
|
|
298
298
|
}?: {
|
|
299
|
-
provider?: (request: R, response: S) =>
|
|
299
|
+
provider?: (request: R, response: S$1) => RET | Promise<RET>;
|
|
300
300
|
transformer?: (err: Error) => Error;
|
|
301
301
|
});
|
|
302
302
|
}
|
|
303
303
|
//#endregion
|
|
304
|
-
//#region src/depends-on-method.d.ts
|
|
305
|
-
declare class DependsOnMethod extends Routable {
|
|
306
|
-
#private;
|
|
307
|
-
constructor(endpoints: Partial<Record<Method, AbstractEndpoint>>);
|
|
308
|
-
deprecated(): this;
|
|
309
|
-
}
|
|
310
|
-
//#endregion
|
|
311
|
-
//#region src/serve-static.d.ts
|
|
312
|
-
type OriginalStatic = typeof express.static;
|
|
313
|
-
declare class ServeStatic {
|
|
314
|
-
#private;
|
|
315
|
-
constructor(...params: Parameters<OriginalStatic>);
|
|
316
|
-
}
|
|
317
|
-
//#endregion
|
|
318
304
|
//#region src/result-helpers.d.ts
|
|
319
305
|
type ResultSchema<R extends Result> = R extends Result<infer S> ? S : never;
|
|
320
306
|
type DiscriminatedResult = {
|
|
@@ -335,12 +321,12 @@ type Handler$1<RES = unknown> = (params: DiscriminatedResult & {
|
|
|
335
321
|
/** null in case of failure to parse or to find the matching endpoint (error: not found) */
|
|
336
322
|
input: FlatObject | null;
|
|
337
323
|
/** can be empty: check presence of the required property using "in" operator */
|
|
338
|
-
|
|
324
|
+
ctx: FlatObject;
|
|
339
325
|
request: Request;
|
|
340
326
|
response: Response<RES>;
|
|
341
327
|
logger: ActualLogger;
|
|
342
328
|
}) => void | Promise<void>;
|
|
343
|
-
type Result<S extends z.ZodType = z.ZodType> = S | ApiResponse<S> | ApiResponse<S>[];
|
|
329
|
+
type Result<S$1 extends z.ZodType = z.ZodType> = S$1 | ApiResponse<S$1> | ApiResponse<S$1>[];
|
|
344
330
|
type LazyResult<R extends Result, A extends unknown[] = []> = (...args: A) => R;
|
|
345
331
|
declare abstract class AbstractResultHandler {
|
|
346
332
|
#private;
|
|
@@ -377,6 +363,13 @@ declare const arrayResultHandler: ResultHandler<z.ZodArray<z.core.$ZodType<unkno
|
|
|
377
363
|
mimeType: string;
|
|
378
364
|
}>;
|
|
379
365
|
//#endregion
|
|
366
|
+
//#region src/serve-static.d.ts
|
|
367
|
+
type OriginalStatic = typeof express.static;
|
|
368
|
+
declare class ServeStatic {
|
|
369
|
+
#private;
|
|
370
|
+
constructor(...params: Parameters<OriginalStatic>);
|
|
371
|
+
}
|
|
372
|
+
//#endregion
|
|
380
373
|
//#region src/server-helpers.d.ts
|
|
381
374
|
/** @desc Returns child logger for the given request (if configured) or the configured logger otherwise */
|
|
382
375
|
type GetLogger = (request?: Request) => ActualLogger;
|
|
@@ -387,29 +380,27 @@ type GetLogger = (request?: Request) => ActualLogger;
|
|
|
387
380
|
* @example { "v1/books/:bookId": getBookEndpoint }
|
|
388
381
|
* @example { "get /v1/books/:bookId": getBookEndpoint }
|
|
389
382
|
* @example { v1: { "patch /books/:bookId": changeBookEndpoint } }
|
|
383
|
+
* @example { dependsOnMethod: { get: retrieveEndpoint, post: createEndpoint } }
|
|
384
|
+
* @see CommonConfig.methodLikeRouteBehavior
|
|
390
385
|
* */
|
|
391
386
|
interface Routing {
|
|
392
|
-
[K: string]: Routing |
|
|
393
|
-
}
|
|
394
|
-
//#endregion
|
|
395
|
-
//#region src/routable.d.ts
|
|
396
|
-
declare abstract class Routable {
|
|
397
|
-
/** @desc Marks the route as deprecated (makes a copy of the endpoint) */
|
|
398
|
-
abstract deprecated(): this;
|
|
399
|
-
/** @desc Enables nested routes within the path assigned to the subject */
|
|
400
|
-
nest(routing: Routing): Routing;
|
|
387
|
+
[K: string]: Routing | AbstractEndpoint | ServeStatic;
|
|
401
388
|
}
|
|
402
389
|
//#endregion
|
|
403
390
|
//#region src/endpoint.d.ts
|
|
404
|
-
type Handler<IN, OUT,
|
|
391
|
+
type Handler<IN, OUT, CTX> = (params: {
|
|
405
392
|
/** @desc The inputs from the enabled input sources validated against the final input schema (incl. Middlewares) */
|
|
406
393
|
input: IN;
|
|
407
394
|
/** @desc The returns of the assigned Middlewares */
|
|
408
|
-
|
|
395
|
+
ctx: CTX;
|
|
409
396
|
/** @desc The instance of the configured logger */
|
|
410
397
|
logger: ActualLogger;
|
|
411
398
|
}) => Promise<OUT>;
|
|
412
|
-
declare abstract class AbstractEndpoint
|
|
399
|
+
declare abstract class AbstractEndpoint {
|
|
400
|
+
/** @desc Enables nested routes within the path assigned to the subject */
|
|
401
|
+
nest(routing: Routing): Routing;
|
|
402
|
+
/** @desc Marks the route as deprecated (makes a copy of the endpoint) */
|
|
403
|
+
abstract deprecated(): this;
|
|
413
404
|
abstract execute(params: {
|
|
414
405
|
request: Request;
|
|
415
406
|
response: Response;
|
|
@@ -417,14 +408,14 @@ declare abstract class AbstractEndpoint extends Routable {
|
|
|
417
408
|
config: CommonConfig;
|
|
418
409
|
}): Promise<void>;
|
|
419
410
|
}
|
|
420
|
-
declare class Endpoint<IN extends IOSchema, OUT extends IOSchema,
|
|
411
|
+
declare class Endpoint<IN extends IOSchema, OUT extends IOSchema, CTX extends FlatObject> extends AbstractEndpoint {
|
|
421
412
|
#private;
|
|
422
413
|
constructor(def: {
|
|
423
414
|
deprecated?: boolean;
|
|
424
415
|
middlewares?: AbstractMiddleware[];
|
|
425
416
|
inputSchema: IN;
|
|
426
417
|
outputSchema: OUT;
|
|
427
|
-
handler: Handler<z.output<IN>, z.input<OUT>,
|
|
418
|
+
handler: Handler<z.output<IN>, z.input<OUT>, CTX>;
|
|
428
419
|
resultHandler: AbstractResultHandler;
|
|
429
420
|
description?: string;
|
|
430
421
|
shortDescription?: string;
|
|
@@ -477,6 +468,14 @@ interface CommonConfig {
|
|
|
477
468
|
* @default 405
|
|
478
469
|
* */
|
|
479
470
|
wrongMethodBehavior?: 404 | 405;
|
|
471
|
+
/**
|
|
472
|
+
* @desc How to treat Routing keys that look like methods (when assigned with an Endpoint)
|
|
473
|
+
* @see Method
|
|
474
|
+
* @example "method" — the key is treated as method of its parent path
|
|
475
|
+
* @example "path" — the key is treated as a nested path segment
|
|
476
|
+
* @default "method"
|
|
477
|
+
* */
|
|
478
|
+
methodLikeRouteBehavior?: "method" | "path";
|
|
480
479
|
/**
|
|
481
480
|
* @desc The ResultHandler to use for handling routing, parsing and upload errors
|
|
482
481
|
* @default defaultResultHandler
|
|
@@ -547,7 +546,7 @@ interface GracefulOptions {
|
|
|
547
546
|
/** @desc The hook to call after the server was closed, but before terminating the process. */
|
|
548
547
|
beforeExit?: () => void | Promise<void>;
|
|
549
548
|
}
|
|
550
|
-
type
|
|
549
|
+
type ServerHook = (params: {
|
|
551
550
|
app: IRouter;
|
|
552
551
|
/** @desc Returns child logger for the given request (if configured) or the configured logger otherwise */
|
|
553
552
|
getLogger: GetLogger;
|
|
@@ -608,7 +607,12 @@ interface ServerConfig extends CommonConfig {
|
|
|
608
607
|
* @desc It can help to avoid making a DIY solution based on the attachRouting() approach.
|
|
609
608
|
* @example ({ app }) => { app.use('/docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument)); }
|
|
610
609
|
* */
|
|
611
|
-
beforeRouting?:
|
|
610
|
+
beforeRouting?: ServerHook;
|
|
611
|
+
/**
|
|
612
|
+
* @desc A code to execute after processing the Routing of your API, but before error handling.
|
|
613
|
+
* @see beforeRouting
|
|
614
|
+
* */
|
|
615
|
+
afterRouting?: ServerHook;
|
|
612
616
|
/**
|
|
613
617
|
* @desc Rejects new connections and attempts to finish ongoing ones in the specified time before exit.
|
|
614
618
|
* */
|
|
@@ -622,7 +626,7 @@ declare function createConfig(config: ServerConfig): ServerConfig;
|
|
|
622
626
|
declare function createConfig(config: AppConfig): AppConfig;
|
|
623
627
|
//#endregion
|
|
624
628
|
//#region src/endpoints-factory.d.ts
|
|
625
|
-
interface BuildProps<IN extends IOSchema, OUT extends IOSchema | z.ZodVoid, MIN extends IOSchema | undefined,
|
|
629
|
+
interface BuildProps<IN extends IOSchema, OUT extends IOSchema | z.ZodVoid, MIN extends IOSchema | undefined, CTX extends FlatObject, SCO extends string> {
|
|
626
630
|
/**
|
|
627
631
|
* @desc Input schema of the Endpoint, combining properties from all the enabled input sources (path params, headers)
|
|
628
632
|
* @default z.object({})
|
|
@@ -631,8 +635,8 @@ interface BuildProps<IN extends IOSchema, OUT extends IOSchema | z.ZodVoid, MIN
|
|
|
631
635
|
input?: IN;
|
|
632
636
|
/** @desc The schema by which the returns of the Endpoint handler is validated */
|
|
633
637
|
output: OUT;
|
|
634
|
-
/** @desc The Endpoint handler receiving the validated inputs, returns of added Middlewares (
|
|
635
|
-
handler: Handler<z.output<FinalInputSchema<MIN, IN>>, z.input<OUT>,
|
|
638
|
+
/** @desc The Endpoint handler receiving the validated inputs, returns of added Middlewares (ctx) and a logger */
|
|
639
|
+
handler: Handler<z.output<FinalInputSchema<MIN, IN>>, z.input<OUT>, CTX>;
|
|
636
640
|
/** @desc The operation description for the generated Documentation */
|
|
637
641
|
description?: string;
|
|
638
642
|
/** @desc The operation summary for the generated Documentation (50 symbols max) */
|
|
@@ -641,8 +645,7 @@ interface BuildProps<IN extends IOSchema, OUT extends IOSchema | z.ZodVoid, MIN
|
|
|
641
645
|
operationId?: string | ((method: ClientMethod) => string);
|
|
642
646
|
/**
|
|
643
647
|
* @desc HTTP method(s) this endpoint can handle
|
|
644
|
-
* @default "get" unless
|
|
645
|
-
* @see DependsOnMethod
|
|
648
|
+
* @default "get" unless method is explicitly defined in Routing keys
|
|
646
649
|
* */
|
|
647
650
|
method?: Method | [Method, ...Method[]];
|
|
648
651
|
/**
|
|
@@ -658,19 +661,19 @@ interface BuildProps<IN extends IOSchema, OUT extends IOSchema | z.ZodVoid, MIN
|
|
|
658
661
|
/** @desc Marks the operation deprecated in the generated Documentation */
|
|
659
662
|
deprecated?: boolean;
|
|
660
663
|
}
|
|
661
|
-
declare class EndpointsFactory<IN extends IOSchema | undefined = undefined,
|
|
664
|
+
declare class EndpointsFactory<IN extends IOSchema | undefined = undefined, CTX extends FlatObject = EmptyObject, SCO extends string = string> {
|
|
662
665
|
#private;
|
|
663
666
|
protected resultHandler: AbstractResultHandler;
|
|
664
667
|
protected schema: IN;
|
|
665
668
|
protected middlewares: AbstractMiddleware[];
|
|
666
669
|
constructor(resultHandler: AbstractResultHandler);
|
|
667
|
-
addMiddleware<
|
|
668
|
-
use: <R extends Request, S extends Response, AOUT extends FlatObject = Record<string, never>>(nativeMw: (request: R, response: S, next: express0.NextFunction) => any, params_1?: {
|
|
669
|
-
provider?: ((request: R, response: S) => AOUT | Promise<AOUT>) | undefined;
|
|
670
|
+
addMiddleware<RET extends FlatObject, ASCO extends string, AIN extends IOSchema | undefined = undefined>(subject: Middleware<CTX, RET, ASCO, AIN> | ConstructorParameters<typeof Middleware<CTX, RET, ASCO, AIN>>[0]): EndpointsFactory<Extension<IN, AIN>, CTX & RET, SCO & ASCO>;
|
|
671
|
+
use: <R extends Request, S$1 extends Response, AOUT extends FlatObject = Record<string, never>>(nativeMw: (request: R, response: S$1, next: express0.NextFunction) => any, params_1?: {
|
|
672
|
+
provider?: ((request: R, response: S$1) => AOUT | Promise<AOUT>) | undefined;
|
|
670
673
|
transformer?: (err: Error) => Error;
|
|
671
|
-
} | undefined) => EndpointsFactory<Extension<IN, undefined>,
|
|
672
|
-
addExpressMiddleware<R extends Request, S extends Response, AOUT extends FlatObject = EmptyObject>(...params: ConstructorParameters<typeof ExpressMiddleware<R, S, AOUT>>): EndpointsFactory<Extension<IN, undefined>,
|
|
673
|
-
|
|
674
|
+
} | undefined) => EndpointsFactory<Extension<IN, undefined>, CTX & AOUT, SCO>;
|
|
675
|
+
addExpressMiddleware<R extends Request, S$1 extends Response, AOUT extends FlatObject = EmptyObject>(...params: ConstructorParameters<typeof ExpressMiddleware<R, S$1, AOUT>>): EndpointsFactory<Extension<IN, undefined>, CTX & AOUT, SCO>;
|
|
676
|
+
addContext<RET extends FlatObject>(getContext: () => Promise<RET>): EndpointsFactory<Extension<IN, undefined>, CTX & RET, SCO>;
|
|
674
677
|
build<BOUT extends IOSchema, BIN extends IOSchema = EmptySchema>({
|
|
675
678
|
input,
|
|
676
679
|
output: outputSchema,
|
|
@@ -679,12 +682,12 @@ declare class EndpointsFactory<IN extends IOSchema | undefined = undefined, OUT
|
|
|
679
682
|
tag,
|
|
680
683
|
method,
|
|
681
684
|
...rest
|
|
682
|
-
}: BuildProps<BIN, BOUT, IN,
|
|
685
|
+
}: BuildProps<BIN, BOUT, IN, CTX, SCO>): Endpoint<FinalInputSchema<IN, BIN>, BOUT, CTX>;
|
|
683
686
|
/** @desc shorthand for returning {} while having output schema z.object({}) */
|
|
684
687
|
buildVoid<BIN extends IOSchema = EmptySchema>({
|
|
685
688
|
handler,
|
|
686
689
|
...rest
|
|
687
|
-
}: Omit<BuildProps<BIN, z.ZodVoid, IN,
|
|
690
|
+
}: Omit<BuildProps<BIN, z.ZodVoid, IN, CTX, SCO>, "output">): Endpoint<FinalInputSchema<IN, BIN>, z.ZodObject<{}, z.core.$strip>, CTX>;
|
|
688
691
|
}
|
|
689
692
|
declare const defaultEndpointsFactory: EndpointsFactory<undefined, Record<string, never>, string>;
|
|
690
693
|
/**
|
|
@@ -696,11 +699,11 @@ declare const arrayEndpointsFactory: EndpointsFactory<undefined, Record<string,
|
|
|
696
699
|
//#endregion
|
|
697
700
|
//#region src/server.d.ts
|
|
698
701
|
declare const attachRouting: (config: AppConfig, routing: Routing) => {
|
|
699
|
-
notFoundHandler: express.RequestHandler<
|
|
702
|
+
notFoundHandler: express.RequestHandler<express_serve_static_core0.ParamsDictionary, any, any, qs0.ParsedQs, Record<string, any>>;
|
|
700
703
|
logger: AbstractLogger | BuiltinLogger;
|
|
701
704
|
};
|
|
702
705
|
declare const createServer: (config: ServerConfig, routing: Routing) => Promise<{
|
|
703
|
-
app:
|
|
706
|
+
app: express_serve_static_core0.Express;
|
|
704
707
|
logger: AbstractLogger | BuiltinLogger;
|
|
705
708
|
servers: (http.Server<typeof http.IncomingMessage, typeof http.ServerResponse> | https.Server<typeof http.IncomingMessage, typeof http.ServerResponse>)[];
|
|
706
709
|
}>;
|
|
@@ -749,6 +752,7 @@ interface DocumentationParams {
|
|
|
749
752
|
/**
|
|
750
753
|
* @desc Depict the HEAD method for each Endpoint supporting the GET method (feature of Express)
|
|
751
754
|
* @default true
|
|
755
|
+
* @todo move to config
|
|
752
756
|
* */
|
|
753
757
|
hasHeadMethod?: boolean;
|
|
754
758
|
/** @default inline */
|
|
@@ -865,26 +869,26 @@ declare const testEndpoint: <LOG extends FlatObject, REQ extends RequestOptions>
|
|
|
865
869
|
/** @desc The endpoint to test */
|
|
866
870
|
endpoint: AbstractEndpoint;
|
|
867
871
|
}) => Promise<{
|
|
868
|
-
requestMock: node_mocks_http0.MockRequest<Request<
|
|
872
|
+
requestMock: node_mocks_http0.MockRequest<Request<express_serve_static_core0.ParamsDictionary, any, any, qs0.ParsedQs, Record<string, any>> & REQ>;
|
|
869
873
|
responseMock: node_mocks_http0.MockResponse<Response<any, Record<string, any>>>;
|
|
870
874
|
loggerMock: AbstractLogger & LOG & {
|
|
871
|
-
_getLogs: () => Record<"
|
|
875
|
+
_getLogs: () => Record<"debug" | "info" | "warn" | "error", unknown[]>;
|
|
872
876
|
};
|
|
873
877
|
}>;
|
|
874
878
|
declare const testMiddleware: <LOG extends FlatObject, REQ extends RequestOptions>({
|
|
875
879
|
middleware,
|
|
876
|
-
|
|
880
|
+
ctx,
|
|
877
881
|
...rest
|
|
878
882
|
}: TestingProps<REQ, LOG> & {
|
|
879
883
|
/** @desc The middleware to test */
|
|
880
884
|
middleware: AbstractMiddleware;
|
|
881
|
-
/** @desc The aggregated
|
|
882
|
-
|
|
885
|
+
/** @desc The aggregated returns of previously executed middlewares */
|
|
886
|
+
ctx?: FlatObject;
|
|
883
887
|
}) => Promise<{
|
|
884
|
-
requestMock: node_mocks_http0.MockRequest<Request<
|
|
888
|
+
requestMock: node_mocks_http0.MockRequest<Request<express_serve_static_core0.ParamsDictionary, any, any, qs0.ParsedQs, Record<string, any>> & REQ>;
|
|
885
889
|
responseMock: node_mocks_http0.MockResponse<Response<any, Record<string, any>>>;
|
|
886
890
|
loggerMock: AbstractLogger & LOG & {
|
|
887
|
-
_getLogs: () => Record<"
|
|
891
|
+
_getLogs: () => Record<"debug" | "info" | "warn" | "error", unknown[]>;
|
|
888
892
|
};
|
|
889
893
|
output: FlatObject;
|
|
890
894
|
}>;
|
|
@@ -903,10 +907,10 @@ interface NextHandlerInc<U> {
|
|
|
903
907
|
interface PrevInc<U> {
|
|
904
908
|
prev: U;
|
|
905
909
|
}
|
|
906
|
-
type SchemaHandler<U, Context extends FlatObject = EmptyObject, Variant extends "regular" | "each" | "last" = "regular"> = (schema: any,
|
|
910
|
+
type SchemaHandler<U, Context$1 extends FlatObject = EmptyObject, Variant extends "regular" | "each" | "last" = "regular"> = (schema: any,
|
|
907
911
|
// eslint-disable-line @typescript-eslint/no-explicit-any -- for assignment compatibility
|
|
908
|
-
ctx: Context & (Variant extends "regular" ? NextHandlerInc<U> : Variant extends "each" ? PrevInc<U> : Context)) => U;
|
|
909
|
-
type HandlingRules<U, Context extends FlatObject = EmptyObject, K extends string | symbol = string | symbol> = Partial<Record<K, SchemaHandler<U, Context>>>;
|
|
912
|
+
ctx: Context$1 & (Variant extends "regular" ? NextHandlerInc<U> : Variant extends "each" ? PrevInc<U> : Context$1)) => U;
|
|
913
|
+
type HandlingRules<U, Context$1 extends FlatObject = EmptyObject, K$1 extends string | symbol = string | symbol> = Partial<Record<K$1, SchemaHandler<U, Context$1>>>;
|
|
910
914
|
//#endregion
|
|
911
915
|
//#region src/zts-helpers.d.ts
|
|
912
916
|
interface ZTSContext extends FlatObject {
|
|
@@ -918,6 +922,7 @@ type Producer = SchemaHandler<ts.TypeNode, ZTSContext>;
|
|
|
918
922
|
//#region src/integration.d.ts
|
|
919
923
|
interface IntegrationParams {
|
|
920
924
|
routing: Routing;
|
|
925
|
+
config: CommonConfig;
|
|
921
926
|
/**
|
|
922
927
|
* @desc What should be generated
|
|
923
928
|
* @example "types" — types of your endpoint requests and responses (for a DIY solution)
|
|
@@ -942,6 +947,7 @@ interface IntegrationParams {
|
|
|
942
947
|
/**
|
|
943
948
|
* @desc Depict the HEAD method for each Endpoint supporting the GET method (feature of Express)
|
|
944
949
|
* @default true
|
|
950
|
+
* @todo move to config
|
|
945
951
|
* */
|
|
946
952
|
hasHeadMethod?: boolean;
|
|
947
953
|
/**
|
|
@@ -965,6 +971,7 @@ declare class Integration extends IntegrationBase {
|
|
|
965
971
|
#private;
|
|
966
972
|
constructor({
|
|
967
973
|
routing,
|
|
974
|
+
config,
|
|
968
975
|
brandHandling,
|
|
969
976
|
variant,
|
|
970
977
|
clientClassName,
|
|
@@ -988,7 +995,7 @@ interface Emitter<E extends EventsMap> extends FlatObject {
|
|
|
988
995
|
/** @desc Abort signal bound to the client connection lifecycle */
|
|
989
996
|
signal: AbortSignal;
|
|
990
997
|
/** @desc Sends an event to the stream according to the declared schema */
|
|
991
|
-
emit: <K extends keyof E>(event: K, data: z.input<E[K]>) => void;
|
|
998
|
+
emit: <K$1 extends keyof E>(event: K$1, data: z.input<E[K$1]>) => void;
|
|
992
999
|
}
|
|
993
1000
|
declare class EventStreamFactory<E extends EventsMap> extends EndpointsFactory<undefined, Emitter<E>> {
|
|
994
1001
|
constructor(events: E);
|
|
@@ -1009,13 +1016,13 @@ declare const base: z.ZodObject<{
|
|
|
1009
1016
|
raw: z.core.$ZodBranded<z.ZodCustom<Buffer<ArrayBufferLike>, Buffer<ArrayBufferLike>>, symbol>;
|
|
1010
1017
|
}, z.core.$strip>;
|
|
1011
1018
|
type Base = ReturnType<typeof base.brand<symbol>>;
|
|
1012
|
-
declare const extended: <S extends z.core.$ZodShape>(extra: S) => z.core.$ZodBranded<z.ZodObject<("raw" & keyof S extends never ? {
|
|
1019
|
+
declare const extended: <S$1 extends z.core.$ZodShape>(extra: S$1) => z.core.$ZodBranded<z.ZodObject<("raw" & keyof S$1 extends never ? {
|
|
1013
1020
|
raw: z.core.$ZodBranded<z.ZodCustom<Buffer<ArrayBufferLike>, Buffer<ArrayBufferLike>>, symbol>;
|
|
1014
|
-
} & S : ({
|
|
1021
|
+
} & S$1 : ({
|
|
1015
1022
|
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>;
|
|
1023
|
+
} extends infer T_1 extends z.core.util.SomeObject ? { [K in keyof T_1 as K extends keyof S$1 ? never : K]: T_1[K] } : never) & { [K_1 in keyof S$1]: S$1[K_1] }) extends infer T ? { [k in keyof T]: T[k] } : never, z.core.$strip>, symbol>;
|
|
1017
1024
|
declare function raw(): Base;
|
|
1018
|
-
declare function raw<S extends z.core.$ZodShape>(extra: S): ReturnType<typeof extended<S>>;
|
|
1025
|
+
declare function raw<S$1 extends z.core.$ZodShape>(extra: S$1): ReturnType<typeof extended<S$1>>;
|
|
1019
1026
|
//#endregion
|
|
1020
1027
|
//#region src/proprietary-schemas.d.ts
|
|
1021
1028
|
declare const ez: {
|
|
@@ -1024,10 +1031,10 @@ declare const ez: {
|
|
|
1024
1031
|
...rest
|
|
1025
1032
|
}?: DateInParams) => 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
1033
|
dateOut: (meta?: DateOutParams) => 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>;
|
|
1034
|
+
form: <S$1 extends zod_v4_core0.$ZodShape>(base: S$1 | zod0.ZodObject<S$1>) => zod_v4_core0.$ZodBranded<zod0.ZodObject<S$1, zod_v4_core0.$strip>, symbol>;
|
|
1028
1035
|
upload: () => zod_v4_core0.$ZodBranded<zod0.ZodCustom<express_fileupload0.UploadedFile, express_fileupload0.UploadedFile>, symbol>;
|
|
1029
1036
|
raw: typeof raw;
|
|
1030
1037
|
buffer: () => zod_v4_core0.$ZodBranded<zod0.ZodCustom<Buffer<ArrayBufferLike>, Buffer<ArrayBufferLike>>, symbol>;
|
|
1031
1038
|
};
|
|
1032
1039
|
//#endregion
|
|
1033
|
-
export { type ApiResponse, type AppConfig, type BasicSecurity, type BearerSecurity, BuiltinLogger, type CommonConfig, type CookieSecurity,
|
|
1040
|
+
export { type ApiResponse, type AppConfig, type BasicSecurity, type BearerSecurity, BuiltinLogger, type CommonConfig, type CookieSecurity, 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 };
|