diff --git a/.changeset/long-bees-thank.md b/.changeset/long-bees-thank.md new file mode 100644 index 00000000000..f716d97457e --- /dev/null +++ b/.changeset/long-bees-thank.md @@ -0,0 +1,5 @@ +--- +"@keystone-6/core": patch +--- + +Handle combined use of old and new validate syntax diff --git a/packages/core/src/fields/resolve-hooks.ts b/packages/core/src/fields/resolve-hooks.ts index 7139e2e0ec9..5179c442bcc 100644 --- a/packages/core/src/fields/resolve-hooks.ts +++ b/packages/core/src/fields/resolve-hooks.ts @@ -9,32 +9,6 @@ import { export type InternalFieldHooks = Omit, 'validateInput' | 'validateDelete' | 'resolveInput'> -/** @deprecated, TODO: remove in breaking change */ -function resolveValidateHooks ({ - validate, - validateInput, - validateDelete -}: FieldHooks): Exclude["validate"], Function> | undefined { - if (validateInput || validateDelete) { - return { - create: validateInput, - update: validateInput, - delete: validateDelete, - } - } - - if (!validate) return - if (typeof validate === 'function') { - return { - create: validate, - update: validate, - delete: validate - } - } - - return validate -} - function merge < R, A extends (r: R) => MaybePromise, @@ -47,6 +21,23 @@ function merge < } } +/** @deprecated, TODO: remove in breaking change */ +function resolveValidateHooks ({ + validate, + validateInput, + validateDelete +}: FieldHooks): Exclude["validate"], Function> | undefined { + if (!validate && !validateInput && !validateDelete) return + + const isFnValidate = typeof validate === 'function' + + return { + create: merge(validateInput, isFnValidate ? validate : validate?.create), + update: merge(validateInput, isFnValidate ? validate : validate?.update), + delete: merge(validateDelete, isFnValidate ? validate : validate?.delete), + } +} + export function mergeFieldHooks ( builtin?: InternalFieldHooks, hooks?: FieldHooks,