feat: collection, global and field props for hooks, fix request context initialization, add context to global hooks (#3780)

* feat: pass collection, global and field props to collection, global and field hooks - where applicable

* fix: initial request context not set for all operations

* chore: add tests which check the collection prop for collection hooks

* feat: add context to props of global hooks

* chore: add global tests for global and field props

* chore: int tests: use JSON instead of object hashes
This commit is contained in:
Alessio Gravili
2023-10-21 11:40:57 +02:00
committed by GitHub
parent 67d61df563
commit f6adbae0c7
52 changed files with 752 additions and 71 deletions

View File

@@ -6,13 +6,14 @@ import { deepCopyObject } from '../../../utilities/deepCopyObject'
import { traverseFields } from './traverseFields'
type Args = {
collection: SanitizedCollectionConfig | null
context: RequestContext
currentDepth?: number
depth: number
doc: Record<string, unknown>
entityConfig: SanitizedCollectionConfig | SanitizedGlobalConfig
findMany?: boolean
flattenLocales?: boolean
global: SanitizedGlobalConfig | null
overrideAccess: boolean
req: PayloadRequest
showHiddenFields: boolean
@@ -20,13 +21,14 @@ type Args = {
export async function afterRead<T = any>(args: Args): Promise<T> {
const {
collection,
context,
currentDepth: incomingCurrentDepth,
depth: incomingDepth,
doc: incomingDoc,
entityConfig,
findMany,
flattenLocales = true,
global,
overrideAccess,
req,
showHiddenFields,
@@ -45,14 +47,16 @@ export async function afterRead<T = any>(args: Args): Promise<T> {
const currentDepth = incomingCurrentDepth || 1
traverseFields({
collection,
context,
currentDepth,
depth,
doc,
fieldPromises,
fields: entityConfig.fields,
fields: collection?.fields || global?.fields,
findMany,
flattenLocales,
global,
overrideAccess,
populationPromises,
req,