Comparing version 4.4.0 to 4.5.0
{ | ||
"name": "async-app", | ||
"version": "4.4.0", | ||
"version": "4.5.0", | ||
"description": "An express wrapper for handling async middlewares, order middlewares, schema validator, and other stuff", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -17,3 +17,3 @@ "use strict"; | ||
}); | ||
const createMiddleware = (validate, generateError, source) => (req, res, next) => { | ||
const createMiddleware = (validate, generateError, source, context) => (req, res, next) => { | ||
const realSource = source || METHOD_SOURCE_MAP[req.method.toLowerCase()]; | ||
@@ -23,3 +23,3 @@ const data = req[realSource]; | ||
if (schemaErrors.length) { | ||
res.status(400).send(generateError(schemaErrors, realSource)); | ||
res.status(400).send(generateError(schemaErrors, realSource, Object.assign({}, context, { req }))); | ||
return; | ||
@@ -38,3 +38,3 @@ } | ||
return middlewares; | ||
const schemaMiddleware = createMiddleware(compileSchema(schema.$schema || schema, context), generateError, source); | ||
const schemaMiddleware = createMiddleware(compileSchema(schema.$schema || schema, context), generateError, source, context); | ||
schemaMiddleware.$noOrder = true; | ||
@@ -41,0 +41,0 @@ return [schemaMiddleware, ...middlewares]; |
@@ -7,2 +7,5 @@ import { Express, NextFunction, Request, Response } from 'express'; | ||
} | ||
export interface ErrorContext extends Context { | ||
req: Request; | ||
} | ||
export interface Entities { | ||
@@ -52,3 +55,3 @@ _: unknown; | ||
export declare type CompileSchema<T> = (schema: Schema<T>, context: Context) => ValidateSchema; | ||
export declare type GenerateSchemaErrorFn = (errors: ValidationError[], source: string) => any; | ||
export declare type GenerateSchemaErrorFn = (errors: ValidationError[], source: string, context: ErrorContext) => any; | ||
export declare type ErrorHandlerFn<TEntities extends Entities> = (errors: CustomError, req: Req<TEntities, keyof TEntities>, res: Response, next: NextFunction) => any; | ||
@@ -55,0 +58,0 @@ export declare type MiddlewareArg<TEntities extends Entities> = CommonMiddleware<TEntities> | CommonMiddleware<TEntities>[] | AsyncMiddleware<TEntities>; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
104174
1102