@feathersjs/schema
Advanced tools
Comparing version 5.0.0-pre.10 to 5.0.0-pre.11
@@ -6,2 +6,13 @@ # Change Log | ||
# [5.0.0-pre.11](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.10...v5.0.0-pre.11) (2021-10-06) | ||
### Features | ||
* **schema:** Allow resolvers to validate a schema ([#2465](https://github.com/feathersjs/feathers/issues/2465)) ([7d9590b](https://github.com/feathersjs/feathers/commit/7d9590bbe12b94b8b5a7987684f5d4968e426481)) | ||
# [5.0.0-pre.10](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.9...v5.0.0-pre.10) (2021-09-19) | ||
@@ -8,0 +19,0 @@ |
{ | ||
"name": "@feathersjs/schema", | ||
"description": "A common data schema definition format", | ||
"version": "5.0.0-pre.10", | ||
"version": "5.0.0-pre.11", | ||
"homepage": "https://feathersjs.com", | ||
@@ -53,4 +53,4 @@ "main": "lib/", | ||
"dependencies": { | ||
"@feathersjs/errors": "^5.0.0-pre.10", | ||
"@feathersjs/feathers": "^5.0.0-pre.10", | ||
"@feathersjs/errors": "^5.0.0-pre.11", | ||
"@feathersjs/feathers": "^5.0.0-pre.11", | ||
"ajv": "^8.6.3", | ||
@@ -61,6 +61,6 @@ "json-schema": "^0.3.0", | ||
"devDependencies": { | ||
"@feathersjs/memory": "^5.0.0-pre.10", | ||
"@feathersjs/memory": "^5.0.0-pre.11", | ||
"@types/mocha": "^9.0.0", | ||
"@types/node": "^16.9.4", | ||
"mocha": "^9.1.1", | ||
"@types/node": "^16.10.2", | ||
"mocha": "^9.1.2", | ||
"shx": "^0.3.3", | ||
@@ -67,0 +67,0 @@ "typescript": "^4.4.3" |
import { BadRequest } from '@feathersjs/errors'; | ||
import { Schema } from './schema'; | ||
@@ -15,2 +16,4 @@ export type PropertyResolver<T, V, C> = ( | ||
export interface ResolverConfig<T, C> { | ||
schema?: Schema<any>, | ||
validate?: 'before'|'after'|false, | ||
properties: PropertyResolverMap<T, C> | ||
@@ -56,4 +59,5 @@ } | ||
async resolve<D> (data: D, context: C, status?: Partial<ResolverStatus<T, C>>): Promise<T> { | ||
const { properties: resolvers } = this.options; | ||
async resolve<D> (_data: D, context: C, status?: Partial<ResolverStatus<T, C>>): Promise<T> { | ||
const { properties: resolvers, schema, validate } = this.options; | ||
const data = schema && validate === 'before' ? await schema.validate(_data) : _data; | ||
const propertyList = (Array.isArray(status?.properties) | ||
@@ -71,3 +75,3 @@ ? status?.properties | ||
await Promise.all(propertyList.map(async name => { | ||
const value = (data as any)[name]; | ||
const value = data[name]; | ||
@@ -99,3 +103,5 @@ if (resolvers[name]) { | ||
return result; | ||
return schema && validate === 'after' | ||
? await schema.validate(result) | ||
: result; | ||
} | ||
@@ -102,0 +108,0 @@ } |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
33023
619
0