BREAKING CHANGE: collection.admin.hooks.beforeDuplicate removed and instead should be handled using field beforeDuplicate hooks which take the full field hook arguments. * feat: duplicate doc moved from frontend to backend concern * feat: default beforeDuplicate hook functions on unique fields * docs: beforeDuplicate field hook * test: duplicate doc local api * chore: fix build errors * chore: add access.create call to duplicate operation * chore: perfectionist reorder imports
61 lines
1.3 KiB
TypeScript
61 lines
1.3 KiB
TypeScript
import type { SanitizedCollectionConfig } from '../../../collections/config/types.js'
|
|
import type { SanitizedGlobalConfig } from '../../../globals/config/types.js'
|
|
import type { PayloadRequest, RequestContext } from '../../../types/index.js'
|
|
import type { Field, TabAsField } from '../../config/types.js'
|
|
|
|
import { promise } from './promise.js'
|
|
|
|
type Args<T> = {
|
|
collection: SanitizedCollectionConfig | null
|
|
context: RequestContext
|
|
data: T
|
|
doc: T
|
|
duplicate: boolean
|
|
fields: (Field | TabAsField)[]
|
|
global: SanitizedGlobalConfig | null
|
|
id?: number | string
|
|
operation: 'create' | 'update'
|
|
overrideAccess: boolean
|
|
req: PayloadRequest
|
|
siblingData: Record<string, unknown>
|
|
siblingDoc: Record<string, unknown>
|
|
}
|
|
|
|
export const traverseFields = async <T>({
|
|
id,
|
|
collection,
|
|
context,
|
|
data,
|
|
doc,
|
|
duplicate,
|
|
fields,
|
|
global,
|
|
operation,
|
|
overrideAccess,
|
|
req,
|
|
siblingData,
|
|
siblingDoc,
|
|
}: Args<T>): Promise<void> => {
|
|
const promises = []
|
|
fields.forEach((field) => {
|
|
promises.push(
|
|
promise({
|
|
id,
|
|
collection,
|
|
context,
|
|
data,
|
|
doc,
|
|
duplicate,
|
|
field,
|
|
global,
|
|
operation,
|
|
overrideAccess,
|
|
req,
|
|
siblingData,
|
|
siblingDoc,
|
|
}),
|
|
)
|
|
})
|
|
await Promise.all(promises)
|
|
}
|