diff --git a/packages/schema/src/resolver.ts b/packages/schema/src/resolver.ts index 5de4dbd56a..e891ef7a2a 100644 --- a/packages/schema/src/resolver.ts +++ b/packages/schema/src/resolver.ts @@ -3,7 +3,7 @@ import { Schema } from './schema'; export type PropertyResolver = ( value: V|undefined, - obj: any, + obj: T, context: C, status: ResolverStatus ) => Promise; @@ -52,7 +52,7 @@ export class Resolver { stack: [...stack, resolver] } - return resolver(value, data, context, resolverStatus); + return resolver(value, data as any, context, resolverStatus); } async resolve (_data: D, context: C, status?: Partial>): Promise { diff --git a/packages/schema/test/fixture.ts b/packages/schema/test/fixture.ts index df9cf86b43..2e0b340224 100644 --- a/packages/schema/test/fixture.ts +++ b/packages/schema/test/fixture.ts @@ -5,8 +5,7 @@ import { memory, Service } from '@feathersjs/memory'; import { schema, resolve, Infer, resolveResult, - queryProperty, resolveQuery, - validateQuery, validateData, resolveData + queryProperty, resolveQuery, resolveData } from '../src'; export const userSchema = schema({ @@ -24,7 +23,7 @@ export const userResultSchema = schema({ $id: 'UserResult', type: 'object', additionalProperties: false, - required: ['id', ...userSchema.definition.required ], + required: ['id', ...userSchema.definition.required], properties: { ...userSchema.definition.properties, id: { type: 'number' } @@ -35,6 +34,8 @@ export type User = Infer; export type UserResult = Infer; export const userDataResolver = resolve>({ + schema: userSchema, + validate: 'before', properties: { password: async () => { return 'hashed'; @@ -43,6 +44,7 @@ export const userDataResolver = resolve>({ }); export const userResultResolver = resolve>({ + schema: userResultSchema, properties: { password: async (value, _user, context) => { return context.params.provider ? undefined : value; @@ -79,6 +81,7 @@ export type MessageResult = Infer & { }; export const messageResultResolver = resolve>({ + schema: messageResultSchema, properties: { user: async (_value, message, context) => { const { userId } = message; @@ -114,6 +117,8 @@ export const messageQuerySchema = schema({ export type MessageQuery = Infer; export const messageQueryResolver = resolve>({ + schema: messageQuerySchema, + validate: 'before', properties: { userId: async (value, _query, context) => { if (context.params?.user) { @@ -138,7 +143,6 @@ const app = feathers() .use('messages', memory()); app.service('messages').hooks([ - validateQuery(messageQuerySchema), resolveQuery(messageQueryResolver), resolveResult(messageResultResolver) ]); @@ -149,7 +153,6 @@ app.service('users').hooks([ app.service('users').hooks({ create: [ - validateData(userSchema), resolveData(userDataResolver) ] });