express-zod-api 19.2.1 → 20.0.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 +87 -0
- package/README.md +41 -55
- package/dist/index.cjs +8 -8
- package/dist/index.d.cts +145 -100
- package/dist/index.d.ts +145 -100
- package/dist/index.js +9 -9
- package/package.json +6 -17
package/dist/index.d.cts
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import * as zod from 'zod';
|
|
2
2
|
import { z, ZodError } from 'zod';
|
|
3
3
|
import compression from 'compression';
|
|
4
|
-
import
|
|
4
|
+
import * as express from 'express';
|
|
5
|
+
import express__default, { Request, Response, NextFunction, RequestHandler, IRouter } from 'express';
|
|
5
6
|
import * as express_fileupload from 'express-fileupload';
|
|
6
7
|
import express_fileupload__default from 'express-fileupload';
|
|
7
8
|
import https, { ServerOptions } from 'node:https';
|
|
8
9
|
import { Ansis } from 'ansis';
|
|
9
|
-
import { HttpError } from 'http-errors';
|
|
10
10
|
import { ListenOptions } from 'node:net';
|
|
11
11
|
import * as qs from 'qs';
|
|
12
12
|
import * as express_serve_static_core from 'express-serve-static-core';
|
|
13
13
|
import http from 'node:http';
|
|
14
14
|
import { ReferenceObject, SchemaObject, OpenApiBuilder, SecuritySchemeType, SecuritySchemeObject } from 'openapi3-ts/oas31';
|
|
15
|
+
import * as node_mocks_http from 'node-mocks-http';
|
|
16
|
+
import { RequestOptions, ResponseOptions } from 'node-mocks-http';
|
|
15
17
|
import ts from 'typescript';
|
|
18
|
+
import { Rule } from 'eslint';
|
|
16
19
|
|
|
17
20
|
declare const metaSymbol: unique symbol;
|
|
18
21
|
interface Metadata {
|
|
@@ -47,6 +50,8 @@ interface LoggerOverrides {
|
|
|
47
50
|
}
|
|
48
51
|
type ActualLogger = AbstractLogger & LoggerOverrides;
|
|
49
52
|
|
|
53
|
+
/** @desc this type does not allow props assignment, but it works for reading them when merged with another interface */
|
|
54
|
+
type EmptyObject = Record<string, never>;
|
|
50
55
|
type FlatObject = Record<string, unknown>;
|
|
51
56
|
declare const getMessageFromError: (error: Error) => string;
|
|
52
57
|
declare const getStatusCodeFromError: (error: Error) => number;
|
|
@@ -107,12 +112,6 @@ declare class BuiltinLogger implements AbstractLogger {
|
|
|
107
112
|
error(message: string, meta?: unknown): void;
|
|
108
113
|
child(ctx: Context): BuiltinLogger;
|
|
109
114
|
}
|
|
110
|
-
/**
|
|
111
|
-
* @desc Alias for "new BuiltinLogger()"
|
|
112
|
-
* @deprecated use new BuiltinLogger()
|
|
113
|
-
* @todo remove in v20
|
|
114
|
-
* */
|
|
115
|
-
declare const createLogger: (config: BuiltinLoggerConfig) => BuiltinLogger;
|
|
116
115
|
|
|
117
116
|
interface ApiResponse<S extends z.ZodTypeAny> {
|
|
118
117
|
schema: S;
|
|
@@ -136,7 +135,6 @@ interface ApiResponse<S extends z.ZodTypeAny> {
|
|
|
136
135
|
mimeTypes?: [string, ...string[]];
|
|
137
136
|
}
|
|
138
137
|
type NormalizedResponse = Required<Pick<ApiResponse<z.ZodTypeAny>, "schema" | "statusCodes" | "mimeTypes">>;
|
|
139
|
-
type AnyResponseDefinition = z.ZodTypeAny | ApiResponse<z.ZodTypeAny> | ApiResponse<z.ZodTypeAny>[];
|
|
140
138
|
|
|
141
139
|
type LogicalOr<T> = {
|
|
142
140
|
or: T[];
|
|
@@ -219,28 +217,47 @@ interface OAuth2Security<S extends string> {
|
|
|
219
217
|
* */
|
|
220
218
|
type Security<K extends string = string, S extends string = string> = BasicSecurity | BearerSecurity | InputSecurity<K> | CustomHeaderSecurity | CookieSecurity | OpenIdSecurity | OAuth2Security<S>;
|
|
221
219
|
|
|
222
|
-
|
|
220
|
+
type Handler$2<IN, OPT, OUT> = (params: {
|
|
223
221
|
input: IN;
|
|
224
222
|
options: OPT;
|
|
225
223
|
request: Request;
|
|
226
224
|
response: Response;
|
|
227
225
|
logger: ActualLogger;
|
|
226
|
+
}) => Promise<OUT>;
|
|
227
|
+
declare abstract class AbstractMiddleware {
|
|
228
|
+
abstract getSecurity(): LogicalContainer<Security> | undefined;
|
|
229
|
+
abstract getSchema(): IOSchema<"strip">;
|
|
230
|
+
abstract execute(params: {
|
|
231
|
+
input: unknown;
|
|
232
|
+
options: FlatObject;
|
|
233
|
+
request: Request;
|
|
234
|
+
response: Response;
|
|
235
|
+
logger: ActualLogger;
|
|
236
|
+
}): Promise<FlatObject>;
|
|
228
237
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
input:
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
238
|
+
declare class Middleware<IN extends IOSchema<"strip">, OPT extends FlatObject, OUT extends FlatObject, SCO extends string> extends AbstractMiddleware {
|
|
239
|
+
#private;
|
|
240
|
+
constructor({ input, security, handler, }: {
|
|
241
|
+
input: IN;
|
|
242
|
+
security?: LogicalContainer<Security<Extract<keyof z.input<IN>, string>, SCO>>;
|
|
243
|
+
handler: Handler$2<z.output<IN>, OPT, OUT>;
|
|
244
|
+
});
|
|
245
|
+
getSecurity(): LogicalContainer<Security<Extract<keyof z.input<IN>, string>, SCO>> | undefined;
|
|
246
|
+
getSchema(): IN;
|
|
247
|
+
/** @throws InputValidationError */
|
|
248
|
+
execute({ input, ...rest }: {
|
|
249
|
+
input: unknown;
|
|
250
|
+
options: OPT;
|
|
251
|
+
request: Request;
|
|
252
|
+
response: Response;
|
|
253
|
+
logger: ActualLogger;
|
|
254
|
+
}): Promise<OUT>;
|
|
237
255
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
transformer?: (err: Error) => HttpError | Error;
|
|
256
|
+
declare class ExpressMiddleware<R extends Request, S extends Response, OUT extends FlatObject> extends Middleware<z.ZodObject<EmptyObject, "strip">, FlatObject, OUT, string> {
|
|
257
|
+
constructor(nativeMw: (request: R, response: S, next: NextFunction) => void | Promise<void>, { provider, transformer, }?: {
|
|
258
|
+
provider?: (request: R, response: S) => OUT | Promise<OUT>;
|
|
259
|
+
transformer?: (err: Error) => Error;
|
|
260
|
+
});
|
|
244
261
|
}
|
|
245
262
|
|
|
246
263
|
/** Shorthand for z.object({ raw: ez.file("buffer") }) */
|
|
@@ -262,8 +279,7 @@ type Refined<T extends z.ZodTypeAny> = T extends z.ZodType<infer O> ? z.ZodEffec
|
|
|
262
279
|
* @desc The type allowed on the top level of Middlewares and Endpoints
|
|
263
280
|
* @param U — only "strip" is allowed for Middlewares due to intersection issue (Zod) #600
|
|
264
281
|
* */
|
|
265
|
-
type IOSchema<U extends z.UnknownKeysParam =
|
|
266
|
-
type ProbableIntersection<A extends IOSchema<"strip"> | null, B extends IOSchema> = A extends null ? B : A extends IOSchema<"strip"> ? z.ZodIntersection<A, B> : never;
|
|
282
|
+
type IOSchema<U extends z.UnknownKeysParam = z.UnknownKeysParam> = z.ZodObject<z.ZodRawShape, U> | z.ZodUnion<[IOSchema<U>, ...IOSchema<U>[]]> | z.ZodIntersection<IOSchema<U>, IOSchema<U>> | z.ZodDiscriminatedUnion<string, z.ZodObject<z.ZodRawShape, U>[]> | Refined<z.ZodObject<z.ZodRawShape, U>> | RawSchema;
|
|
267
283
|
|
|
268
284
|
declare const methods: ("get" | "post" | "put" | "delete" | "patch")[];
|
|
269
285
|
type Method = (typeof methods)[number];
|
|
@@ -275,7 +291,9 @@ declare const contentTypes: {
|
|
|
275
291
|
};
|
|
276
292
|
type ContentType = keyof typeof contentTypes;
|
|
277
293
|
|
|
278
|
-
|
|
294
|
+
type ResultSchema<R extends Result> = R extends Result<infer S> ? S : never;
|
|
295
|
+
|
|
296
|
+
type Handler$1<RES = unknown> = (params: {
|
|
279
297
|
/** null in case of failure to parse or to find the matching endpoint (error: not found) */
|
|
280
298
|
input: FlatObject | null;
|
|
281
299
|
/** null in case of errors or failures */
|
|
@@ -286,17 +304,30 @@ interface ResultHandlerParams<RES> {
|
|
|
286
304
|
request: Request;
|
|
287
305
|
response: Response<RES>;
|
|
288
306
|
logger: ActualLogger;
|
|
307
|
+
}) => void | Promise<void>;
|
|
308
|
+
type Result<S extends z.ZodTypeAny = z.ZodTypeAny> = S | ApiResponse<S> | ApiResponse<S>[];
|
|
309
|
+
type LazyResult<R extends Result, A extends unknown[] = []> = (...args: A) => R;
|
|
310
|
+
declare abstract class AbstractResultHandler {
|
|
311
|
+
#private;
|
|
312
|
+
abstract getPositiveResponse(output: IOSchema): NormalizedResponse[];
|
|
313
|
+
abstract getNegativeResponse(): NormalizedResponse[];
|
|
314
|
+
protected constructor(handler: Handler$1);
|
|
315
|
+
execute(...params: Parameters<Handler$1>): void | Promise<void>;
|
|
289
316
|
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
317
|
+
declare class ResultHandler<POS extends Result, NEG extends Result> extends AbstractResultHandler {
|
|
318
|
+
#private;
|
|
319
|
+
constructor(params: {
|
|
320
|
+
/** @desc A description of the API response in case of success (schema, status code, MIME type) */
|
|
321
|
+
positive: POS | LazyResult<POS, [IOSchema]>;
|
|
322
|
+
/** @desc A description of the API response in case of error (schema, status code, MIME type) */
|
|
323
|
+
negative: NEG | LazyResult<NEG>;
|
|
324
|
+
/** @desc The actual implementation to transmit the response in any case */
|
|
325
|
+
handler: Handler$1<z.output<ResultSchema<POS> | ResultSchema<NEG>>>;
|
|
326
|
+
});
|
|
327
|
+
getPositiveResponse(output: IOSchema): Required<Pick<ApiResponse<z.ZodTypeAny>, "schema" | "statusCodes" | "mimeTypes">>[];
|
|
328
|
+
getNegativeResponse(): Required<Pick<ApiResponse<z.ZodTypeAny>, "schema" | "statusCodes" | "mimeTypes">>[];
|
|
296
329
|
}
|
|
297
|
-
|
|
298
|
-
declare const createResultHandler: <POS extends AnyResponseDefinition, NEG extends AnyResponseDefinition>(definition: ResultHandlerDefinition<POS, NEG>) => ResultHandlerDefinition<POS, NEG>;
|
|
299
|
-
declare const defaultResultHandler: ResultHandlerDefinition<z.ZodObject<{
|
|
330
|
+
declare const defaultResultHandler: ResultHandler<z.ZodObject<{
|
|
300
331
|
status: z.ZodLiteral<"success">;
|
|
301
332
|
data: IOSchema;
|
|
302
333
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -330,7 +361,7 @@ declare const defaultResultHandler: ResultHandlerDefinition<z.ZodObject<{
|
|
|
330
361
|
* @desc Responding with array is a bad practice keeping your endpoints from evolving without breaking changes.
|
|
331
362
|
* @desc This handler expects your endpoint to have the property 'items' in the output object schema
|
|
332
363
|
* */
|
|
333
|
-
declare const arrayResultHandler:
|
|
364
|
+
declare const arrayResultHandler: ResultHandler<z.ZodArray<z.ZodTypeAny, "many">, z.ZodString>;
|
|
334
365
|
|
|
335
366
|
type Handler<IN, OUT, OPT> = (params: {
|
|
336
367
|
input: IN;
|
|
@@ -364,11 +395,11 @@ declare abstract class AbstractEndpoint {
|
|
|
364
395
|
declare class Endpoint<IN extends IOSchema, OUT extends IOSchema, OPT extends FlatObject, SCO extends string, TAG extends string> extends AbstractEndpoint {
|
|
365
396
|
#private;
|
|
366
397
|
constructor({ methods, inputSchema, outputSchema, handler, resultHandler, getOperationId, scopes, middlewares, tags, description: long, shortDescription: short, }: {
|
|
367
|
-
middlewares?:
|
|
398
|
+
middlewares?: AbstractMiddleware[];
|
|
368
399
|
inputSchema: IN;
|
|
369
400
|
outputSchema: OUT;
|
|
370
401
|
handler: Handler<z.output<IN>, z.input<OUT>, OPT>;
|
|
371
|
-
resultHandler:
|
|
402
|
+
resultHandler: AbstractResultHandler;
|
|
372
403
|
description?: string;
|
|
373
404
|
shortDescription?: string;
|
|
374
405
|
getOperationId?: (method: Method) => string | undefined;
|
|
@@ -427,7 +458,7 @@ interface CommonConfig<TAG extends string = string> {
|
|
|
427
458
|
* @default defaultResultHandler
|
|
428
459
|
* @see defaultResultHandler
|
|
429
460
|
*/
|
|
430
|
-
errorHandler?:
|
|
461
|
+
errorHandler?: AbstractResultHandler;
|
|
431
462
|
/**
|
|
432
463
|
* @desc Built-in logger configuration or an instance of any compatible logger.
|
|
433
464
|
* @example { level: "debug", color: true }
|
|
@@ -533,10 +564,10 @@ interface AppConfig<TAG extends string = string> extends CommonConfig<TAG> {
|
|
|
533
564
|
declare function createConfig<TAG extends string>(config: ServerConfig<TAG>): ServerConfig<TAG>;
|
|
534
565
|
declare function createConfig<TAG extends string>(config: AppConfig<TAG>): AppConfig<TAG>;
|
|
535
566
|
|
|
536
|
-
type BuildProps<IN extends IOSchema, OUT extends IOSchema, MIN extends IOSchema<"strip"
|
|
567
|
+
type BuildProps<IN extends IOSchema, OUT extends IOSchema, MIN extends IOSchema<"strip">, OPT extends FlatObject, SCO extends string, TAG extends string> = {
|
|
537
568
|
input: IN;
|
|
538
569
|
output: OUT;
|
|
539
|
-
handler: Handler<z.output<
|
|
570
|
+
handler: Handler<z.output<z.ZodIntersection<MIN, IN>>, z.input<OUT>, OPT>;
|
|
540
571
|
description?: string;
|
|
541
572
|
shortDescription?: string;
|
|
542
573
|
operationId?: string | ((method: Method) => string);
|
|
@@ -553,29 +584,40 @@ type BuildProps<IN extends IOSchema, OUT extends IOSchema, MIN extends IOSchema<
|
|
|
553
584
|
} | {
|
|
554
585
|
tag?: TAG;
|
|
555
586
|
});
|
|
556
|
-
declare class EndpointsFactory<IN extends IOSchema<"strip">
|
|
587
|
+
declare class EndpointsFactory<IN extends IOSchema<"strip"> = z.ZodObject<EmptyObject, "strip">, OUT extends FlatObject = EmptyObject, SCO extends string = string, TAG extends string = string> {
|
|
557
588
|
#private;
|
|
558
|
-
protected resultHandler:
|
|
559
|
-
protected middlewares:
|
|
589
|
+
protected resultHandler: AbstractResultHandler;
|
|
590
|
+
protected middlewares: AbstractMiddleware[];
|
|
560
591
|
/** @desc Consider using the "config" prop with the "tags" option to enforce constraints on tagging the endpoints */
|
|
561
|
-
constructor(resultHandler:
|
|
592
|
+
constructor(resultHandler: AbstractResultHandler);
|
|
562
593
|
constructor(params: {
|
|
563
|
-
resultHandler:
|
|
594
|
+
resultHandler: AbstractResultHandler;
|
|
564
595
|
config?: CommonConfig<TAG>;
|
|
565
596
|
});
|
|
566
|
-
addMiddleware<AIN extends IOSchema<"strip">, AOUT extends FlatObject, ASCO extends string>(subject:
|
|
567
|
-
use: <R extends Request<express_serve_static_core.ParamsDictionary, any, any, qs.ParsedQs, Record<string, any>>, S extends Response<any, Record<string, any>>, AOUT extends FlatObject =
|
|
568
|
-
|
|
597
|
+
addMiddleware<AIN extends IOSchema<"strip">, AOUT extends FlatObject, ASCO extends string>(subject: Middleware<AIN, OUT, AOUT, ASCO> | ConstructorParameters<typeof Middleware<AIN, OUT, AOUT, ASCO>>[0]): EndpointsFactory<z.ZodIntersection<IN, AIN>, OUT & AOUT, SCO & ASCO, TAG>;
|
|
598
|
+
use: <R extends Request<express_serve_static_core.ParamsDictionary, any, any, qs.ParsedQs, Record<string, any>>, S extends Response<any, Record<string, any>>, AOUT extends FlatObject = EmptyObject>(nativeMw: (request: R, response: S, next: express.NextFunction) => void | Promise<void>, params_1?: {
|
|
599
|
+
provider?: ((request: R, response: S) => AOUT | Promise<AOUT>) | undefined;
|
|
600
|
+
transformer?: ((err: Error) => Error) | undefined;
|
|
601
|
+
} | undefined) => EndpointsFactory<IN, OUT & AOUT, SCO, TAG>;
|
|
602
|
+
addExpressMiddleware<R extends Request, S extends Response, AOUT extends FlatObject = EmptyObject>(...params: ConstructorParameters<typeof ExpressMiddleware<R, S, AOUT>>): EndpointsFactory<IN, OUT & AOUT, SCO, TAG>;
|
|
569
603
|
addOptions<AOUT extends FlatObject>(getOptions: () => Promise<AOUT>): EndpointsFactory<IN, OUT & AOUT, SCO, TAG>;
|
|
570
|
-
build<BIN extends IOSchema, BOUT extends IOSchema>({ input, handler, output: outputSchema, description, shortDescription, operationId, ...rest }: BuildProps<BIN, BOUT, IN, OUT, SCO, TAG>): Endpoint<
|
|
604
|
+
build<BIN extends IOSchema, BOUT extends IOSchema>({ input, handler, output: outputSchema, description, shortDescription, operationId, ...rest }: BuildProps<BIN, BOUT, IN, OUT, SCO, TAG>): Endpoint<z.ZodIntersection<IN, BIN>, BOUT, OUT, SCO, TAG>;
|
|
571
605
|
}
|
|
572
|
-
declare const defaultEndpointsFactory: EndpointsFactory<
|
|
606
|
+
declare const defaultEndpointsFactory: EndpointsFactory<z.ZodObject<EmptyObject, "strip", z.ZodTypeAny, {
|
|
607
|
+
[x: string]: never;
|
|
608
|
+
}, {
|
|
609
|
+
[x: string]: never;
|
|
610
|
+
}>, EmptyObject, string, string>;
|
|
573
611
|
/**
|
|
574
612
|
* @deprecated Resist the urge of using it: this factory is designed only to simplify the migration of legacy APIs.
|
|
575
613
|
* @desc Responding with array is a bad practice keeping your endpoints from evolving without breaking changes.
|
|
576
614
|
* @desc The result handler of this factory expects your endpoint to have the property 'items' in the output schema
|
|
577
615
|
*/
|
|
578
|
-
declare const arrayEndpointsFactory: EndpointsFactory<
|
|
616
|
+
declare const arrayEndpointsFactory: EndpointsFactory<z.ZodObject<EmptyObject, "strip", z.ZodTypeAny, {
|
|
617
|
+
[x: string]: never;
|
|
618
|
+
}, {
|
|
619
|
+
[x: string]: never;
|
|
620
|
+
}>, EmptyObject, string, string>;
|
|
579
621
|
|
|
580
622
|
declare class DependsOnMethod {
|
|
581
623
|
readonly pairs: ReadonlyArray<[Method, AbstractEndpoint]>;
|
|
@@ -584,7 +626,7 @@ declare class DependsOnMethod {
|
|
|
584
626
|
constructor(endpoints: Partial<Record<Method, AbstractEndpoint>>);
|
|
585
627
|
}
|
|
586
628
|
|
|
587
|
-
type OriginalStatic = typeof
|
|
629
|
+
type OriginalStatic = typeof express__default.static;
|
|
588
630
|
type StaticHandler = ReturnType<OriginalStatic>;
|
|
589
631
|
declare class ServeStatic {
|
|
590
632
|
params: Parameters<OriginalStatic>;
|
|
@@ -597,7 +639,7 @@ interface Routing {
|
|
|
597
639
|
}
|
|
598
640
|
|
|
599
641
|
declare const attachRouting: (config: AppConfig, routing: Routing) => {
|
|
600
|
-
notFoundHandler:
|
|
642
|
+
notFoundHandler: express__default.RequestHandler<express_serve_static_core.ParamsDictionary, any, any, qs.ParsedQs, Record<string, any>>;
|
|
601
643
|
logger: AbstractLogger | BuiltinLogger;
|
|
602
644
|
};
|
|
603
645
|
declare const createServer: (config: ServerConfig, routing: Routing) => Promise<{
|
|
@@ -670,18 +712,15 @@ declare const ez: {
|
|
|
670
712
|
}, S>>[k_1]; } : never>, symbol>;
|
|
671
713
|
};
|
|
672
714
|
|
|
673
|
-
interface
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
prev: U;
|
|
679
|
-
};
|
|
680
|
-
last: {};
|
|
715
|
+
interface NextHandlerInc<U> {
|
|
716
|
+
next: (schema: z.ZodTypeAny) => U;
|
|
717
|
+
}
|
|
718
|
+
interface PrevInc<U> {
|
|
719
|
+
prev: U;
|
|
681
720
|
}
|
|
682
|
-
type
|
|
683
|
-
|
|
684
|
-
type HandlingRules<U, Context extends FlatObject =
|
|
721
|
+
type SchemaHandler<U, Context extends FlatObject = EmptyObject, Variant extends "regular" | "each" | "last" = "regular"> = (schema: any, // eslint-disable-line @typescript-eslint/no-explicit-any -- for assignmet compatibility
|
|
722
|
+
ctx: Context & (Variant extends "regular" ? NextHandlerInc<U> : Variant extends "each" ? PrevInc<U> : Context)) => U;
|
|
723
|
+
type HandlingRules<U, Context extends FlatObject = EmptyObject, K extends string | symbol = string | symbol> = Partial<Record<K, SchemaHandler<U, Context>>>;
|
|
685
724
|
|
|
686
725
|
interface OpenAPIContext extends FlatObject {
|
|
687
726
|
isResponse: boolean;
|
|
@@ -743,28 +782,19 @@ type LocalResponse = Response<unknown, {
|
|
|
743
782
|
};
|
|
744
783
|
}>;
|
|
745
784
|
|
|
746
|
-
|
|
747
|
-
* @desc Using module augmentation approach you can set the Mock type of your actual testing framework.
|
|
748
|
-
* @example declare module "express-zod-api" { interface MockOverrides extends Mock {} }
|
|
749
|
-
* @link https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation
|
|
750
|
-
* */
|
|
751
|
-
interface MockOverrides {
|
|
752
|
-
}
|
|
753
|
-
/** @desc Compatibility constraints for a function mocking method of a testing framework. */
|
|
754
|
-
type MockFunction = (implementation?: (...args: any[]) => any) => MockOverrides;
|
|
755
|
-
interface TestEndpointProps<REQ, RES, LOG> {
|
|
785
|
+
interface TestEndpointProps<REQ, LOG> {
|
|
756
786
|
/** @desc The endpoint to test */
|
|
757
787
|
endpoint: AbstractEndpoint;
|
|
758
788
|
/**
|
|
759
789
|
* @desc Additional properties to set on Request mock
|
|
760
|
-
* @default { method: "GET",
|
|
790
|
+
* @default { method: "GET", headers: { "content-type": "application/json" } }
|
|
761
791
|
* */
|
|
762
792
|
requestProps?: REQ;
|
|
763
793
|
/**
|
|
764
|
-
* @
|
|
765
|
-
* @default {
|
|
794
|
+
* @link https://www.npmjs.com/package/node-mocks-http
|
|
795
|
+
* @default { req: requestMock }
|
|
766
796
|
* */
|
|
767
|
-
|
|
797
|
+
responseOptions?: ResponseOptions;
|
|
768
798
|
/**
|
|
769
799
|
* @desc Additional properties to set on config mock
|
|
770
800
|
* @default { cors: false, logger }
|
|
@@ -775,25 +805,26 @@ interface TestEndpointProps<REQ, RES, LOG> {
|
|
|
775
805
|
* @default { info, warn, error, debug }
|
|
776
806
|
* */
|
|
777
807
|
loggerProps?: LOG;
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
808
|
+
}
|
|
809
|
+
declare const testEndpoint: <LOG extends FlatObject, REQ extends RequestOptions>({ endpoint, requestProps, responseOptions, configProps, loggerProps, }: TestEndpointProps<REQ, LOG>) => Promise<{
|
|
810
|
+
requestMock: Request<express_serve_static_core.ParamsDictionary, any, any, qs.ParsedQs, Record<string, any>> & {
|
|
811
|
+
[key: string]: any;
|
|
812
|
+
_setParameter: (key: string, value?: string | undefined) => void;
|
|
813
|
+
_setSessionVariable: (variable: string, value?: string | undefined) => void;
|
|
814
|
+
_setCookiesVariable: (variable: string, value?: string | undefined) => void;
|
|
815
|
+
_setSignedCookiesVariable: (variable: string, value?: string | undefined) => void;
|
|
816
|
+
_setHeadersCookiesVariable: (variable: string, value: string) => void;
|
|
817
|
+
_setFilesCookiesVariable: (variable: string, value?: string | undefined) => void;
|
|
818
|
+
_setMethod: (method?: string | undefined) => void;
|
|
819
|
+
_setURL: (value?: string | undefined) => void;
|
|
820
|
+
_setOriginalUrl: (value?: string | undefined) => void;
|
|
821
|
+
_setBody: (body?: node_mocks_http.Body | undefined) => void;
|
|
822
|
+
_addBody: (key: string, value?: any) => void;
|
|
823
|
+
} & REQ;
|
|
824
|
+
responseMock: node_mocks_http.MockResponse<LocalResponse>;
|
|
825
|
+
loggerMock: AbstractLogger & LOG & {
|
|
826
|
+
_getLogs: () => Record<"info" | "debug" | "warn" | "error", unknown[]>;
|
|
827
|
+
};
|
|
797
828
|
}>;
|
|
798
829
|
|
|
799
830
|
interface ZTSContext extends FlatObject {
|
|
@@ -915,4 +946,18 @@ declare class Integration {
|
|
|
915
946
|
printFormatted({ printerOptions, format: userDefined, }?: FormattedPrintingOptions): Promise<string>;
|
|
916
947
|
}
|
|
917
948
|
|
|
918
|
-
|
|
949
|
+
/** @desc ESLint plugin for migrating to this version (from previous) */
|
|
950
|
+
declare const migration: {
|
|
951
|
+
rules: {
|
|
952
|
+
"ez-migration/v20": "error";
|
|
953
|
+
};
|
|
954
|
+
plugins: {
|
|
955
|
+
"ez-migration": {
|
|
956
|
+
rules: {
|
|
957
|
+
v20: Rule.RuleModule;
|
|
958
|
+
};
|
|
959
|
+
};
|
|
960
|
+
};
|
|
961
|
+
};
|
|
962
|
+
|
|
963
|
+
export { type ApiResponse, type AppConfig, type BasicSecurity, type BearerSecurity, BuiltinLogger, type CommonConfig, type CookieSecurity, type CustomHeaderSecurity, DependsOnMethod, type Depicter, Documentation, DocumentationError, EndpointsFactory, type FlatObject, 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, arrayEndpointsFactory, arrayResultHandler, attachRouting, createConfig, createServer, defaultEndpointsFactory, defaultResultHandler, ez, getExamples, getMessageFromError, getStatusCodeFromError, migration, testEndpoint };
|