feat(payload): expose owning collection/global config to field access functions#17051
feat(payload): expose owning collection/global config to field access functions#17051JarrodMFlesch wants to merge 8 commits into
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
… traversal Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…assertions Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…mise Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ll callsites Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…access args Align FieldAccessArgs with FieldHookArgs pattern: pass full SanitizedCollectionConfig / SanitizedGlobalConfig objects (or null) instead of plain slug strings. Updated callsites: - fields/hooks/afterRead/promise.ts - fields/hooks/beforeValidate/promise.ts - collections/operations/findDistinct.ts - utilities/getEntityPermissions/populateFieldPermissions.ts - utilities/getEntityPermissions/getEntityPermissions.ts - packages/ui addFieldStatePromise.ts (looks up config from req.payload) Test: add global→child relationship probe asserting child field access receives child collection context when populated from a global. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Pull Request titles must follow the Conventional Commits specification and have valid scopes. Unknown scope "payload" found in pull request title "feat(payload): expose owning collection/global config to field access functions". Scope must match one of: cpa, claude, codemod, db-*, db-d1-sqlite, db-mongodb, db-postgres, db-vercel-postgres, db-sqlite, db-d1-sqlite, drizzle, email-*, email-nodemailer, email-resend, eslint, evals, graphql, kv, kv-redis, live-preview, live-preview-react, live-preview-vue, next, payload-cloud, plugin-cloud, plugin-cloud-storage, plugin-ecommerce, plugin-form-builder, plugin-import-export, plugin-mcp, plugin-multi-tenant, plugin-nested-docs, plugin-redirects, plugin-search, plugin-sentry, plugin-seo, plugin-stripe, richtext-*, richtext-lexical, sdk, skills, storage-*, storage-azure, storage-gcs, storage-r2, storage-uploadthing, storage-vercel-blob, storage-s3, translations, ui, templates, examples(/(\w|-)+)?, deps. |
📦 esbuild Bundle Analysis for payloadThis analysis was generated by esbuild-bundle-analyzer. 🤖
Largest pathsThese visualization shows top 20 largest paths in the bundle.Meta file: packages/next/meta_index.json, Out file: esbuild/index.js
Meta file: packages/payload/meta_index.json, Out file: esbuild/index.js
Meta file: packages/payload/meta_shared.json, Out file: esbuild/exports/shared.js
Meta file: packages/richtext-lexical/meta_client.json, Out file: esbuild/exports/client_optimized/index.js
Meta file: packages/ui/meta_client.json, Out file: esbuild/exports/client_optimized/index.js
Meta file: packages/ui/meta_shared.json, Out file: esbuild/exports/shared_optimized/index.js
DetailsNext to the size is how much the size has increased or decreased compared with the base branch of this PR.
|
Adds
collectionandglobaltoFieldAccessArgs, giving field access functions (create,read,update) the same owning-entity context thatFieldHookArgshas always had.The primary motivation is shared block references: a block defined once and reused across multiple collections and globals has no way to differentiate which entity its field access is being evaluated for. With this change,
field.access.read({ collection, global, ... })receives the fullSanitizedCollectionConfigorSanitizedGlobalConfig(the other isnull), exactly mirroring the existingFieldHookArgspattern.Before:
After:
Callsites updated across all entry paths (local API, REST, GraphQL, form state builder):
fields/hooks/afterRead/promise.tsfields/hooks/beforeValidate/promise.tscollections/operations/findDistinct.tsutilities/getEntityPermissions/populateFieldPermissions.ts+getEntityPermissions.tspackages/ui—addFieldStatePromise.tslooks up the full config fromreq.payloadat the point of the access call; slug strings continue to flow through the rest of the UI chain unchangedRelationship traversal correctly passes the related collection's config (not the parent's), so a field on a populated child always sees its own owning collection.