express-zod-api 22.0.0-beta.1 → 22.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 +47 -0
- package/README.md +22 -25
- package/dist/index.cjs +8 -8
- package/dist/index.d.cts +41 -40
- package/dist/index.d.ts +41 -40
- package/dist/index.js +7 -7
- package/migration/index.cjs +7 -1
- package/migration/index.d.cts +1 -1
- package/migration/index.d.ts +1 -1
- package/migration/index.js +7 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -12,7 +12,7 @@ import { ListenOptions } from 'node:net';
|
|
|
12
12
|
import * as qs from 'qs';
|
|
13
13
|
import * as express_serve_static_core from 'express-serve-static-core';
|
|
14
14
|
import http from 'node:http';
|
|
15
|
-
import { SchemaObject, ReferenceObject, OpenApiBuilder, SecuritySchemeType, SecuritySchemeObject } from 'openapi3-ts/oas31';
|
|
15
|
+
import { SchemaObject, ReferenceObject, TagObject, OpenApiBuilder, SecuritySchemeType, SecuritySchemeObject } from 'openapi3-ts/oas31';
|
|
16
16
|
import * as node_mocks_http from 'node-mocks-http';
|
|
17
17
|
import { RequestOptions, ResponseOptions } from 'node-mocks-http';
|
|
18
18
|
import ts from 'typescript';
|
|
@@ -442,15 +442,11 @@ type HeadersProvider = (params: {
|
|
|
442
442
|
endpoint: AbstractEndpoint;
|
|
443
443
|
logger: ActualLogger;
|
|
444
444
|
}) => Headers | Promise<Headers>;
|
|
445
|
-
type TagsConfig<TAG extends string> = Record<TAG, string | {
|
|
446
|
-
description: string;
|
|
447
|
-
url?: string;
|
|
448
|
-
}>;
|
|
449
445
|
type ChildLoggerProvider = (params: {
|
|
450
446
|
request: Request;
|
|
451
447
|
parent: ActualLogger;
|
|
452
448
|
}) => ActualLogger | Promise<ActualLogger>;
|
|
453
|
-
interface CommonConfig
|
|
449
|
+
interface CommonConfig {
|
|
454
450
|
/**
|
|
455
451
|
* @desc Enables cross-origin resource sharing.
|
|
456
452
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
|
|
@@ -486,11 +482,6 @@ interface CommonConfig<TAG extends string = string> {
|
|
|
486
482
|
* @see defaultInputSources
|
|
487
483
|
*/
|
|
488
484
|
inputSources?: Partial<InputSources>;
|
|
489
|
-
/**
|
|
490
|
-
* @desc Optional endpoints tagging configuration.
|
|
491
|
-
* @example: { users: "Everything about the users" }
|
|
492
|
-
*/
|
|
493
|
-
tags?: TagsConfig<TAG>;
|
|
494
485
|
}
|
|
495
486
|
type BeforeUpload = (params: {
|
|
496
487
|
request: Request;
|
|
@@ -538,7 +529,7 @@ interface HttpsConfig extends HttpConfig {
|
|
|
538
529
|
/** @desc At least "cert" and "key" options required. */
|
|
539
530
|
options: ServerOptions;
|
|
540
531
|
}
|
|
541
|
-
interface ServerConfig
|
|
532
|
+
interface ServerConfig extends CommonConfig {
|
|
542
533
|
/** @desc HTTP server configuration. */
|
|
543
534
|
http?: HttpConfig;
|
|
544
535
|
/** @desc HTTPS server configuration. */
|
|
@@ -581,17 +572,27 @@ interface ServerConfig<TAG extends string = string> extends CommonConfig<TAG> {
|
|
|
581
572
|
* */
|
|
582
573
|
gracefulShutdown?: boolean | GracefulOptions;
|
|
583
574
|
}
|
|
584
|
-
interface AppConfig
|
|
575
|
+
interface AppConfig extends CommonConfig {
|
|
585
576
|
/** @desc Your custom express app or express router instead. */
|
|
586
577
|
app: IRouter;
|
|
587
578
|
}
|
|
588
|
-
declare function createConfig
|
|
589
|
-
declare function createConfig
|
|
579
|
+
declare function createConfig(config: ServerConfig): ServerConfig;
|
|
580
|
+
declare function createConfig(config: AppConfig): AppConfig;
|
|
590
581
|
|
|
591
582
|
/** @desc this type does not allow props assignment, but it works for reading them when merged with another interface */
|
|
592
583
|
type EmptyObject = Record<string, never>;
|
|
593
584
|
type EmptySchema = z.ZodObject<EmptyObject, "strip">;
|
|
594
585
|
type FlatObject = Record<string, unknown>;
|
|
586
|
+
/** @link https://stackoverflow.com/a/65492934 */
|
|
587
|
+
type NoNever<T, F> = [T] extends [never] ? F : T;
|
|
588
|
+
/**
|
|
589
|
+
* @desc Using module augmentation approach you can specify tags as the keys of this interface
|
|
590
|
+
* @example declare module "express-zod-api" { interface TagOverrides { users: unknown } }
|
|
591
|
+
* @link https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation
|
|
592
|
+
* */
|
|
593
|
+
interface TagOverrides {
|
|
594
|
+
}
|
|
595
|
+
type Tag = NoNever<keyof TagOverrides, string>;
|
|
595
596
|
declare const getMessageFromError: (error: Error) => string;
|
|
596
597
|
declare const getExamples: <T extends z.ZodTypeAny, V extends "original" | "parsed" | undefined>({ schema, variant, validate, }: {
|
|
597
598
|
schema: T;
|
|
@@ -655,7 +656,7 @@ declare module "zod" {
|
|
|
655
656
|
}
|
|
656
657
|
}
|
|
657
658
|
|
|
658
|
-
interface BuildProps<IN extends IOSchema, OUT extends IOSchema | z.ZodVoid, MIN extends IOSchema<"strip">, OPT extends FlatObject, SCO extends string
|
|
659
|
+
interface BuildProps<IN extends IOSchema, OUT extends IOSchema | z.ZodVoid, MIN extends IOSchema<"strip">, OPT extends FlatObject, SCO extends string> {
|
|
659
660
|
input?: IN;
|
|
660
661
|
output: OUT;
|
|
661
662
|
handler: Handler<z.output<z.ZodIntersection<MIN, IN>>, z.input<OUT>, OPT>;
|
|
@@ -664,37 +665,31 @@ interface BuildProps<IN extends IOSchema, OUT extends IOSchema | z.ZodVoid, MIN
|
|
|
664
665
|
operationId?: string | ((method: Method) => string);
|
|
665
666
|
method?: Method | [Method, ...Method[]];
|
|
666
667
|
scope?: SCO | SCO[];
|
|
667
|
-
tag?:
|
|
668
|
+
tag?: Tag | Tag[];
|
|
668
669
|
}
|
|
669
|
-
declare class EndpointsFactory<IN extends IOSchema<"strip"> = EmptySchema, OUT extends FlatObject = EmptyObject, SCO extends string = string
|
|
670
|
+
declare class EndpointsFactory<IN extends IOSchema<"strip"> = EmptySchema, OUT extends FlatObject = EmptyObject, SCO extends string = string> {
|
|
670
671
|
#private;
|
|
671
672
|
protected resultHandler: AbstractResultHandler;
|
|
672
673
|
protected middlewares: AbstractMiddleware[];
|
|
673
|
-
/** @desc Consider using the "config" prop with the "tags" option to enforce constraints on tagging the endpoints */
|
|
674
674
|
constructor(resultHandler: AbstractResultHandler);
|
|
675
|
-
|
|
676
|
-
constructor(params: {
|
|
677
|
-
resultHandler: AbstractResultHandler;
|
|
678
|
-
config?: CommonConfig<TAG>;
|
|
679
|
-
});
|
|
680
|
-
addMiddleware<AOUT extends FlatObject, ASCO extends string, AIN extends IOSchema<"strip"> = EmptySchema>(subject: Middleware<OUT, AOUT, ASCO, AIN> | ConstructorParameters<typeof Middleware<OUT, AOUT, ASCO, AIN>>[0]): EndpointsFactory<z.ZodIntersection<IN, AIN>, OUT & AOUT, SCO & ASCO, TAG>;
|
|
675
|
+
addMiddleware<AOUT extends FlatObject, ASCO extends string, AIN extends IOSchema<"strip"> = EmptySchema>(subject: Middleware<OUT, AOUT, ASCO, AIN> | ConstructorParameters<typeof Middleware<OUT, AOUT, ASCO, AIN>>[0]): EndpointsFactory<z.ZodIntersection<IN, AIN>, OUT & AOUT, SCO & ASCO>;
|
|
681
676
|
use: <R extends Request, S extends Response, AOUT extends FlatObject = EmptyObject>(nativeMw: (request: R, response: S, next: express.NextFunction) => void | Promise<void>, params_1?: {
|
|
682
677
|
provider?: ((request: R, response: S) => AOUT | Promise<AOUT>) | undefined;
|
|
683
678
|
transformer?: (err: Error) => Error;
|
|
684
|
-
} | undefined) => EndpointsFactory<IN, OUT & AOUT, SCO
|
|
685
|
-
addExpressMiddleware<R extends Request, S extends Response, AOUT extends FlatObject = EmptyObject>(...params: ConstructorParameters<typeof ExpressMiddleware<R, S, AOUT>>): EndpointsFactory<IN, OUT & AOUT, SCO
|
|
686
|
-
addOptions<AOUT extends FlatObject>(getOptions: () => Promise<AOUT>): EndpointsFactory<IN, OUT & AOUT, SCO
|
|
687
|
-
build<BOUT extends IOSchema, BIN extends IOSchema = EmptySchema>({ input, handler, output: outputSchema, description, shortDescription, operationId, scope, tag, method, }: BuildProps<BIN, BOUT, IN, OUT, SCO
|
|
679
|
+
} | undefined) => EndpointsFactory<IN, OUT & AOUT, SCO>;
|
|
680
|
+
addExpressMiddleware<R extends Request, S extends Response, AOUT extends FlatObject = EmptyObject>(...params: ConstructorParameters<typeof ExpressMiddleware<R, S, AOUT>>): EndpointsFactory<IN, OUT & AOUT, SCO>;
|
|
681
|
+
addOptions<AOUT extends FlatObject>(getOptions: () => Promise<AOUT>): EndpointsFactory<IN, OUT & AOUT, SCO>;
|
|
682
|
+
build<BOUT extends IOSchema, BIN extends IOSchema = EmptySchema>({ input, handler, output: outputSchema, description, shortDescription, operationId, scope, tag, method, }: BuildProps<BIN, BOUT, IN, OUT, SCO>): Endpoint<z.ZodIntersection<IN, BIN>, BOUT, OUT>;
|
|
688
683
|
/** @desc shorthand for returning {} while having output schema z.object({}) */
|
|
689
|
-
buildVoid<BIN extends IOSchema = EmptySchema>({ handler, ...rest }: Omit<BuildProps<BIN, z.ZodVoid, IN, OUT, SCO
|
|
684
|
+
buildVoid<BIN extends IOSchema = EmptySchema>({ handler, ...rest }: Omit<BuildProps<BIN, z.ZodVoid, IN, OUT, SCO>, "output">): Endpoint<z.ZodIntersection<IN, BIN>, z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>, OUT>;
|
|
690
685
|
}
|
|
691
|
-
declare const defaultEndpointsFactory: EndpointsFactory<EmptySchema, EmptyObject, string
|
|
686
|
+
declare const defaultEndpointsFactory: EndpointsFactory<EmptySchema, EmptyObject, string>;
|
|
692
687
|
/**
|
|
693
688
|
* @deprecated Resist the urge of using it: this factory is designed only to simplify the migration of legacy APIs.
|
|
694
689
|
* @desc Responding with array is a bad practice keeping your endpoints from evolving without breaking changes.
|
|
695
690
|
* @desc The result handler of this factory expects your endpoint to have the property 'items' in the output schema
|
|
696
691
|
*/
|
|
697
|
-
declare const arrayEndpointsFactory: EndpointsFactory<EmptySchema, EmptyObject, string
|
|
692
|
+
declare const arrayEndpointsFactory: EndpointsFactory<EmptySchema, EmptyObject, string>;
|
|
698
693
|
|
|
699
694
|
declare const attachRouting: (config: AppConfig, routing: Routing) => {
|
|
700
695
|
notFoundHandler: express__default.RequestHandler<express_serve_static_core.ParamsDictionary, any, any, qs.ParsedQs, Record<string, any>>;
|
|
@@ -752,6 +747,10 @@ interface OpenAPIContext extends FlatObject {
|
|
|
752
747
|
method: Method;
|
|
753
748
|
}
|
|
754
749
|
type Depicter = SchemaHandler<SchemaObject | ReferenceObject, OpenAPIContext>;
|
|
750
|
+
declare const depictTags: (tags: Partial<Record<Tag, string | {
|
|
751
|
+
description: string;
|
|
752
|
+
url?: string;
|
|
753
|
+
}>>) => TagObject[];
|
|
755
754
|
|
|
756
755
|
type Component = "positiveResponse" | "negativeResponse" | "requestParameter" | "requestBody";
|
|
757
756
|
/** @desc user defined function that creates a component description from its properties */
|
|
@@ -781,6 +780,12 @@ interface DocumentationParams {
|
|
|
781
780
|
* @example { MyBrand: ( schema: typeof myBrandSchema, { next } ) => ({ type: "object" })
|
|
782
781
|
*/
|
|
783
782
|
brandHandling?: HandlingRules<SchemaObject | ReferenceObject, OpenAPIContext>;
|
|
783
|
+
/**
|
|
784
|
+
* @desc Extended description of tags used in endpoints. For enforcing constraints:
|
|
785
|
+
* @see TagOverrides
|
|
786
|
+
* @example { users: "About users", files: { description: "About files", url: "https://example.com" } }
|
|
787
|
+
* */
|
|
788
|
+
tags?: Parameters<typeof depictTags>[0];
|
|
784
789
|
}
|
|
785
790
|
declare class Documentation extends OpenApiBuilder {
|
|
786
791
|
protected lastSecuritySchemaIds: Map<SecuritySchemeType, number>;
|
|
@@ -789,7 +794,7 @@ declare class Documentation extends OpenApiBuilder {
|
|
|
789
794
|
protected makeRef(schema: z.ZodTypeAny, subject: SchemaObject | ReferenceObject | (() => SchemaObject | ReferenceObject), name?: string | undefined): ReferenceObject;
|
|
790
795
|
protected ensureUniqOperationId(path: string, method: Method, userDefined?: string): string;
|
|
791
796
|
protected ensureUniqSecuritySchemaName(subject: SecuritySchemeObject): string;
|
|
792
|
-
constructor({ routing, config, title, version, serverUrl, descriptions, brandHandling, hasSummaryFromDescription, composition, }: DocumentationParams);
|
|
797
|
+
constructor({ routing, config, title, version, serverUrl, descriptions, brandHandling, tags, hasSummaryFromDescription, composition, }: DocumentationParams);
|
|
793
798
|
}
|
|
794
799
|
|
|
795
800
|
/** @desc An error related to the wrong Routing declaration */
|
|
@@ -1023,12 +1028,8 @@ interface Emitter<E extends EventsMap> extends FlatObject {
|
|
|
1023
1028
|
/** @desc Sends an event to the stream accordin to the declared schema */
|
|
1024
1029
|
emit: <K extends keyof E>(event: K, data: z.input<E[K]>) => void;
|
|
1025
1030
|
}
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
constructor({ events, config }: {
|
|
1029
|
-
events: E;
|
|
1030
|
-
config?: CommonConfig<TAG>;
|
|
1031
|
-
});
|
|
1031
|
+
declare class EventStreamFactory<E extends EventsMap> extends EndpointsFactory<EmptySchema, Emitter<E>> {
|
|
1032
|
+
constructor(events: E);
|
|
1032
1033
|
}
|
|
1033
1034
|
|
|
1034
|
-
export { type ApiResponse, type AppConfig, type BasicSecurity, type BearerSecurity, BuiltinLogger, type CommonConfig, type CookieSecurity, type CustomHeaderSecurity, DependsOnMethod, type Depicter, Documentation, DocumentationError, EndpointsFactory, EventStreamFactory, type FlatObject, type IOSchema, type InputSecurity, InputValidationError, Integration, type LoggerOverrides, type Method, Middleware, MissingPeerError, type NormalizedResponse, type OAuth2Security, type OpenIdSecurity, OutputValidationError, type Producer, ResultHandler, type Routing, RoutingError, ServeStatic, type ServerConfig, arrayEndpointsFactory, arrayResultHandler, attachRouting, createConfig, createServer, defaultEndpointsFactory, defaultResultHandler, ensureHttpError, ez, getExamples, getMessageFromError, testEndpoint, testMiddleware };
|
|
1035
|
+
export { type ApiResponse, type AppConfig, type BasicSecurity, type BearerSecurity, BuiltinLogger, type CommonConfig, type CookieSecurity, type CustomHeaderSecurity, DependsOnMethod, type Depicter, Documentation, DocumentationError, EndpointsFactory, EventStreamFactory, type FlatObject, type IOSchema, type InputSecurity, InputValidationError, Integration, type LoggerOverrides, type Method, Middleware, MissingPeerError, type NormalizedResponse, 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, getExamples, getMessageFromError, testEndpoint, testMiddleware };
|
package/dist/index.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ import { ListenOptions } from 'node:net';
|
|
|
12
12
|
import * as qs from 'qs';
|
|
13
13
|
import * as express_serve_static_core from 'express-serve-static-core';
|
|
14
14
|
import http from 'node:http';
|
|
15
|
-
import { SchemaObject, ReferenceObject, OpenApiBuilder, SecuritySchemeType, SecuritySchemeObject } from 'openapi3-ts/oas31';
|
|
15
|
+
import { SchemaObject, ReferenceObject, TagObject, OpenApiBuilder, SecuritySchemeType, SecuritySchemeObject } from 'openapi3-ts/oas31';
|
|
16
16
|
import * as node_mocks_http from 'node-mocks-http';
|
|
17
17
|
import { RequestOptions, ResponseOptions } from 'node-mocks-http';
|
|
18
18
|
import ts from 'typescript';
|
|
@@ -442,15 +442,11 @@ type HeadersProvider = (params: {
|
|
|
442
442
|
endpoint: AbstractEndpoint;
|
|
443
443
|
logger: ActualLogger;
|
|
444
444
|
}) => Headers | Promise<Headers>;
|
|
445
|
-
type TagsConfig<TAG extends string> = Record<TAG, string | {
|
|
446
|
-
description: string;
|
|
447
|
-
url?: string;
|
|
448
|
-
}>;
|
|
449
445
|
type ChildLoggerProvider = (params: {
|
|
450
446
|
request: Request;
|
|
451
447
|
parent: ActualLogger;
|
|
452
448
|
}) => ActualLogger | Promise<ActualLogger>;
|
|
453
|
-
interface CommonConfig
|
|
449
|
+
interface CommonConfig {
|
|
454
450
|
/**
|
|
455
451
|
* @desc Enables cross-origin resource sharing.
|
|
456
452
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
|
|
@@ -486,11 +482,6 @@ interface CommonConfig<TAG extends string = string> {
|
|
|
486
482
|
* @see defaultInputSources
|
|
487
483
|
*/
|
|
488
484
|
inputSources?: Partial<InputSources>;
|
|
489
|
-
/**
|
|
490
|
-
* @desc Optional endpoints tagging configuration.
|
|
491
|
-
* @example: { users: "Everything about the users" }
|
|
492
|
-
*/
|
|
493
|
-
tags?: TagsConfig<TAG>;
|
|
494
485
|
}
|
|
495
486
|
type BeforeUpload = (params: {
|
|
496
487
|
request: Request;
|
|
@@ -538,7 +529,7 @@ interface HttpsConfig extends HttpConfig {
|
|
|
538
529
|
/** @desc At least "cert" and "key" options required. */
|
|
539
530
|
options: ServerOptions;
|
|
540
531
|
}
|
|
541
|
-
interface ServerConfig
|
|
532
|
+
interface ServerConfig extends CommonConfig {
|
|
542
533
|
/** @desc HTTP server configuration. */
|
|
543
534
|
http?: HttpConfig;
|
|
544
535
|
/** @desc HTTPS server configuration. */
|
|
@@ -581,17 +572,27 @@ interface ServerConfig<TAG extends string = string> extends CommonConfig<TAG> {
|
|
|
581
572
|
* */
|
|
582
573
|
gracefulShutdown?: boolean | GracefulOptions;
|
|
583
574
|
}
|
|
584
|
-
interface AppConfig
|
|
575
|
+
interface AppConfig extends CommonConfig {
|
|
585
576
|
/** @desc Your custom express app or express router instead. */
|
|
586
577
|
app: IRouter;
|
|
587
578
|
}
|
|
588
|
-
declare function createConfig
|
|
589
|
-
declare function createConfig
|
|
579
|
+
declare function createConfig(config: ServerConfig): ServerConfig;
|
|
580
|
+
declare function createConfig(config: AppConfig): AppConfig;
|
|
590
581
|
|
|
591
582
|
/** @desc this type does not allow props assignment, but it works for reading them when merged with another interface */
|
|
592
583
|
type EmptyObject = Record<string, never>;
|
|
593
584
|
type EmptySchema = z.ZodObject<EmptyObject, "strip">;
|
|
594
585
|
type FlatObject = Record<string, unknown>;
|
|
586
|
+
/** @link https://stackoverflow.com/a/65492934 */
|
|
587
|
+
type NoNever<T, F> = [T] extends [never] ? F : T;
|
|
588
|
+
/**
|
|
589
|
+
* @desc Using module augmentation approach you can specify tags as the keys of this interface
|
|
590
|
+
* @example declare module "express-zod-api" { interface TagOverrides { users: unknown } }
|
|
591
|
+
* @link https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation
|
|
592
|
+
* */
|
|
593
|
+
interface TagOverrides {
|
|
594
|
+
}
|
|
595
|
+
type Tag = NoNever<keyof TagOverrides, string>;
|
|
595
596
|
declare const getMessageFromError: (error: Error) => string;
|
|
596
597
|
declare const getExamples: <T extends z.ZodTypeAny, V extends "original" | "parsed" | undefined>({ schema, variant, validate, }: {
|
|
597
598
|
schema: T;
|
|
@@ -655,7 +656,7 @@ declare module "zod" {
|
|
|
655
656
|
}
|
|
656
657
|
}
|
|
657
658
|
|
|
658
|
-
interface BuildProps<IN extends IOSchema, OUT extends IOSchema | z.ZodVoid, MIN extends IOSchema<"strip">, OPT extends FlatObject, SCO extends string
|
|
659
|
+
interface BuildProps<IN extends IOSchema, OUT extends IOSchema | z.ZodVoid, MIN extends IOSchema<"strip">, OPT extends FlatObject, SCO extends string> {
|
|
659
660
|
input?: IN;
|
|
660
661
|
output: OUT;
|
|
661
662
|
handler: Handler<z.output<z.ZodIntersection<MIN, IN>>, z.input<OUT>, OPT>;
|
|
@@ -664,37 +665,31 @@ interface BuildProps<IN extends IOSchema, OUT extends IOSchema | z.ZodVoid, MIN
|
|
|
664
665
|
operationId?: string | ((method: Method) => string);
|
|
665
666
|
method?: Method | [Method, ...Method[]];
|
|
666
667
|
scope?: SCO | SCO[];
|
|
667
|
-
tag?:
|
|
668
|
+
tag?: Tag | Tag[];
|
|
668
669
|
}
|
|
669
|
-
declare class EndpointsFactory<IN extends IOSchema<"strip"> = EmptySchema, OUT extends FlatObject = EmptyObject, SCO extends string = string
|
|
670
|
+
declare class EndpointsFactory<IN extends IOSchema<"strip"> = EmptySchema, OUT extends FlatObject = EmptyObject, SCO extends string = string> {
|
|
670
671
|
#private;
|
|
671
672
|
protected resultHandler: AbstractResultHandler;
|
|
672
673
|
protected middlewares: AbstractMiddleware[];
|
|
673
|
-
/** @desc Consider using the "config" prop with the "tags" option to enforce constraints on tagging the endpoints */
|
|
674
674
|
constructor(resultHandler: AbstractResultHandler);
|
|
675
|
-
|
|
676
|
-
constructor(params: {
|
|
677
|
-
resultHandler: AbstractResultHandler;
|
|
678
|
-
config?: CommonConfig<TAG>;
|
|
679
|
-
});
|
|
680
|
-
addMiddleware<AOUT extends FlatObject, ASCO extends string, AIN extends IOSchema<"strip"> = EmptySchema>(subject: Middleware<OUT, AOUT, ASCO, AIN> | ConstructorParameters<typeof Middleware<OUT, AOUT, ASCO, AIN>>[0]): EndpointsFactory<z.ZodIntersection<IN, AIN>, OUT & AOUT, SCO & ASCO, TAG>;
|
|
675
|
+
addMiddleware<AOUT extends FlatObject, ASCO extends string, AIN extends IOSchema<"strip"> = EmptySchema>(subject: Middleware<OUT, AOUT, ASCO, AIN> | ConstructorParameters<typeof Middleware<OUT, AOUT, ASCO, AIN>>[0]): EndpointsFactory<z.ZodIntersection<IN, AIN>, OUT & AOUT, SCO & ASCO>;
|
|
681
676
|
use: <R extends Request, S extends Response, AOUT extends FlatObject = EmptyObject>(nativeMw: (request: R, response: S, next: express.NextFunction) => void | Promise<void>, params_1?: {
|
|
682
677
|
provider?: ((request: R, response: S) => AOUT | Promise<AOUT>) | undefined;
|
|
683
678
|
transformer?: (err: Error) => Error;
|
|
684
|
-
} | undefined) => EndpointsFactory<IN, OUT & AOUT, SCO
|
|
685
|
-
addExpressMiddleware<R extends Request, S extends Response, AOUT extends FlatObject = EmptyObject>(...params: ConstructorParameters<typeof ExpressMiddleware<R, S, AOUT>>): EndpointsFactory<IN, OUT & AOUT, SCO
|
|
686
|
-
addOptions<AOUT extends FlatObject>(getOptions: () => Promise<AOUT>): EndpointsFactory<IN, OUT & AOUT, SCO
|
|
687
|
-
build<BOUT extends IOSchema, BIN extends IOSchema = EmptySchema>({ input, handler, output: outputSchema, description, shortDescription, operationId, scope, tag, method, }: BuildProps<BIN, BOUT, IN, OUT, SCO
|
|
679
|
+
} | undefined) => EndpointsFactory<IN, OUT & AOUT, SCO>;
|
|
680
|
+
addExpressMiddleware<R extends Request, S extends Response, AOUT extends FlatObject = EmptyObject>(...params: ConstructorParameters<typeof ExpressMiddleware<R, S, AOUT>>): EndpointsFactory<IN, OUT & AOUT, SCO>;
|
|
681
|
+
addOptions<AOUT extends FlatObject>(getOptions: () => Promise<AOUT>): EndpointsFactory<IN, OUT & AOUT, SCO>;
|
|
682
|
+
build<BOUT extends IOSchema, BIN extends IOSchema = EmptySchema>({ input, handler, output: outputSchema, description, shortDescription, operationId, scope, tag, method, }: BuildProps<BIN, BOUT, IN, OUT, SCO>): Endpoint<z.ZodIntersection<IN, BIN>, BOUT, OUT>;
|
|
688
683
|
/** @desc shorthand for returning {} while having output schema z.object({}) */
|
|
689
|
-
buildVoid<BIN extends IOSchema = EmptySchema>({ handler, ...rest }: Omit<BuildProps<BIN, z.ZodVoid, IN, OUT, SCO
|
|
684
|
+
buildVoid<BIN extends IOSchema = EmptySchema>({ handler, ...rest }: Omit<BuildProps<BIN, z.ZodVoid, IN, OUT, SCO>, "output">): Endpoint<z.ZodIntersection<IN, BIN>, z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>, OUT>;
|
|
690
685
|
}
|
|
691
|
-
declare const defaultEndpointsFactory: EndpointsFactory<EmptySchema, EmptyObject, string
|
|
686
|
+
declare const defaultEndpointsFactory: EndpointsFactory<EmptySchema, EmptyObject, string>;
|
|
692
687
|
/**
|
|
693
688
|
* @deprecated Resist the urge of using it: this factory is designed only to simplify the migration of legacy APIs.
|
|
694
689
|
* @desc Responding with array is a bad practice keeping your endpoints from evolving without breaking changes.
|
|
695
690
|
* @desc The result handler of this factory expects your endpoint to have the property 'items' in the output schema
|
|
696
691
|
*/
|
|
697
|
-
declare const arrayEndpointsFactory: EndpointsFactory<EmptySchema, EmptyObject, string
|
|
692
|
+
declare const arrayEndpointsFactory: EndpointsFactory<EmptySchema, EmptyObject, string>;
|
|
698
693
|
|
|
699
694
|
declare const attachRouting: (config: AppConfig, routing: Routing) => {
|
|
700
695
|
notFoundHandler: express__default.RequestHandler<express_serve_static_core.ParamsDictionary, any, any, qs.ParsedQs, Record<string, any>>;
|
|
@@ -752,6 +747,10 @@ interface OpenAPIContext extends FlatObject {
|
|
|
752
747
|
method: Method;
|
|
753
748
|
}
|
|
754
749
|
type Depicter = SchemaHandler<SchemaObject | ReferenceObject, OpenAPIContext>;
|
|
750
|
+
declare const depictTags: (tags: Partial<Record<Tag, string | {
|
|
751
|
+
description: string;
|
|
752
|
+
url?: string;
|
|
753
|
+
}>>) => TagObject[];
|
|
755
754
|
|
|
756
755
|
type Component = "positiveResponse" | "negativeResponse" | "requestParameter" | "requestBody";
|
|
757
756
|
/** @desc user defined function that creates a component description from its properties */
|
|
@@ -781,6 +780,12 @@ interface DocumentationParams {
|
|
|
781
780
|
* @example { MyBrand: ( schema: typeof myBrandSchema, { next } ) => ({ type: "object" })
|
|
782
781
|
*/
|
|
783
782
|
brandHandling?: HandlingRules<SchemaObject | ReferenceObject, OpenAPIContext>;
|
|
783
|
+
/**
|
|
784
|
+
* @desc Extended description of tags used in endpoints. For enforcing constraints:
|
|
785
|
+
* @see TagOverrides
|
|
786
|
+
* @example { users: "About users", files: { description: "About files", url: "https://example.com" } }
|
|
787
|
+
* */
|
|
788
|
+
tags?: Parameters<typeof depictTags>[0];
|
|
784
789
|
}
|
|
785
790
|
declare class Documentation extends OpenApiBuilder {
|
|
786
791
|
protected lastSecuritySchemaIds: Map<SecuritySchemeType, number>;
|
|
@@ -789,7 +794,7 @@ declare class Documentation extends OpenApiBuilder {
|
|
|
789
794
|
protected makeRef(schema: z.ZodTypeAny, subject: SchemaObject | ReferenceObject | (() => SchemaObject | ReferenceObject), name?: string | undefined): ReferenceObject;
|
|
790
795
|
protected ensureUniqOperationId(path: string, method: Method, userDefined?: string): string;
|
|
791
796
|
protected ensureUniqSecuritySchemaName(subject: SecuritySchemeObject): string;
|
|
792
|
-
constructor({ routing, config, title, version, serverUrl, descriptions, brandHandling, hasSummaryFromDescription, composition, }: DocumentationParams);
|
|
797
|
+
constructor({ routing, config, title, version, serverUrl, descriptions, brandHandling, tags, hasSummaryFromDescription, composition, }: DocumentationParams);
|
|
793
798
|
}
|
|
794
799
|
|
|
795
800
|
/** @desc An error related to the wrong Routing declaration */
|
|
@@ -1023,12 +1028,8 @@ interface Emitter<E extends EventsMap> extends FlatObject {
|
|
|
1023
1028
|
/** @desc Sends an event to the stream accordin to the declared schema */
|
|
1024
1029
|
emit: <K extends keyof E>(event: K, data: z.input<E[K]>) => void;
|
|
1025
1030
|
}
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
constructor({ events, config }: {
|
|
1029
|
-
events: E;
|
|
1030
|
-
config?: CommonConfig<TAG>;
|
|
1031
|
-
});
|
|
1031
|
+
declare class EventStreamFactory<E extends EventsMap> extends EndpointsFactory<EmptySchema, Emitter<E>> {
|
|
1032
|
+
constructor(events: E);
|
|
1032
1033
|
}
|
|
1033
1034
|
|
|
1034
|
-
export { type ApiResponse, type AppConfig, type BasicSecurity, type BearerSecurity, BuiltinLogger, type CommonConfig, type CookieSecurity, type CustomHeaderSecurity, DependsOnMethod, type Depicter, Documentation, DocumentationError, EndpointsFactory, EventStreamFactory, type FlatObject, type IOSchema, type InputSecurity, InputValidationError, Integration, type LoggerOverrides, type Method, Middleware, MissingPeerError, type NormalizedResponse, type OAuth2Security, type OpenIdSecurity, OutputValidationError, type Producer, ResultHandler, type Routing, RoutingError, ServeStatic, type ServerConfig, arrayEndpointsFactory, arrayResultHandler, attachRouting, createConfig, createServer, defaultEndpointsFactory, defaultResultHandler, ensureHttpError, ez, getExamples, getMessageFromError, testEndpoint, testMiddleware };
|
|
1035
|
+
export { type ApiResponse, type AppConfig, type BasicSecurity, type BearerSecurity, BuiltinLogger, type CommonConfig, type CookieSecurity, type CustomHeaderSecurity, DependsOnMethod, type Depicter, Documentation, DocumentationError, EndpointsFactory, EventStreamFactory, type FlatObject, type IOSchema, type InputSecurity, InputValidationError, Integration, type LoggerOverrides, type Method, Middleware, MissingPeerError, type NormalizedResponse, 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, getExamples, getMessageFromError, testEndpoint, testMiddleware };
|