From 6b150e01d306fde5686156a2fa6a8fa00aeffe0e Mon Sep 17 00:00:00 2001 From: James Date: Thu, 25 Nov 2021 09:54:12 -0500 Subject: [PATCH] feat: further types field based functions --- src/collections/config/types.ts | 4 ++-- src/fields/config/types.ts | 20 +++++++++----------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/collections/config/types.ts b/src/collections/config/types.ts index a8c12f6a6e..6fbf067a09 100644 --- a/src/collections/config/types.ts +++ b/src/collections/config/types.ts @@ -36,7 +36,7 @@ export type BeforeOperationHook = (args: { }) => any; export type BeforeValidateHook = (args: { - data?: any; + data?: Partial; req?: PayloadRequest; /** * Hook operation being performed @@ -51,7 +51,7 @@ export type BeforeValidateHook = (args: { }) => any; export type BeforeChangeHook = (args: { - data: T; + data: Partial; req: PayloadRequest; /** * Hook operation being performed diff --git a/src/fields/config/types.ts b/src/fields/config/types.ts index f73826945a..539ecb79da 100644 --- a/src/fields/config/types.ts +++ b/src/fields/config/types.ts @@ -6,28 +6,26 @@ import { PayloadRequest } from '../../express/types'; import { ConditionalDateProps } from '../../admin/components/elements/DatePicker/types'; import { Description } from '../../admin/components/forms/FieldDescription/types'; -export type FieldHookArgs = { - value?: T[P], +export type FieldHookArgs = { + value?: P, originalDoc?: T, - data?: { - [key: string]: unknown - }, + data?: Partial, operation?: 'create' | 'read' | 'update' | 'delete', req: PayloadRequest } export type FieldHookReturnType = Promise | unknown; -export type FieldHook = (args: FieldHookArgs) => FieldHookReturnType; +export type FieldHook = (args: FieldHookArgs) => FieldHookReturnType; -export type FieldAccess = (args: { +export type FieldAccess = (args: { req: PayloadRequest id?: string - data: Record - siblingData: Record + data: Partial + siblingData: Partial

}) => Promise | boolean; -export type Condition = (data: Record, siblingData: Record) => boolean; +export type Condition = (data: Partial, siblingData: Partial

) => boolean; type Admin = { position?: 'sidebar'; @@ -50,7 +48,7 @@ export type Labels = { plural: string; }; -export type Validate = (value: unknown, options?: any) => string | true | Promise; +export type Validate = (value?: T, options?: any) => string | true | Promise; export type OptionObject = { label: string