@@ -58,7 +58,11 @@ import type {
5858 IncomingCollectionVersions ,
5959 SanitizedCollectionVersions ,
6060} from '../../versions/types.js'
61- import type { AfterOperationArg , AfterOperationMap } from '../operations/utils.js'
61+ import type {
62+ AfterOperationArg ,
63+ BeforeOperationArg ,
64+ OperationMap ,
65+ } from '../operations/utilities/types.js'
6266
6367export type DataFromCollectionSlug < TSlug extends CollectionSlug > = TypedCollection [ TSlug ]
6468
@@ -69,7 +73,7 @@ export type AuthOperationsFromCollectionSlug<TSlug extends CollectionSlug> =
6973
7074export type RequiredDataFromCollection < TData extends JsonObject > = MarkOptional <
7175 TData ,
72- 'createdAt' | 'deletedAt' | 'id' | 'sizes' | ' updatedAt'
76+ 'createdAt' | 'deletedAt' | 'id' | 'updatedAt'
7377>
7478
7579export type RequiredDataFromCollectionSlug < TSlug extends CollectionSlug > =
@@ -80,7 +84,7 @@ export type RequiredDataFromCollectionSlug<TSlug extends CollectionSlug> =
8084 * When creating a draft, required fields don't need to be provided as validation is skipped
8185 */
8286export type DraftDataFromCollection < TData extends JsonObject > = Partial <
83- MarkOptional < TData , 'createdAt' | 'deletedAt' | 'id' | 'sizes' | ' updatedAt'>
87+ MarkOptional < TData , 'createdAt' | 'deletedAt' | 'id' | 'updatedAt' >
8488>
8589
8690export type DraftDataFromCollectionSlug < TSlug extends CollectionSlug > = DraftDataFromCollection <
@@ -104,19 +108,13 @@ export type HookOperationType =
104108
105109type CreateOrUpdateOperation = Extract < HookOperationType , 'create' | 'update' >
106110
107- export type BeforeOperationHook = ( args : {
108- args ?: any
109- /**
110- * The collection which this hook is being run on
111- */
112- collection : SanitizedCollectionConfig
113- context : RequestContext
114- /**
115- * Hook operation being performed
116- */
117- operation : HookOperationType
118- req : PayloadRequest
119- } ) => any
111+ export type BeforeOperationHook < TOperationGeneric extends CollectionSlug = string > = (
112+ arg : BeforeOperationArg < TOperationGeneric > ,
113+ ) =>
114+ | Parameters < OperationMap < TOperationGeneric > [ keyof OperationMap < TOperationGeneric > ] > [ 0 ]
115+ | Promise < Parameters < OperationMap < TOperationGeneric > [ keyof OperationMap < TOperationGeneric > ] > [ 0 ] >
116+ | Promise < void >
117+ | void
120118
121119export type BeforeValidateHook < T extends TypeWithID = any > = ( args : {
122120 /** The collection which this hook is being run on */
@@ -207,13 +205,9 @@ export type AfterDeleteHook<T extends TypeWithID = any> = (args: {
207205export type AfterOperationHook < TOperationGeneric extends CollectionSlug = string > = (
208206 arg : AfterOperationArg < TOperationGeneric > ,
209207) =>
210- | Awaited <
211- ReturnType < AfterOperationMap < TOperationGeneric > [ keyof AfterOperationMap < TOperationGeneric > ] >
212- >
208+ | Awaited < ReturnType < OperationMap < TOperationGeneric > [ keyof OperationMap < TOperationGeneric > ] > >
213209 | Promise <
214- Awaited <
215- ReturnType < AfterOperationMap < TOperationGeneric > [ keyof AfterOperationMap < TOperationGeneric > ] >
216- >
210+ Awaited < ReturnType < OperationMap < TOperationGeneric > [ keyof OperationMap < TOperationGeneric > ] > >
217211 >
218212
219213export type BeforeLoginHook < T extends TypeWithID = any > = ( args : {
@@ -577,7 +571,7 @@ export type CollectionConfig<TSlug extends CollectionSlug = any> = {
577571 beforeChange ?: BeforeChangeHook [ ]
578572 beforeDelete ?: BeforeDeleteHook [ ]
579573 beforeLogin ?: BeforeLoginHook [ ]
580- beforeOperation ?: BeforeOperationHook [ ]
574+ beforeOperation ?: BeforeOperationHook < TSlug > [ ]
581575 beforeRead ?: BeforeReadHook [ ]
582576 beforeValidate ?: BeforeValidateHook [ ]
583577 /**
0 commit comments