@travetto/schema
Advanced tools
Comparing version 0.2.2 to 0.2.4
@@ -1,4 +0,2 @@ | ||
import { Request, Response } from 'express'; | ||
import { ControllerRegistry, AppError, ParamConfig } from '@travetto/express'; | ||
import { ControllerRegistry, AppError, ParamConfig, Filter, EndpointDecorator, Response, Request } from '@travetto/rest'; | ||
import { Util } from '@travetto/base'; | ||
@@ -11,3 +9,4 @@ import { Class } from '@travetto/registry'; | ||
(ValidationErrors as any as Class<Error>).prototype.render = function (res: Response) { | ||
res.status(403).json({ | ||
res.status(403); | ||
res.json({ | ||
message: this.message, | ||
@@ -64,3 +63,3 @@ errors: this.errors, | ||
export function SchemaBody<T>(cls: Class<T>, view?: string) { | ||
return (target: any, prop: string | symbol, descriptor: PropertyDescriptor) => { | ||
return function (target: any, prop: string | symbol, descriptor: TypedPropertyDescriptor<Filter>) { | ||
ControllerRegistry.registerPendingEndpoint(target.constructor, descriptor, { | ||
@@ -71,3 +70,3 @@ requestType: { | ||
filters: [ | ||
async (req: Request, res: Response) => { | ||
async function (req: Request) { | ||
req.body = await getSchemaBody(req, cls, view); | ||
@@ -77,3 +76,3 @@ } | ||
}); | ||
}; | ||
} as EndpointDecorator; | ||
} | ||
@@ -83,3 +82,3 @@ | ||
return (target: any, prop: string | symbol, descriptor: PropertyDescriptor) => { | ||
return function (target: any, prop: string | symbol, descriptor: TypedPropertyDescriptor<Filter>) { | ||
const params = schemaToParams(cls, view); | ||
@@ -90,3 +89,3 @@ | ||
filters: [ | ||
async (req: Request, res: Response) => { | ||
async (req: Request) => { | ||
const o = getBound(cls, BindUtil.expandPaths(req.query), view); | ||
@@ -101,3 +100,3 @@ if (SchemaRegistry.has(cls)) { | ||
}); | ||
}; | ||
} as EndpointDecorator; | ||
} |
@@ -15,3 +15,3 @@ { | ||
"optionalExtensionDependencies": { | ||
"@travetto/express": "^0.1.11", | ||
"@travetto/rest": "^0.1.11", | ||
"@types/faker": "^4.1.2", | ||
@@ -39,4 +39,4 @@ "faker": "^4.1.0" | ||
}, | ||
"version": "0.2.2", | ||
"gitHead": "14b93bc88216ca2baacfe20af1b0bd1b407b35b0" | ||
"version": "0.2.4", | ||
"gitHead": "b341ad30d6dd66c933577b0b99de2d4a748715a5" | ||
} |
58562
327
4
4
1
52