From 269fdecc5961092dc8608b3cbe16f433c80bfa96 Mon Sep 17 00:00:00 2001 From: David Luecke Date: Tue, 17 May 2022 17:59:06 -0700 Subject: [PATCH] fix(typescript): Make additional types generic to work with extended types (#2625) --- packages/mongodb/src/adapter.ts | 2 +- packages/schema/src/hooks.ts | 30 +++++++++++++++--------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/packages/mongodb/src/adapter.ts b/packages/mongodb/src/adapter.ts index 8ee888dd3a..0748e58912 100644 --- a/packages/mongodb/src/adapter.ts +++ b/packages/mongodb/src/adapter.ts @@ -19,7 +19,7 @@ export interface MongoDBAdapterParams extends AdapterParams, P extends MongoDBAdapterParams = MongoDBAdapterParams> +export class MongoDbAdapter, P extends MongoDBAdapterParams = MongoDBAdapterParams> extends AdapterBase { constructor (options: MongoDBAdapterOptions) { if (!options) { diff --git a/packages/schema/src/hooks.ts b/packages/schema/src/hooks.ts index 5e48894d5a..4f890d5be6 100644 --- a/packages/schema/src/hooks.ts +++ b/packages/schema/src/hooks.ts @@ -3,7 +3,7 @@ import { BadRequest } from '../../errors/lib'; import { Resolver, ResolverStatus } from './resolver'; import { Schema } from './schema'; -const getContext = (context: HookContext) => { +const getContext = (context: H) => { return { ...context, params: { @@ -13,11 +13,11 @@ const getContext = (context: HookContext) => { } } -const runResolvers = async ( - resolvers: Resolver[], +const runResolvers = async ( + resolvers: Resolver[], data: any, - ctx: HookContext, - status?: Partial> + ctx: H, + status?: Partial> ) => { let current: any = data; @@ -28,8 +28,8 @@ const runResolvers = async ( return current as T; } -export const resolveQuery = (...resolvers: Resolver[]) => - async (context: HookContext, next?: NextFunction) => { +export const resolveQuery = (...resolvers: Resolver[]) => + async (context: H, next?: NextFunction) => { const ctx = getContext(context); const data = context?.params?.query || {}; const query = await runResolvers(resolvers, data, ctx); @@ -44,8 +44,8 @@ export const resolveQuery = (...resolvers: Resolver[]) => } }; -export const resolveData = (...resolvers: Resolver[]) => - async (context: HookContext, next?: NextFunction) => { +export const resolveData = (...resolvers: Resolver[]) => + async (context: H, next?: NextFunction) => { const ctx = getContext(context); const data = context.data; const status = { @@ -65,8 +65,8 @@ export const resolveData = (...resolvers: Resolver[]) => } }; -export const resolveResult = (...resolvers: Resolver[]) => - async (context: HookContext, next?: NextFunction) => { +export const resolveResult = (...resolvers: Resolver[]) => + async (context: H, next?: NextFunction) => { if (typeof next === 'function') { const { $resolve: properties, ...query } = context.params?.query || {}; const resolve = { @@ -101,8 +101,8 @@ export const resolveResult = (...resolvers: Resolver[]) => } }; -export const validateQuery = (schema: Schema) => - async (context: HookContext, next?: NextFunction) => { +export const validateQuery = (schema: Schema) => + async (context: H, next?: NextFunction) => { const data = context?.params?.query || {}; try { @@ -121,8 +121,8 @@ export const validateQuery = (schema: Schema) => } }; -export const validateData = (schema: Schema) => - async (context: HookContext, next?: NextFunction) => { +export const validateData = (schema: Schema) => + async (context: H, next?: NextFunction) => { const data = context.data; try {