import type { CollectionConfig } from 'payload' /** * A project's change to a collection the plugin adds (consent records, stats): * - an object is merged over the plugin's: `access`, `admin` and `hooks` key by * key (your access rules win, your hooks run after the plugin's), anything * else (labels, fields, …) replaces the plugin's value; * - a function gets the plugin's collection and returns the one to use — full * control. Keep the slug: the plugin's endpoints and views write and read it. * * Same rules as `globalOverrides`. */ export type CollectionOverride = ((collection: CollectionConfig) => CollectionConfig) | Partial type Hooks = NonNullable /** Applies one CollectionOverride to a plugin collection. */ export function applyCollectionOverride(collection: CollectionConfig, override: CollectionOverride | undefined): CollectionConfig { if (!override) {return collection} if (typeof override === 'function') {return override(collection)} const hooks: Record = { ...(collection.hooks as Record) } for (const [key, list] of Object.entries(override.hooks ?? {})) { hooks[key] = [...(hooks[key] ?? []), ...((list as unknown[]) ?? [])] } return { ...collection, ...override, access: { ...collection.access, ...override.access }, admin: { ...collection.admin, ...override.admin }, hooks: hooks as Hooks, } }