balda 0.0.57 → 0.0.59
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/lib/cli.js +35 -35
- package/lib/cli.js.map +1 -1
- package/lib/index.cjs +66 -66
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +186 -29
- package/lib/index.d.ts +186 -29
- package/lib/index.js +66 -66
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/lib/index.d.cts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { JSONSchema as JSONSchema$1, FromSchema } from 'json-schema-to-ts';
|
|
2
|
-
import { Ajv } from 'ajv';
|
|
2
|
+
import { Ajv, ErrorObject } from 'ajv';
|
|
3
|
+
export { ErrorObject, ValidationError } from 'ajv';
|
|
3
4
|
import { IncomingMessage, ServerResponse, Server as Server$2 } from 'node:http';
|
|
4
5
|
import { schedule, TaskContext } from 'node-cron';
|
|
5
6
|
import { Http2Server } from 'node:http2';
|
|
@@ -869,6 +870,18 @@ declare const flag: {
|
|
|
869
870
|
*/
|
|
870
871
|
type SwaggerUIType = "standard" | "rapidoc" | "scalar" | "elements" | "custom";
|
|
871
872
|
type HTMLString = string;
|
|
873
|
+
/**
|
|
874
|
+
* Configuration for validation error response documentation.
|
|
875
|
+
* Used to document validation errors in Swagger when routes have validation schemas.
|
|
876
|
+
*/
|
|
877
|
+
type ValidationErrorResponseOptions = {
|
|
878
|
+
/** HTTP status code for validation errors. Default: 422 */
|
|
879
|
+
statusCode?: number;
|
|
880
|
+
/** Response description. Default: "Validation error" */
|
|
881
|
+
description?: string;
|
|
882
|
+
/** Response schema for the error body. Default: { type: "object", properties: { message: { type: "string" }, errors: { type: "array", items: { type: "object", properties: { instancePath: { type: "string" }, schemaPath: { type: "string" }, keyword: { type: "string" }, params: { type: "object" }, message: { type: "string" } } } }, ajv: { type: "boolean" }, validation: { type: "boolean" } } } */
|
|
883
|
+
schema?: JSONSchema;
|
|
884
|
+
};
|
|
872
885
|
/**
|
|
873
886
|
* Custom UI generator function that takes the spec URL and global options and returns HTML
|
|
874
887
|
*/
|
|
@@ -951,6 +964,13 @@ type SwaggerGlobalOptionsBase = {
|
|
|
951
964
|
* OpenAPI models to be shown in the documentation. Must be valid OpenAPI/AJV JSONSchema objects.
|
|
952
965
|
*/
|
|
953
966
|
models?: Record<string, JSONSchema> | JSONSchema[];
|
|
967
|
+
/**
|
|
968
|
+
* Global configuration for validation error response documentation.
|
|
969
|
+
* Applied to all routes that have validation schemas (body, query, headers, or all).
|
|
970
|
+
* Can be overridden per-route via swagger.validationErrorResponse.
|
|
971
|
+
* Default: { statusCode: 422, description: "Validation error" }
|
|
972
|
+
*/
|
|
973
|
+
validationErrorResponse?: ValidationErrorResponseOptions;
|
|
954
974
|
};
|
|
955
975
|
/**
|
|
956
976
|
* Global documentation options for the API (OpenAPI/Swagger style)
|
|
@@ -998,6 +1018,12 @@ type SwaggerRouteOptions = {
|
|
|
998
1018
|
* Defaults to 'json'.
|
|
999
1019
|
*/
|
|
1000
1020
|
bodyType?: SwaggerBodyType;
|
|
1021
|
+
/**
|
|
1022
|
+
* Override the global validation error response for this route.
|
|
1023
|
+
* Only applies when the route has validation schemas (body, query, headers, or all).
|
|
1024
|
+
* Overrides swagger global validationErrorResponse configuration.
|
|
1025
|
+
*/
|
|
1026
|
+
validationErrorResponse?: ValidationErrorResponseOptions;
|
|
1001
1027
|
};
|
|
1002
1028
|
type OAuth2Flows = {
|
|
1003
1029
|
implicit?: OAuth2Flow;
|
|
@@ -1378,6 +1404,7 @@ declare class Response$1<TResponseMap extends Record<number, any> = Record<numbe
|
|
|
1378
1404
|
}
|
|
1379
1405
|
|
|
1380
1406
|
/**
|
|
1407
|
+
* @deprecated use directly router.delete() instead, this is just a wrapper for backward compatibility and might be removed in future versions
|
|
1381
1408
|
* Decorator to mark a handler for a DELETE request with type-safe path parameters and response body
|
|
1382
1409
|
* DELETE requests cannot have a request body (by HTTP spec)
|
|
1383
1410
|
* Query params must be validated with @validate decorators to be typed
|
|
@@ -1406,6 +1433,7 @@ declare class Response$1<TResponseMap extends Record<number, any> = Record<numbe
|
|
|
1406
1433
|
declare const del: <TPath extends string = string>(path: TPath, options?: SwaggerRouteOptions) => <T extends (req: Request<ExtractParams<TPath>>, res: Response$1, ...args: any[]) => any>(target: any, propertyKey: string, descriptor: PropertyDescriptor) => TypedPropertyDescriptor<T>;
|
|
1407
1434
|
|
|
1408
1435
|
/**
|
|
1436
|
+
* @deprecated use directly router.get() instead, this is just a wrapper for backward compatibility and might be removed in future versions
|
|
1409
1437
|
* Decorator to mark a handler for a GET request with type-safe path parameters and response body
|
|
1410
1438
|
* GET requests cannot have a request body (by HTTP spec)
|
|
1411
1439
|
* Body and query must be validated with @validate decorators to be typed
|
|
@@ -1440,6 +1468,7 @@ declare const del: <TPath extends string = string>(path: TPath, options?: Swagge
|
|
|
1440
1468
|
declare const get: <TPath extends string = string>(path: TPath, options?: SwaggerRouteOptions) => <T extends (req: Request<ExtractParams<TPath>>, res: Response$1, ...args: any[]) => any>(target: any, propertyKey: string, descriptor: PropertyDescriptor) => TypedPropertyDescriptor<T>;
|
|
1441
1469
|
|
|
1442
1470
|
/**
|
|
1471
|
+
* @deprecated use directly router.post() instead, this is just a wrapper for backward compatibility and might be removed in future versions
|
|
1443
1472
|
* Decorator to mark a handler for a PATCH request with type-safe path parameters and response body
|
|
1444
1473
|
* Body and query must be validated with @validate decorators to be typed
|
|
1445
1474
|
* @param path - The path of the route (path parameters will be automatically inferred)
|
|
@@ -1472,6 +1501,7 @@ declare const get: <TPath extends string = string>(path: TPath, options?: Swagge
|
|
|
1472
1501
|
declare const patch: <TPath extends string = string>(path: TPath, options?: SwaggerRouteOptions) => <T extends (req: Request<ExtractParams<TPath>>, res: Response$1, ...args: any[]) => any>(target: any, propertyKey: string, descriptor: PropertyDescriptor) => TypedPropertyDescriptor<T>;
|
|
1473
1502
|
|
|
1474
1503
|
/**
|
|
1504
|
+
* @deprecated use directly router.post() instead, this is just a wrapper for backward compatibility and might be removed in future versions
|
|
1475
1505
|
* Decorator to mark a handler for a POST request with type-safe path parameters and response body
|
|
1476
1506
|
* Body and query must be validated with @validate decorators to be typed
|
|
1477
1507
|
* @param path - The path of the route (path parameters will be automatically inferred)
|
|
@@ -1504,6 +1534,7 @@ declare const patch: <TPath extends string = string>(path: TPath, options?: Swag
|
|
|
1504
1534
|
declare const post: <TPath extends string = string>(path: TPath, options?: SwaggerRouteOptions) => <T extends (req: Request<ExtractParams<TPath>>, res: Response$1, ...args: any[]) => any>(target: any, propertyKey: string, descriptor: PropertyDescriptor) => TypedPropertyDescriptor<T>;
|
|
1505
1535
|
|
|
1506
1536
|
/**
|
|
1537
|
+
* @deprecated use directly router.post() instead, this is just a wrapper for backward compatibility and might be removed in future versions
|
|
1507
1538
|
* Decorator to mark a handler for a PUT request with type-safe path parameters and response body
|
|
1508
1539
|
* Body and query must be validated with @validate decorators to be typed
|
|
1509
1540
|
* @param path - The path of the route (path parameters will be automatically inferred)
|
|
@@ -1710,7 +1741,7 @@ type InferMiddlewareExtensions<T extends readonly any[]> = T extends readonly [i
|
|
|
1710
1741
|
*/
|
|
1711
1742
|
interface GroupRouter<TGroupExt extends Record<string, any> = Record<string, never>> {
|
|
1712
1743
|
get<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath, Record<number, RequestSchema>, unknown, unknown, unknown, unknown, TGroupExt>): void;
|
|
1713
|
-
get<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>,
|
|
1744
|
+
get<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TQuery extends RequestSchema | undefined = undefined, THeaders extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: BodylessMethodOptions<TResponses, TQuery, THeaders, TPath, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, unknown, TQuery, THeaders, unknown, TGroupExt & InferMiddlewareExtensions<TMiddlewares>>): void;
|
|
1714
1745
|
post<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath, Record<number, RequestSchema>, unknown, unknown, unknown, unknown, TGroupExt>): void;
|
|
1715
1746
|
post<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, THeaders extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, THeaders, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, THeaders, TAll, TGroupExt & InferMiddlewareExtensions<TMiddlewares>>): void;
|
|
1716
1747
|
patch<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath, Record<number, RequestSchema>, unknown, unknown, unknown, unknown, TGroupExt>): void;
|
|
@@ -1718,7 +1749,7 @@ interface GroupRouter<TGroupExt extends Record<string, any> = Record<string, nev
|
|
|
1718
1749
|
put<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath, Record<number, RequestSchema>, unknown, unknown, unknown, unknown, TGroupExt>): void;
|
|
1719
1750
|
put<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, THeaders extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, THeaders, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, THeaders, TAll, TGroupExt & InferMiddlewareExtensions<TMiddlewares>>): void;
|
|
1720
1751
|
delete<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath, Record<number, RequestSchema>, unknown, unknown, unknown, unknown, TGroupExt>): void;
|
|
1721
|
-
delete<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>,
|
|
1752
|
+
delete<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TQuery extends RequestSchema | undefined = undefined, THeaders extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: BodylessMethodOptions<TResponses, TQuery, THeaders, TPath, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, unknown, TQuery, THeaders, unknown, TGroupExt & InferMiddlewareExtensions<TMiddlewares>>): void;
|
|
1722
1753
|
options<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath, Record<number, RequestSchema>, unknown, unknown, unknown, unknown, TGroupExt>): void;
|
|
1723
1754
|
options<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, THeaders extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, THeaders, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, THeaders, TAll, TGroupExt & InferMiddlewareExtensions<TMiddlewares>>): void;
|
|
1724
1755
|
head<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath, Record<number, RequestSchema>, unknown, unknown, unknown, unknown, TGroupExt>): void;
|
|
@@ -1776,9 +1807,10 @@ declare class Router {
|
|
|
1776
1807
|
private extractOptionsAndHandler;
|
|
1777
1808
|
/**
|
|
1778
1809
|
* Register a GET route under this router's base path with type-safe path parameters.
|
|
1810
|
+
* Note: GET routes cannot have body validation per HTTP specification.
|
|
1779
1811
|
*/
|
|
1780
1812
|
get<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath>): void;
|
|
1781
|
-
get<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>,
|
|
1813
|
+
get<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TQuery extends RequestSchema | undefined = undefined, THeaders extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: BodylessMethodOptions<TResponses, TQuery, THeaders, TPath, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, unknown, TQuery, THeaders, unknown, InferMiddlewareExtensions<TMiddlewares>>): void;
|
|
1782
1814
|
/**
|
|
1783
1815
|
* Register a POST route under this router's base path with type-safe path parameters.
|
|
1784
1816
|
*/
|
|
@@ -1796,9 +1828,10 @@ declare class Router {
|
|
|
1796
1828
|
put<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | undefined = undefined, TQuery extends RequestSchema | undefined = undefined, THeaders extends RequestSchema | undefined = undefined, TAll extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: StandardMethodOptions<TResponses, TBody, TQuery, THeaders, TPath, TAll, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, TBody, TQuery, THeaders, TAll, InferMiddlewareExtensions<TMiddlewares>>): void;
|
|
1797
1829
|
/**
|
|
1798
1830
|
* Register a DELETE route under this router's base path with type-safe path parameters.
|
|
1831
|
+
* Note: DELETE routes cannot have body validation per HTTP specification.
|
|
1799
1832
|
*/
|
|
1800
1833
|
delete<TPath extends string = string>(path: TPath, handler: ControllerHandler<TPath>): void;
|
|
1801
|
-
delete<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>,
|
|
1834
|
+
delete<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TQuery extends RequestSchema | undefined = undefined, THeaders extends RequestSchema | undefined = undefined, const TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]>(path: TPath, options: BodylessMethodOptions<TResponses, TQuery, THeaders, TPath, TMiddlewares>, handler: ControllerHandler<TPath, TResponses, unknown, TQuery, THeaders, unknown, InferMiddlewareExtensions<TMiddlewares>>): void;
|
|
1802
1835
|
/**
|
|
1803
1836
|
* Register an OPTIONS route under this router's base path with type-safe path parameters.
|
|
1804
1837
|
*/
|
|
@@ -1871,16 +1904,65 @@ interface Route {
|
|
|
1871
1904
|
type ClientRouter = Omit<Router, "applyGlobalMiddlewaresToAllRoutes" | "addOrUpdate">;
|
|
1872
1905
|
|
|
1873
1906
|
/**
|
|
1874
|
-
*
|
|
1875
|
-
*
|
|
1907
|
+
* Configuration for custom policy error handling.
|
|
1908
|
+
* Replaces the default 401 response with a custom status and body shape.
|
|
1909
|
+
*
|
|
1910
|
+
* @template T - The schema type (Zod, TypeBox, or JSON Schema). When provided,
|
|
1911
|
+
* the map function return type is inferred as ValidatedData<T>.
|
|
1876
1912
|
*/
|
|
1877
|
-
|
|
1913
|
+
interface PolicyErrorHandlerOptions<T extends RequestSchema = RequestSchema> {
|
|
1914
|
+
/** HTTP status code for the response. Default: 401 */
|
|
1915
|
+
status?: number;
|
|
1916
|
+
/**
|
|
1917
|
+
* Zod/TypeBox/JSON schema for the response body.
|
|
1918
|
+
* Used for Swagger documentation and type inference for map return type.
|
|
1919
|
+
*/
|
|
1920
|
+
schema?: T;
|
|
1921
|
+
/**
|
|
1922
|
+
* Transform policy error to your custom response shape.
|
|
1923
|
+
* Required if schema is provided.
|
|
1924
|
+
* @param req - The request object (for path, method, headers, user, etc.)
|
|
1925
|
+
* @returns The response body to send. When schema is provided, return type is ValidatedData<T>.
|
|
1926
|
+
* Can be async (return Promise) for asynchronous transformations.
|
|
1927
|
+
*/
|
|
1928
|
+
map?: (req: Request) => ValidatedData<T> | Promise<ValidatedData<T>>;
|
|
1929
|
+
}
|
|
1878
1930
|
|
|
1879
1931
|
/**
|
|
1880
|
-
*
|
|
1881
|
-
*
|
|
1932
|
+
* The serialized validation error object passed to the map function.
|
|
1933
|
+
* This is the JSON-serializable shape of AJV's ValidationError.
|
|
1934
|
+
*/
|
|
1935
|
+
interface SerializedValidationError {
|
|
1936
|
+
message: string;
|
|
1937
|
+
errors: ErrorObject[];
|
|
1938
|
+
ajv: true;
|
|
1939
|
+
validation: true;
|
|
1940
|
+
}
|
|
1941
|
+
/**
|
|
1942
|
+
* Configuration for custom validation error handling.
|
|
1943
|
+
* Replaces the default 422 response with a custom status and body shape.
|
|
1944
|
+
*
|
|
1945
|
+
* @template T - The schema type (Zod, TypeBox, or JSON Schema). When provided,
|
|
1946
|
+
* the map function return type is inferred as ValidatedData<T>.
|
|
1882
1947
|
*/
|
|
1883
|
-
|
|
1948
|
+
interface ValidationErrorHandlerOptions<T extends RequestSchema = RequestSchema> {
|
|
1949
|
+
/** HTTP status code for the response. Default: 422 */
|
|
1950
|
+
status?: number;
|
|
1951
|
+
/**
|
|
1952
|
+
* Zod/TypeBox/JSON schema for the response body.
|
|
1953
|
+
* Used for Swagger documentation and type inference for map return type.
|
|
1954
|
+
*/
|
|
1955
|
+
schema?: T;
|
|
1956
|
+
/**
|
|
1957
|
+
* Transform AJV errors to your custom response shape.
|
|
1958
|
+
* Required if schema is provided.
|
|
1959
|
+
* @param error - The validation error object with AJV ErrorObject array
|
|
1960
|
+
* @param req - The request object (for path, method, headers, etc.)
|
|
1961
|
+
* @returns The response body to send. When schema is provided, return type is ValidatedData<T>.
|
|
1962
|
+
* Can be async (return Promise) for asynchronous transformations.
|
|
1963
|
+
*/
|
|
1964
|
+
map?: (error: SerializedValidationError, req: Request) => ValidatedData<T> | Promise<ValidatedData<T>>;
|
|
1965
|
+
}
|
|
1884
1966
|
|
|
1885
1967
|
/**
|
|
1886
1968
|
* The server class that is used to create and manage the server
|
|
@@ -1902,9 +1984,12 @@ declare class Server<H extends NodeHttpClient = NodeHttpClient> implements Serve
|
|
|
1902
1984
|
* @param options.host - The hostname to listen on, if not provided, it will use the HOST environment variable, if not provided, it will default to 0.0.0.0
|
|
1903
1985
|
* @param options.controllerPatterns - The patterns to match for controllers, defaults to an empty array
|
|
1904
1986
|
* @param options.plugins - The plugins to apply to the server, by default no plugins are applied, plugins are applied in the order they are defined in the options
|
|
1905
|
-
* @param options.logger - The logger to use for the server, by default a default logger is used
|
|
1987
|
+
* @param options.logger - The pino logger to use for the server, by default a default logger is used
|
|
1906
1988
|
* @param options.tapOptions - Options fetch to the runtime server before the server is up and running
|
|
1907
1989
|
* @param options.abortSignal - An optional AbortSignal to gracefully shutdown the server when aborted
|
|
1990
|
+
* @param options.ajvInstance - An optional AJV instance to use for validation, if not provided, a default instance will be used
|
|
1991
|
+
* @param options.nodeHttpClient - The node http client to use, it can be "http", "https" or "http2-secure", by default it's "http", if you set it to "https" or "http2-secure" you must also provide the httpsOptions
|
|
1992
|
+
* @param options.httpsOptions - The https options to use if the nodeHttpClient is set to "https" or "http2-secure"
|
|
1908
1993
|
*/
|
|
1909
1994
|
constructor(options?: ServerOptions<H>);
|
|
1910
1995
|
get protectedKeys(): string[];
|
|
@@ -1934,13 +2019,13 @@ declare class Server<H extends NodeHttpClient = NodeHttpClient> implements Serve
|
|
|
1934
2019
|
mountExpressRouter(basePath: string, expressRouter: Router$1): void;
|
|
1935
2020
|
setErrorHandler(errorHandler?: ServerErrorHandler): void;
|
|
1936
2021
|
setNotFoundHandler(notFoundHandler?: ServerRouteHandler): void;
|
|
1937
|
-
setValidationErrorHandler(
|
|
1938
|
-
setPolicyErrorHandler(
|
|
2022
|
+
setValidationErrorHandler<T extends RequestSchema>(options: ValidationErrorHandlerOptions<T>): void;
|
|
2023
|
+
setPolicyErrorHandler<T extends RequestSchema>(options: PolicyErrorHandlerOptions<T>): void;
|
|
1939
2024
|
beforeStart(hook: ServerHook): void;
|
|
1940
2025
|
beforeClose(hook: ServerHook): void;
|
|
1941
2026
|
listen(cb?: ServerListenCallback): void;
|
|
1942
2027
|
listen(port: number, cb?: ServerListenCallback): void;
|
|
1943
|
-
waitUntilListening(): Promise<{
|
|
2028
|
+
waitUntilListening(port?: number): Promise<{
|
|
1944
2029
|
port: number;
|
|
1945
2030
|
host: string;
|
|
1946
2031
|
url: string;
|
|
@@ -1990,10 +2075,14 @@ declare class MockResponse<T = any> {
|
|
|
1990
2075
|
body(): T;
|
|
1991
2076
|
statusCode(): number;
|
|
1992
2077
|
headers(): Record<string, string>;
|
|
2078
|
+
cookies(): Record<string, string>;
|
|
1993
2079
|
assertStatus(status: number): this;
|
|
1994
2080
|
assertHeader(header: string, value: string): this;
|
|
1995
2081
|
assertHeaderExists(header: string): this;
|
|
1996
2082
|
assertHeaderNotExists(header: string): this;
|
|
2083
|
+
assertCookie(name: string, value: string): this;
|
|
2084
|
+
assertCookieExists(name: string): this;
|
|
2085
|
+
assertCookieNotExists(name: string): this;
|
|
1997
2086
|
assertBodySubset(subset: Partial<T>): this;
|
|
1998
2087
|
assertBodyDeepEqual(expected: T): this;
|
|
1999
2088
|
assertBodyNotSubset(subset: Partial<T>): this;
|
|
@@ -2728,28 +2817,83 @@ interface ServerInterface {
|
|
|
2728
2817
|
setNotFoundHandler: (notFoundHandler?: ServerRouteHandler) => void;
|
|
2729
2818
|
/**
|
|
2730
2819
|
* Set a custom handler for validation errors (body/query validation failures).
|
|
2731
|
-
*
|
|
2732
|
-
*
|
|
2733
|
-
*
|
|
2820
|
+
* Replaces the default 422 response with a custom status and body shape.
|
|
2821
|
+
*
|
|
2822
|
+
* The 'map' function is required when 'schema' is provided.
|
|
2823
|
+
* The schema is used for Swagger documentation, 'map' transforms the error to your shape.
|
|
2824
|
+
*
|
|
2825
|
+
* @param options - Configuration object
|
|
2826
|
+
*
|
|
2827
|
+
* @example Basic usage - custom status and map
|
|
2734
2828
|
* ```ts
|
|
2735
|
-
* server.setValidationErrorHandler(
|
|
2736
|
-
*
|
|
2829
|
+
* server.setValidationErrorHandler({
|
|
2830
|
+
* status: 400,
|
|
2831
|
+
* map: (error, req) => ({
|
|
2832
|
+
* path: req.path,
|
|
2833
|
+
* errors: error.errors,
|
|
2834
|
+
* }),
|
|
2835
|
+
* });
|
|
2836
|
+
* ```
|
|
2837
|
+
*
|
|
2838
|
+
* @example With schema for Swagger docs
|
|
2839
|
+
* ```ts
|
|
2840
|
+
* import { z } from "zod";
|
|
2841
|
+
*
|
|
2842
|
+
* server.setValidationErrorHandler({
|
|
2843
|
+
* status: 422,
|
|
2844
|
+
* schema: z.object({
|
|
2845
|
+
* code: z.string(),
|
|
2846
|
+
* message: z.string(),
|
|
2847
|
+
* errors: z.array(z.object({
|
|
2848
|
+
* field: z.string(),
|
|
2849
|
+
* message: z.string(),
|
|
2850
|
+
* })),
|
|
2851
|
+
* }),
|
|
2852
|
+
* map: (error, req) => ({
|
|
2853
|
+
* code: "VALIDATION_ERROR",
|
|
2854
|
+
* message: error.message,
|
|
2855
|
+
* errors: error.errors.map(e => ({
|
|
2856
|
+
* field: e.instancePath,
|
|
2857
|
+
* message: e.message,
|
|
2858
|
+
* })),
|
|
2859
|
+
* }),
|
|
2737
2860
|
* });
|
|
2738
2861
|
* ```
|
|
2739
2862
|
*/
|
|
2740
|
-
setValidationErrorHandler: (
|
|
2863
|
+
setValidationErrorHandler: (options: ValidationErrorHandlerOptions) => void;
|
|
2741
2864
|
/**
|
|
2742
2865
|
* Set a custom handler for policy authorization failures.
|
|
2743
2866
|
* When set, replaces the default `res.unauthorized({ error: "Unauthorized" })` response.
|
|
2744
|
-
*
|
|
2745
|
-
* @
|
|
2867
|
+
*
|
|
2868
|
+
* @param options - Configuration object with status, schema, and map function
|
|
2869
|
+
*
|
|
2870
|
+
* @example Basic usage
|
|
2871
|
+
* ```ts
|
|
2872
|
+
* server.setPolicyErrorHandler({
|
|
2873
|
+
* status: 403,
|
|
2874
|
+
* map: (req) => ({
|
|
2875
|
+
* code: "FORBIDDEN",
|
|
2876
|
+
* message: "Access denied",
|
|
2877
|
+
* }),
|
|
2878
|
+
* });
|
|
2879
|
+
* ```
|
|
2880
|
+
*
|
|
2881
|
+
* @example With schema for Swagger docs
|
|
2746
2882
|
* ```ts
|
|
2747
|
-
* server.setPolicyErrorHandler(
|
|
2748
|
-
*
|
|
2883
|
+
* server.setPolicyErrorHandler({
|
|
2884
|
+
* status: 401,
|
|
2885
|
+
* schema: z.object({
|
|
2886
|
+
* code: z.string(),
|
|
2887
|
+
* message: z.string(),
|
|
2888
|
+
* }),
|
|
2889
|
+
* map: (req) => ({
|
|
2890
|
+
* code: "UNAUTHORIZED",
|
|
2891
|
+
* message: "Authentication required",
|
|
2892
|
+
* }),
|
|
2749
2893
|
* });
|
|
2750
2894
|
* ```
|
|
2751
2895
|
*/
|
|
2752
|
-
setPolicyErrorHandler: (
|
|
2896
|
+
setPolicyErrorHandler: (options: PolicyErrorHandlerOptions) => void;
|
|
2753
2897
|
/**
|
|
2754
2898
|
* Register a hook to be called after bootstrap (controllers imported, plugins applied) but before the server starts accepting requests.
|
|
2755
2899
|
* Multiple hooks are called in the order they are registered.
|
|
@@ -2779,14 +2923,12 @@ interface ServerInterface {
|
|
|
2779
2923
|
* Binds the server to the port and hostname defined in the serverOptions, meant to be called only once
|
|
2780
2924
|
* It initializes the server without blocking the event loop, you can pass a callback to be called when the server is listening
|
|
2781
2925
|
* Use `waitUntilListening` instead if you want to wait for the server to be listening for requests before returning
|
|
2782
|
-
* @warning All routes defined with decorators are defined on this method just before the server starts listening for requests
|
|
2783
2926
|
*/
|
|
2784
2927
|
listen: (cb?: ServerListenCallback) => void;
|
|
2785
2928
|
/**
|
|
2786
2929
|
* Binds the server to the port and hostname defined in the serverOptions, meant to be called only once
|
|
2787
2930
|
* It initializes the server blocking the event loop, it will wait for the server to be listening for requests before returning
|
|
2788
2931
|
* Use `listen` instead if you want to initialize the server without blocking the event loop
|
|
2789
|
-
* @warning All routes defined with decorators are defined on this method just before the server starts listening for requests
|
|
2790
2932
|
*/
|
|
2791
2933
|
waitUntilListening: () => Promise<{
|
|
2792
2934
|
port: number;
|
|
@@ -2836,6 +2978,21 @@ type StandardMethodOptions<TResponses extends Record<number, RequestSchema> = Re
|
|
|
2836
2978
|
/** Policy configuration for this route. Accepts a single policy or an array of policies. */
|
|
2837
2979
|
policy?: PolicyRouteConfig | PolicyRouteConfig[];
|
|
2838
2980
|
};
|
|
2981
|
+
/**
|
|
2982
|
+
* Options for routes that don't allow request body (GET, DELETE).
|
|
2983
|
+
* Excludes 'body' and 'all' validation options per HTTP specification.
|
|
2984
|
+
*/
|
|
2985
|
+
type BodylessMethodOptions<TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TQuery extends RequestSchema | unknown = unknown, THeaders extends RequestSchema | unknown = unknown, TPath extends string = string, TMiddlewares extends readonly TypedMiddleware<any>[] = readonly TypedMiddleware<any>[]> = {
|
|
2986
|
+
middlewares?: TMiddlewares | TypedMiddleware<any>;
|
|
2987
|
+
query?: TQuery;
|
|
2988
|
+
headers?: THeaders;
|
|
2989
|
+
responses?: TResponses;
|
|
2990
|
+
swagger?: SwaggerRouteOptions;
|
|
2991
|
+
/** Cache configuration for this route. Body-based caching is not available for GET/DELETE. */
|
|
2992
|
+
cache?: TypedCacheRouteConfig<unknown, TQuery, TPath>;
|
|
2993
|
+
/** Policy configuration for this route. Accepts a single policy or an array of policies. */
|
|
2994
|
+
policy?: PolicyRouteConfig | PolicyRouteConfig[];
|
|
2995
|
+
};
|
|
2839
2996
|
type ServerHook = () => SyncOrAsync;
|
|
2840
2997
|
type SignalEvent = Deno.Signal | NodeJS.Signals;
|
|
2841
2998
|
type ControllerHandler<TPath extends string = string, TResponses extends Record<number, RequestSchema> = Record<number, RequestSchema>, TBody extends RequestSchema | unknown = unknown, TQuery extends RequestSchema | unknown = unknown, THeaders extends RequestSchema | unknown = unknown, TAll extends RequestSchema | unknown = unknown, TMiddlewareExt extends Record<string, any> = Record<string, never>> = (req: Request<ExtractParams<TPath>, TBody extends RequestSchema ? InferBodyType<TBody> : InferBodyType<TAll>, InferQueryType<TQuery> extends Record<string, any> ? InferQueryType<TQuery> : Record<string, unknown>, THeaders extends RequestSchema ? InferHeadersType<THeaders> : Record<string, string | string[]>> & TMiddlewareExt, res: Response$1<InferResponseMap<TResponses>>) => ServerHandlerReturnType<InferResponseMap<TResponses>>;
|
|
@@ -4750,4 +4907,4 @@ declare enum CacheStatus {
|
|
|
4750
4907
|
*/
|
|
4751
4908
|
declare const router: ClientRouter;
|
|
4752
4909
|
|
|
4753
|
-
export { type AsyncLocalStorageContextSetters, AzureBlobStorageProvider, BaseCron, BasePlugin, type BaseStorageProviderOptions, type BlobStorageProviderOptions, BullMQConfiguration, type BullMQConfigurationOptions, BullMQPubSub, CACHE_STATUS_HEADER, type CacheKeyIncludes, type CacheMiddlewareOptions, type CachePluginOptions, type CacheProvider, type CacheRedisOptions, type CacheRouteConfig, CacheService, type CacheServiceInterface, type CacheStats, CacheStatus, Command, type CommandOptions, CommandRegistry, type CompressionOptions, type CookieMiddlewareOptions, type CorsOptions, type CronSchedule, type CronScheduleParams, CronService, type CronUIOptions, CustomAdapter, type CustomQueueConfiguration, type CustomStorageProviderOptions, CustomTypedQueue, type CustomValidationError, DEFAULT_CACHE_OPTIONS, EdgeAdapter, EjsAdapter, type ExtractParams, GraphQL, type GraphQLContext, type GraphQLOptions, type GraphQLResolverFunction, type GraphQLResolverMap, type GraphQLResolverType, type GraphQLResolvers, type GraphQLSchemaInput, type GraphQLTypeDef, type GroupRouter, HandlebarsAdapter, type HelmetOptions, type HttpMethod, type HttpsOptions, type InferMiddlewareExtension, type InferMiddlewareExtensions, type InferResponseMap, type InferSchemaType, LocalStorageProvider, type LocalStorageProviderOptions, type LockBehavior, type LogOptions, type LoggerOptions, type MailOptions, MailOptionsBuilder, MailProvider, type MailProviderInterface, Mailer, type MailerInterface, type MailerOptions, type MailerProviderOptions, MemoryCacheProvider, MemoryPubSub, type MethodOverrideOptions, MockResponse, MockServer, type MockServerOptions, type MqttConnectionOptions, type MqttHandler, type MqttPublishOptions, MqttService, type MqttSubscribeOptions, type MqttSubscription, type MqttTopics, MustacheAdapter, type NextFunction, type NodeHttpClient, type NodeServer as NodeHttpServerClient, PGBossConfiguration, type PGBossConfigurationOptions, PGBossPubSub, type PolicyDecorator, type
|
|
4910
|
+
export { type AsyncLocalStorageContextSetters, AzureBlobStorageProvider, BaseCron, BasePlugin, type BaseStorageProviderOptions, type BlobStorageProviderOptions, type BodylessMethodOptions, BullMQConfiguration, type BullMQConfigurationOptions, BullMQPubSub, CACHE_STATUS_HEADER, type CacheKeyIncludes, type CacheMiddlewareOptions, type CachePluginOptions, type CacheProvider, type CacheRedisOptions, type CacheRouteConfig, CacheService, type CacheServiceInterface, type CacheStats, CacheStatus, Command, type CommandOptions, CommandRegistry, type CompressionOptions, type CookieMiddlewareOptions, type CorsOptions, type CronSchedule, type CronScheduleParams, CronService, type CronUIOptions, CustomAdapter, type CustomQueueConfiguration, type CustomStorageProviderOptions, CustomTypedQueue, type CustomValidationError, DEFAULT_CACHE_OPTIONS, EdgeAdapter, EjsAdapter, type ExtractParams, GraphQL, type GraphQLContext, type GraphQLOptions, type GraphQLResolverFunction, type GraphQLResolverMap, type GraphQLResolverType, type GraphQLResolvers, type GraphQLSchemaInput, type GraphQLTypeDef, type GroupRouter, HandlebarsAdapter, type HelmetOptions, type HttpMethod, type HttpsOptions, type InferMiddlewareExtension, type InferMiddlewareExtensions, type InferResponseMap, type InferSchemaType, LocalStorageProvider, type LocalStorageProviderOptions, type LockBehavior, type LogOptions, type LoggerOptions, type MailOptions, MailOptionsBuilder, MailProvider, type MailProviderInterface, Mailer, type MailerInterface, type MailerOptions, type MailerProviderOptions, MemoryCacheProvider, MemoryPubSub, type MethodOverrideOptions, MockResponse, MockServer, type MockServerOptions, type MqttConnectionOptions, type MqttHandler, type MqttPublishOptions, MqttService, type MqttSubscribeOptions, type MqttSubscription, type MqttTopics, MustacheAdapter, type NextFunction, type NodeHttpClient, type NodeServer as NodeHttpServerClient, PGBossConfiguration, type PGBossConfigurationOptions, PGBossPubSub, type PolicyDecorator, type PolicyErrorHandlerOptions, PolicyManager, type PolicyProvider, type PolicyRouteConfig, type PublishTopic, QueueManager, QueueService, type RateLimiterKeyOptions, RedisCacheProvider, Request, type RequestSchema, Response$1 as Response, type ResponseBodyForStatus, type RuntimeServer, S3StorageProvider, type S3StorageProviderOptions, SQSConfiguration, type SQSConfigurationOptions, SQSPubSub, type CacheMetrics as SchemaCacheMetrics, type SerializeOptions, type SerializedValidationError, Server, type ServerConnectInput, type ServerErrorHandler, type ServerHook, type ServerInterface, type ServerListenCallback, type ServerOptions, type ServerRouteHandler, type ServerRouteMiddleware, type ServerTapOptions, type SessionOptions, type SignalEvent, type StandardMethodOptions, type StaticPluginOptions, Storage, type StorageInterface, type StorageOptions, type StorageProviderOptions, type TemplateMailOptions, type TimeoutOptions, type TrustProxyOptions, type TypedCacheKeyIncludes, type TypedCacheRouteConfig, type TypedHandler, type TypedMiddleware, TypedQueue, type TypedRouteMetadata, type ValidatedData, type ValidationErrorHandlerOptions, type ValidationOptions, arg, asyncLocalStorage, asyncStorage, bullmqQueue, cache, cacheMiddleware, clearAllCaches as clearAllSchemaCaches, commandRegistry, compression, controller, cookie, cors, createExpressAdapter, createPolicyDecorator, createQueue, cron, cronUIInstance, cronUi, Server as default, defineMiddleware, defineQueueConfiguration, del, expressHandler, expressMiddleware, flag, get, getCacheService, getCacheMetrics as getSchemaCacheMetrics, hash, helmet, initCacheService, log, logCacheMetrics as logSchemaCacheMetrics, logger, memoryQueue, methodOverride, middleware, mountExpressRouter, mqtt, patch, pgbossQueue, post, put, rateLimiter, resetCacheService, router, serialize, serveStatic, session, setCronGlobalErrorHandler, setMqttGlobalErrorHandler, sqsQueue, timeout as timeoutMw, trustProxy, validate };
|