payload 3.0.0-beta.125 → 3.0.0-beta.126

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. package/dist/admin/RichText.d.ts +3 -1
  2. package/dist/admin/RichText.d.ts.map +1 -1
  3. package/dist/admin/RichText.js.map +1 -1
  4. package/dist/collections/operations/create.d.ts +2 -1
  5. package/dist/collections/operations/create.d.ts.map +1 -1
  6. package/dist/collections/operations/create.js +2 -1
  7. package/dist/collections/operations/create.js.map +1 -1
  8. package/dist/collections/operations/delete.d.ts +2 -1
  9. package/dist/collections/operations/delete.d.ts.map +1 -1
  10. package/dist/collections/operations/delete.js +2 -1
  11. package/dist/collections/operations/delete.js.map +1 -1
  12. package/dist/collections/operations/deleteByID.d.ts +2 -1
  13. package/dist/collections/operations/deleteByID.d.ts.map +1 -1
  14. package/dist/collections/operations/deleteByID.js +2 -1
  15. package/dist/collections/operations/deleteByID.js.map +1 -1
  16. package/dist/collections/operations/duplicate.d.ts +2 -1
  17. package/dist/collections/operations/duplicate.d.ts.map +1 -1
  18. package/dist/collections/operations/duplicate.js +2 -1
  19. package/dist/collections/operations/duplicate.js.map +1 -1
  20. package/dist/collections/operations/find.d.ts +2 -1
  21. package/dist/collections/operations/find.d.ts.map +1 -1
  22. package/dist/collections/operations/find.js +2 -1
  23. package/dist/collections/operations/find.js.map +1 -1
  24. package/dist/collections/operations/findByID.d.ts +2 -1
  25. package/dist/collections/operations/findByID.d.ts.map +1 -1
  26. package/dist/collections/operations/findByID.js +2 -1
  27. package/dist/collections/operations/findByID.js.map +1 -1
  28. package/dist/collections/operations/findVersionByID.d.ts +2 -1
  29. package/dist/collections/operations/findVersionByID.d.ts.map +1 -1
  30. package/dist/collections/operations/findVersionByID.js +2 -1
  31. package/dist/collections/operations/findVersionByID.js.map +1 -1
  32. package/dist/collections/operations/findVersions.d.ts +2 -1
  33. package/dist/collections/operations/findVersions.d.ts.map +1 -1
  34. package/dist/collections/operations/findVersions.js +2 -1
  35. package/dist/collections/operations/findVersions.js.map +1 -1
  36. package/dist/collections/operations/local/create.d.ts +2 -1
  37. package/dist/collections/operations/local/create.d.ts.map +1 -1
  38. package/dist/collections/operations/local/create.js +2 -1
  39. package/dist/collections/operations/local/create.js.map +1 -1
  40. package/dist/collections/operations/local/delete.d.ts +2 -1
  41. package/dist/collections/operations/local/delete.d.ts.map +1 -1
  42. package/dist/collections/operations/local/delete.js +2 -1
  43. package/dist/collections/operations/local/delete.js.map +1 -1
  44. package/dist/collections/operations/local/duplicate.d.ts +2 -1
  45. package/dist/collections/operations/local/duplicate.d.ts.map +1 -1
  46. package/dist/collections/operations/local/duplicate.js +2 -1
  47. package/dist/collections/operations/local/duplicate.js.map +1 -1
  48. package/dist/collections/operations/local/find.d.ts +3 -2
  49. package/dist/collections/operations/local/find.d.ts.map +1 -1
  50. package/dist/collections/operations/local/find.js.map +1 -1
  51. package/dist/collections/operations/local/findByID.d.ts +3 -2
  52. package/dist/collections/operations/local/findByID.d.ts.map +1 -1
  53. package/dist/collections/operations/local/findByID.js +2 -1
  54. package/dist/collections/operations/local/findByID.js.map +1 -1
  55. package/dist/collections/operations/local/findVersionByID.d.ts +2 -1
  56. package/dist/collections/operations/local/findVersionByID.d.ts.map +1 -1
  57. package/dist/collections/operations/local/findVersionByID.js +2 -1
  58. package/dist/collections/operations/local/findVersionByID.js.map +1 -1
  59. package/dist/collections/operations/local/findVersions.d.ts +2 -1
  60. package/dist/collections/operations/local/findVersions.d.ts.map +1 -1
  61. package/dist/collections/operations/local/findVersions.js +2 -1
  62. package/dist/collections/operations/local/findVersions.js.map +1 -1
  63. package/dist/collections/operations/local/restoreVersion.d.ts +2 -1
  64. package/dist/collections/operations/local/restoreVersion.d.ts.map +1 -1
  65. package/dist/collections/operations/local/restoreVersion.js +2 -1
  66. package/dist/collections/operations/local/restoreVersion.js.map +1 -1
  67. package/dist/collections/operations/local/update.d.ts +2 -1
  68. package/dist/collections/operations/local/update.d.ts.map +1 -1
  69. package/dist/collections/operations/local/update.js +2 -1
  70. package/dist/collections/operations/local/update.js.map +1 -1
  71. package/dist/collections/operations/restoreVersion.d.ts +2 -1
  72. package/dist/collections/operations/restoreVersion.d.ts.map +1 -1
  73. package/dist/collections/operations/restoreVersion.js +2 -1
  74. package/dist/collections/operations/restoreVersion.js.map +1 -1
  75. package/dist/collections/operations/update.d.ts +2 -1
  76. package/dist/collections/operations/update.d.ts.map +1 -1
  77. package/dist/collections/operations/update.js +2 -1
  78. package/dist/collections/operations/update.js.map +1 -1
  79. package/dist/collections/operations/updateByID.d.ts +2 -1
  80. package/dist/collections/operations/updateByID.d.ts.map +1 -1
  81. package/dist/collections/operations/updateByID.js +8 -6
  82. package/dist/collections/operations/updateByID.js.map +1 -1
  83. package/dist/database/sanitizeJoinQuery.d.ts +3 -3
  84. package/dist/database/sanitizeJoinQuery.d.ts.map +1 -1
  85. package/dist/fields/hooks/afterRead/index.d.ts +2 -1
  86. package/dist/fields/hooks/afterRead/index.d.ts.map +1 -1
  87. package/dist/fields/hooks/afterRead/index.js +2 -1
  88. package/dist/fields/hooks/afterRead/index.js.map +1 -1
  89. package/dist/fields/hooks/afterRead/promise.d.ts +3 -2
  90. package/dist/fields/hooks/afterRead/promise.d.ts.map +1 -1
  91. package/dist/fields/hooks/afterRead/promise.js +12 -1
  92. package/dist/fields/hooks/afterRead/promise.js.map +1 -1
  93. package/dist/fields/hooks/afterRead/relationshipPopulationPromise.d.ts +3 -2
  94. package/dist/fields/hooks/afterRead/relationshipPopulationPromise.d.ts.map +1 -1
  95. package/dist/fields/hooks/afterRead/relationshipPopulationPromise.js +7 -3
  96. package/dist/fields/hooks/afterRead/relationshipPopulationPromise.js.map +1 -1
  97. package/dist/fields/hooks/afterRead/traverseFields.d.ts +3 -2
  98. package/dist/fields/hooks/afterRead/traverseFields.d.ts.map +1 -1
  99. package/dist/fields/hooks/afterRead/traverseFields.js +2 -1
  100. package/dist/fields/hooks/afterRead/traverseFields.js.map +1 -1
  101. package/dist/globals/operations/findOne.d.ts +2 -1
  102. package/dist/globals/operations/findOne.d.ts.map +1 -1
  103. package/dist/globals/operations/findOne.js +2 -1
  104. package/dist/globals/operations/findOne.js.map +1 -1
  105. package/dist/globals/operations/findVersionByID.d.ts +2 -1
  106. package/dist/globals/operations/findVersionByID.d.ts.map +1 -1
  107. package/dist/globals/operations/findVersionByID.js +2 -1
  108. package/dist/globals/operations/findVersionByID.js.map +1 -1
  109. package/dist/globals/operations/findVersions.d.ts +2 -1
  110. package/dist/globals/operations/findVersions.d.ts.map +1 -1
  111. package/dist/globals/operations/findVersions.js +2 -1
  112. package/dist/globals/operations/findVersions.js.map +1 -1
  113. package/dist/globals/operations/local/findOne.d.ts +2 -1
  114. package/dist/globals/operations/local/findOne.d.ts.map +1 -1
  115. package/dist/globals/operations/local/findOne.js +2 -1
  116. package/dist/globals/operations/local/findOne.js.map +1 -1
  117. package/dist/globals/operations/local/findVersionByID.d.ts +2 -1
  118. package/dist/globals/operations/local/findVersionByID.d.ts.map +1 -1
  119. package/dist/globals/operations/local/findVersionByID.js +2 -1
  120. package/dist/globals/operations/local/findVersionByID.js.map +1 -1
  121. package/dist/globals/operations/local/findVersions.d.ts +2 -1
  122. package/dist/globals/operations/local/findVersions.d.ts.map +1 -1
  123. package/dist/globals/operations/local/findVersions.js +2 -1
  124. package/dist/globals/operations/local/findVersions.js.map +1 -1
  125. package/dist/globals/operations/local/restoreVersion.d.ts +2 -1
  126. package/dist/globals/operations/local/restoreVersion.d.ts.map +1 -1
  127. package/dist/globals/operations/local/restoreVersion.js +2 -1
  128. package/dist/globals/operations/local/restoreVersion.js.map +1 -1
  129. package/dist/globals/operations/local/update.d.ts +2 -1
  130. package/dist/globals/operations/local/update.d.ts.map +1 -1
  131. package/dist/globals/operations/local/update.js +2 -1
  132. package/dist/globals/operations/local/update.js.map +1 -1
  133. package/dist/globals/operations/restoreVersion.d.ts +2 -1
  134. package/dist/globals/operations/restoreVersion.d.ts.map +1 -1
  135. package/dist/globals/operations/restoreVersion.js +2 -1
  136. package/dist/globals/operations/restoreVersion.js.map +1 -1
  137. package/dist/globals/operations/update.d.ts +2 -1
  138. package/dist/globals/operations/update.d.ts.map +1 -1
  139. package/dist/globals/operations/update.js +2 -1
  140. package/dist/globals/operations/update.js.map +1 -1
  141. package/dist/index.d.ts +7 -0
  142. package/dist/index.d.ts.map +1 -1
  143. package/dist/index.js.map +1 -1
  144. package/dist/queues/config/jobsCollection.d.ts.map +1 -1
  145. package/dist/queues/config/jobsCollection.js +15 -13
  146. package/dist/queues/config/jobsCollection.js.map +1 -1
  147. package/dist/queues/config/types/index.d.ts +1 -1
  148. package/dist/queues/config/types/index.d.ts.map +1 -1
  149. package/dist/queues/config/types/index.js.map +1 -1
  150. package/dist/queues/operations/runJobs/index.js +1 -1
  151. package/dist/queues/operations/runJobs/index.js.map +1 -1
  152. package/dist/types/index.d.ts +5 -4
  153. package/dist/types/index.d.ts.map +1 -1
  154. package/dist/types/index.js.map +1 -1
  155. package/dist/utilities/configToJSONSchema.d.ts.map +1 -1
  156. package/dist/utilities/configToJSONSchema.js +35 -0
  157. package/dist/utilities/configToJSONSchema.js.map +1 -1
  158. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/collections/operations/updateByID.ts"],"sourcesContent":["import type { DeepPartial } from 'ts-essentials'\n\nimport httpStatus from 'http-status'\n\nimport type { FindOneArgs } from '../../database/types.js'\nimport type { Args } from '../../fields/hooks/beforeChange/index.js'\nimport type { CollectionSlug } from '../../index.js'\nimport type {\n PayloadRequest,\n SelectType,\n TransformCollectionWithSelect,\n} from '../../types/index.js'\nimport type {\n Collection,\n DataFromCollectionSlug,\n RequiredDataFromCollectionSlug,\n SelectFromCollectionSlug,\n} from '../config/types.js'\n\nimport { ensureUsernameOrEmail } from '../../auth/ensureUsernameOrEmail.js'\nimport executeAccess from '../../auth/executeAccess.js'\nimport { generatePasswordSaltHash } from '../../auth/strategies/local/generatePasswordSaltHash.js'\nimport { hasWhereAccessResult } from '../../auth/types.js'\nimport { combineQueries } from '../../database/combineQueries.js'\nimport { APIError, Forbidden, NotFound } from '../../errors/index.js'\nimport { afterChange } from '../../fields/hooks/afterChange/index.js'\nimport { afterRead } from '../../fields/hooks/afterRead/index.js'\nimport { beforeChange } from '../../fields/hooks/beforeChange/index.js'\nimport { beforeValidate } from '../../fields/hooks/beforeValidate/index.js'\nimport { deleteAssociatedFiles } from '../../uploads/deleteAssociatedFiles.js'\nimport { generateFileData } from '../../uploads/generateFileData.js'\nimport { unlinkTempFiles } from '../../uploads/unlinkTempFiles.js'\nimport { uploadFiles } from '../../uploads/uploadFiles.js'\nimport { checkDocumentLockStatus } from '../../utilities/checkDocumentLockStatus.js'\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { getLatestCollectionVersion } from '../../versions/getLatestCollectionVersion.js'\nimport { saveVersion } from '../../versions/saveVersion.js'\nimport { buildAfterOperation } from './utils.js'\n\nexport type Arguments<TSlug extends CollectionSlug> = {\n autosave?: boolean\n collection: Collection\n data: DeepPartial<RequiredDataFromCollectionSlug<TSlug>>\n depth?: number\n disableTransaction?: boolean\n disableVerificationEmail?: boolean\n draft?: boolean\n id: number | string\n overrideAccess?: boolean\n overrideLock?: boolean\n overwriteExistingFiles?: boolean\n publishSpecificLocale?: string\n req: PayloadRequest\n select?: SelectType\n showHiddenFields?: boolean\n}\n\nexport const updateByIDOperation = async <\n TSlug extends CollectionSlug,\n TSelect extends SelectFromCollectionSlug<TSlug> = SelectType,\n>(\n incomingArgs: Arguments<TSlug>,\n): Promise<TransformCollectionWithSelect<TSlug, TSelect>> => {\n let args = incomingArgs\n\n try {\n const shouldCommit = !args.disableTransaction && (await initTransaction(args.req))\n\n // /////////////////////////////////////\n // beforeOperation - Collection\n // /////////////////////////////////////\n\n await args.collection.config.hooks.beforeOperation.reduce(async (priorHook, hook) => {\n await priorHook\n\n args =\n (await hook({\n args,\n collection: args.collection.config,\n context: args.req.context,\n operation: 'update',\n req: args.req,\n })) || args\n }, Promise.resolve())\n\n if (args.publishSpecificLocale) {\n args.req.locale = args.publishSpecificLocale\n }\n\n const {\n id,\n autosave = false,\n collection: { config: collectionConfig },\n collection,\n depth,\n draft: draftArg = false,\n overrideAccess,\n overrideLock,\n overwriteExistingFiles = false,\n publishSpecificLocale,\n req: {\n fallbackLocale,\n locale,\n payload: { config },\n payload,\n },\n req,\n select,\n showHiddenFields,\n } = args\n\n if (!id) {\n throw new APIError('Missing ID of document to update.', httpStatus.BAD_REQUEST)\n }\n\n let { data } = args\n const password = data?.password\n const shouldSaveDraft = Boolean(draftArg && collectionConfig.versions.drafts)\n const shouldSavePassword = Boolean(password && collectionConfig.auth && !shouldSaveDraft)\n\n // /////////////////////////////////////\n // Access\n // /////////////////////////////////////\n\n const accessResults = !overrideAccess\n ? await executeAccess({ id, data, req }, collectionConfig.access.update)\n : true\n const hasWherePolicy = hasWhereAccessResult(accessResults)\n\n // /////////////////////////////////////\n // Retrieve document\n // /////////////////////////////////////\n\n const findOneArgs: FindOneArgs = {\n collection: collectionConfig.slug,\n locale,\n req,\n where: combineQueries({ id: { equals: id } }, accessResults),\n }\n\n const docWithLocales = await getLatestCollectionVersion({\n id,\n config: collectionConfig,\n payload,\n query: findOneArgs,\n req,\n })\n\n if (!docWithLocales && !hasWherePolicy) {\n throw new NotFound(req.t)\n }\n if (!docWithLocales && hasWherePolicy) {\n throw new Forbidden(req.t)\n }\n\n // /////////////////////////////////////\n // Handle potentially locked documents\n // /////////////////////////////////////\n\n await checkDocumentLockStatus({\n id,\n collectionSlug: collectionConfig.slug,\n lockErrorMessage: `Document with ID ${id} is currently locked by another user and cannot be updated.`,\n overrideLock,\n req,\n })\n\n const originalDoc = await afterRead({\n collection: collectionConfig,\n context: req.context,\n depth: 0,\n doc: docWithLocales,\n draft: draftArg,\n fallbackLocale: null,\n global: null,\n locale,\n overrideAccess: true,\n req,\n showHiddenFields: true,\n })\n\n if (args.collection.config.auth) {\n ensureUsernameOrEmail<TSlug>({\n authOptions: args.collection.config.auth,\n collectionSlug: args.collection.config.slug,\n data: args.data,\n operation: 'update',\n originalDoc,\n req: args.req,\n })\n }\n\n // /////////////////////////////////////\n // Generate data for all files and sizes\n // /////////////////////////////////////\n\n const { data: newFileData, files: filesToUpload } = await generateFileData({\n collection,\n config,\n data,\n operation: 'update',\n overwriteExistingFiles,\n req,\n throwOnMissingFile: false,\n })\n\n data = newFileData\n\n // /////////////////////////////////////\n // Delete any associated files\n // /////////////////////////////////////\n\n await deleteAssociatedFiles({\n collectionConfig,\n config,\n doc: docWithLocales,\n files: filesToUpload,\n overrideDelete: false,\n req,\n })\n\n // /////////////////////////////////////\n // beforeValidate - Fields\n // /////////////////////////////////////\n\n data = await beforeValidate<DeepPartial<DataFromCollectionSlug<TSlug>>>({\n id,\n collection: collectionConfig,\n context: req.context,\n data,\n doc: originalDoc,\n global: null,\n operation: 'update',\n overrideAccess,\n req,\n })\n\n // /////////////////////////////////////\n // beforeValidate - Collection\n // /////////////////////////////////////\n\n await collectionConfig.hooks.beforeValidate.reduce(async (priorHook, hook) => {\n await priorHook\n\n data =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n data,\n operation: 'update',\n originalDoc,\n req,\n })) || data\n }, Promise.resolve())\n\n // /////////////////////////////////////\n // Write files to local storage\n // /////////////////////////////////////\n\n if (!collectionConfig.upload.disableLocalStorage) {\n await uploadFiles(payload, filesToUpload, req)\n }\n\n // /////////////////////////////////////\n // beforeChange - Collection\n // /////////////////////////////////////\n\n await collectionConfig.hooks.beforeChange.reduce(async (priorHook, hook) => {\n await priorHook\n\n data =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n data,\n operation: 'update',\n originalDoc,\n req,\n })) || data\n }, Promise.resolve())\n\n // /////////////////////////////////////\n // beforeChange - Fields\n // /////////////////////////////////////\n\n let publishedDocWithLocales = docWithLocales\n let versionSnapshotResult\n\n const beforeChangeArgs: Args<DataFromCollectionSlug<TSlug>> = {\n id,\n collection: collectionConfig,\n context: req.context,\n data: { ...data, id },\n doc: originalDoc,\n docWithLocales: undefined,\n global: null,\n operation: 'update',\n req,\n skipValidation:\n shouldSaveDraft &&\n collectionConfig.versions.drafts &&\n !collectionConfig.versions.drafts.validate &&\n data._status !== 'published',\n }\n\n if (publishSpecificLocale) {\n publishedDocWithLocales = await getLatestCollectionVersion({\n id,\n config: collectionConfig,\n payload,\n published: true,\n query: findOneArgs,\n req,\n })\n\n versionSnapshotResult = await beforeChange({\n ...beforeChangeArgs,\n docWithLocales,\n })\n }\n\n let result = await beforeChange({\n ...beforeChangeArgs,\n docWithLocales: publishedDocWithLocales,\n })\n\n // /////////////////////////////////////\n // Handle potential password update\n // /////////////////////////////////////\n\n const dataToUpdate: Record<string, unknown> = { ...result }\n\n if (shouldSavePassword && typeof password === 'string') {\n const { hash, salt } = await generatePasswordSaltHash({\n collection: collectionConfig,\n password,\n req,\n })\n dataToUpdate.salt = salt\n dataToUpdate.hash = hash\n delete dataToUpdate.password\n delete data.password\n }\n\n // /////////////////////////////////////\n // Update\n // /////////////////////////////////////\n\n if (!shouldSaveDraft || data._status === 'published') {\n result = await req.payload.db.updateOne({\n id,\n collection: collectionConfig.slug,\n data: dataToUpdate,\n locale,\n req,\n select,\n })\n }\n\n // /////////////////////////////////////\n // Create version\n // /////////////////////////////////////\n\n if (collectionConfig.versions) {\n result = await saveVersion({\n id,\n autosave,\n collection: collectionConfig,\n docWithLocales: result,\n draft: shouldSaveDraft,\n payload,\n publishSpecificLocale,\n req,\n select,\n snapshot: versionSnapshotResult,\n })\n }\n\n // /////////////////////////////////////\n // afterRead - Fields\n // /////////////////////////////////////\n\n result = await afterRead({\n collection: collectionConfig,\n context: req.context,\n depth,\n doc: result,\n draft: draftArg,\n fallbackLocale,\n global: null,\n locale,\n overrideAccess,\n req,\n select,\n showHiddenFields,\n })\n\n // /////////////////////////////////////\n // afterRead - Collection\n // /////////////////////////////////////\n\n await collectionConfig.hooks.afterRead.reduce(async (priorHook, hook) => {\n await priorHook\n\n result =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n doc: result,\n req,\n })) || result\n }, Promise.resolve())\n\n // /////////////////////////////////////\n // afterChange - Fields\n // /////////////////////////////////////\n\n result = await afterChange({\n collection: collectionConfig,\n context: req.context,\n data,\n doc: result,\n global: null,\n operation: 'update',\n previousDoc: originalDoc,\n req,\n })\n\n // /////////////////////////////////////\n // afterChange - Collection\n // /////////////////////////////////////\n\n await collectionConfig.hooks.afterChange.reduce(async (priorHook, hook) => {\n await priorHook\n\n result =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n doc: result,\n operation: 'update',\n previousDoc: originalDoc,\n req,\n })) || result\n }, Promise.resolve())\n\n // /////////////////////////////////////\n // afterOperation - Collection\n // /////////////////////////////////////\n\n result = await buildAfterOperation({\n args,\n collection: collectionConfig,\n operation: 'updateByID',\n result,\n })\n\n await unlinkTempFiles({\n collectionConfig,\n config,\n req,\n })\n\n // /////////////////////////////////////\n // Return results\n // /////////////////////////////////////\n\n if (shouldCommit) {\n await commitTransaction(req)\n }\n\n return result as TransformCollectionWithSelect<TSlug, TSelect>\n } catch (error: unknown) {\n await killTransaction(args.req)\n throw error\n }\n}\n"],"names":["httpStatus","ensureUsernameOrEmail","executeAccess","generatePasswordSaltHash","hasWhereAccessResult","combineQueries","APIError","Forbidden","NotFound","afterChange","afterRead","beforeChange","beforeValidate","deleteAssociatedFiles","generateFileData","unlinkTempFiles","uploadFiles","checkDocumentLockStatus","commitTransaction","initTransaction","killTransaction","getLatestCollectionVersion","saveVersion","buildAfterOperation","updateByIDOperation","incomingArgs","args","shouldCommit","disableTransaction","req","collection","config","hooks","beforeOperation","reduce","priorHook","hook","context","operation","Promise","resolve","publishSpecificLocale","locale","id","autosave","collectionConfig","depth","draft","draftArg","overrideAccess","overrideLock","overwriteExistingFiles","fallbackLocale","payload","select","showHiddenFields","BAD_REQUEST","data","password","shouldSaveDraft","Boolean","versions","drafts","shouldSavePassword","auth","accessResults","access","update","hasWherePolicy","findOneArgs","slug","where","equals","docWithLocales","query","t","collectionSlug","lockErrorMessage","originalDoc","doc","global","authOptions","newFileData","files","filesToUpload","throwOnMissingFile","overrideDelete","upload","disableLocalStorage","publishedDocWithLocales","versionSnapshotResult","beforeChangeArgs","undefined","skipValidation","validate","_status","published","result","dataToUpdate","hash","salt","db","updateOne","snapshot","previousDoc","error"],"mappings":"AAEA,OAAOA,gBAAgB,cAAa;AAiBpC,SAASC,qBAAqB,QAAQ,sCAAqC;AAC3E,OAAOC,mBAAmB,8BAA6B;AACvD,SAASC,wBAAwB,QAAQ,0DAAyD;AAClG,SAASC,oBAAoB,QAAQ,sBAAqB;AAC1D,SAASC,cAAc,QAAQ,mCAAkC;AACjE,SAASC,QAAQ,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,wBAAuB;AACrE,SAASC,WAAW,QAAQ,0CAAyC;AACrE,SAASC,SAAS,QAAQ,wCAAuC;AACjE,SAASC,YAAY,QAAQ,2CAA0C;AACvE,SAASC,cAAc,QAAQ,6CAA4C;AAC3E,SAASC,qBAAqB,QAAQ,yCAAwC;AAC9E,SAASC,gBAAgB,QAAQ,oCAAmC;AACpE,SAASC,eAAe,QAAQ,mCAAkC;AAClE,SAASC,WAAW,QAAQ,+BAA8B;AAC1D,SAASC,uBAAuB,QAAQ,6CAA4C;AACpF,SAASC,iBAAiB,QAAQ,uCAAsC;AACxE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,0BAA0B,QAAQ,+CAA8C;AACzF,SAASC,WAAW,QAAQ,gCAA+B;AAC3D,SAASC,mBAAmB,QAAQ,aAAY;AAoBhD,OAAO,MAAMC,sBAAsB,OAIjCC;IAEA,IAAIC,OAAOD;IAEX,IAAI;QACF,MAAME,eAAe,CAACD,KAAKE,kBAAkB,IAAK,MAAMT,gBAAgBO,KAAKG,GAAG;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L3D,WAAW;gBACXkE,aAAa1B;gBACbjD;YACF,MAAOoE;QACX,GAAG1D,QAAQC,OAAO;QAElB,wCAAwC;QACxC,8BAA8B;QAC9B,wCAAwC;QAExCyD,SAAS,MAAM1E,oBAAoB;YACjCG;YACAI,YAAYe;YACZP,WAAW;YACX2D;QACF;QAEA,MAAMlF,gBAAgB;YACpB8B;YACAd;YACAF;QACF;QAEA,wCAAwC;QACxC,iBAAiB;QACjB,wCAAwC;QAExC,IAAIF,cAAc;YAChB,MAAMT,kBAAkBW;QAC1B;QAEA,OAAOoE;IACT,EAAE,OAAOQ,OAAgB;QACvB,MAAMrF,gBAAgBM,KAAKG,GAAG;QAC9B,MAAM4E;IACR;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../src/collections/operations/updateByID.ts"],"sourcesContent":["import type { DeepPartial } from 'ts-essentials'\n\nimport httpStatus from 'http-status'\n\nimport type { FindOneArgs } from '../../database/types.js'\nimport type { Args } from '../../fields/hooks/beforeChange/index.js'\nimport type { CollectionSlug } from '../../index.js'\nimport type {\n PayloadRequest,\n PopulateType,\n SelectType,\n TransformCollectionWithSelect,\n} from '../../types/index.js'\nimport type {\n Collection,\n DataFromCollectionSlug,\n RequiredDataFromCollectionSlug,\n SelectFromCollectionSlug,\n} from '../config/types.js'\n\nimport { ensureUsernameOrEmail } from '../../auth/ensureUsernameOrEmail.js'\nimport executeAccess from '../../auth/executeAccess.js'\nimport { generatePasswordSaltHash } from '../../auth/strategies/local/generatePasswordSaltHash.js'\nimport { hasWhereAccessResult } from '../../auth/types.js'\nimport { combineQueries } from '../../database/combineQueries.js'\nimport { APIError, Forbidden, NotFound } from '../../errors/index.js'\nimport { afterChange } from '../../fields/hooks/afterChange/index.js'\nimport { afterRead } from '../../fields/hooks/afterRead/index.js'\nimport { beforeChange } from '../../fields/hooks/beforeChange/index.js'\nimport { beforeValidate } from '../../fields/hooks/beforeValidate/index.js'\nimport { deleteAssociatedFiles } from '../../uploads/deleteAssociatedFiles.js'\nimport { generateFileData } from '../../uploads/generateFileData.js'\nimport { unlinkTempFiles } from '../../uploads/unlinkTempFiles.js'\nimport { uploadFiles } from '../../uploads/uploadFiles.js'\nimport { checkDocumentLockStatus } from '../../utilities/checkDocumentLockStatus.js'\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { getLatestCollectionVersion } from '../../versions/getLatestCollectionVersion.js'\nimport { saveVersion } from '../../versions/saveVersion.js'\nimport { buildAfterOperation } from './utils.js'\n\nexport type Arguments<TSlug extends CollectionSlug> = {\n autosave?: boolean\n collection: Collection\n data: DeepPartial<RequiredDataFromCollectionSlug<TSlug>>\n depth?: number\n disableTransaction?: boolean\n disableVerificationEmail?: boolean\n draft?: boolean\n id: number | string\n overrideAccess?: boolean\n overrideLock?: boolean\n overwriteExistingFiles?: boolean\n populate?: PopulateType\n publishSpecificLocale?: string\n req: PayloadRequest\n select?: SelectType\n showHiddenFields?: boolean\n}\n\nexport const updateByIDOperation = async <\n TSlug extends CollectionSlug,\n TSelect extends SelectFromCollectionSlug<TSlug> = SelectType,\n>(\n incomingArgs: Arguments<TSlug>,\n): Promise<TransformCollectionWithSelect<TSlug, TSelect>> => {\n let args = incomingArgs\n\n try {\n const shouldCommit = !args.disableTransaction && (await initTransaction(args.req))\n\n // /////////////////////////////////////\n // beforeOperation - Collection\n // /////////////////////////////////////\n\n await args.collection.config.hooks.beforeOperation.reduce(async (priorHook, hook) => {\n await priorHook\n\n args =\n (await hook({\n args,\n collection: args.collection.config,\n context: args.req.context,\n operation: 'update',\n req: args.req,\n })) || args\n }, Promise.resolve())\n\n if (args.publishSpecificLocale) {\n args.req.locale = args.publishSpecificLocale\n }\n\n const {\n id,\n autosave = false,\n collection: { config: collectionConfig },\n collection,\n depth,\n draft: draftArg = false,\n overrideAccess,\n overrideLock,\n overwriteExistingFiles = false,\n populate,\n publishSpecificLocale,\n req: {\n fallbackLocale,\n locale,\n payload: { config },\n payload,\n },\n req,\n select,\n showHiddenFields,\n } = args\n\n if (!id) {\n throw new APIError('Missing ID of document to update.', httpStatus.BAD_REQUEST)\n }\n\n let { data } = args\n const password = data?.password\n const shouldSaveDraft = Boolean(draftArg && collectionConfig.versions.drafts)\n const shouldSavePassword = Boolean(password && collectionConfig.auth && !shouldSaveDraft)\n\n // /////////////////////////////////////\n // Access\n // /////////////////////////////////////\n\n const accessResults = !overrideAccess\n ? await executeAccess({ id, data, req }, collectionConfig.access.update)\n : true\n const hasWherePolicy = hasWhereAccessResult(accessResults)\n\n // /////////////////////////////////////\n // Retrieve document\n // /////////////////////////////////////\n\n const findOneArgs: FindOneArgs = {\n collection: collectionConfig.slug,\n locale,\n req,\n where: combineQueries({ id: { equals: id } }, accessResults),\n }\n\n const docWithLocales = await getLatestCollectionVersion({\n id,\n config: collectionConfig,\n payload,\n query: findOneArgs,\n req,\n })\n\n if (!docWithLocales && !hasWherePolicy) {\n throw new NotFound(req.t)\n }\n if (!docWithLocales && hasWherePolicy) {\n throw new Forbidden(req.t)\n }\n\n // /////////////////////////////////////\n // Handle potentially locked documents\n // /////////////////////////////////////\n\n await checkDocumentLockStatus({\n id,\n collectionSlug: collectionConfig.slug,\n lockErrorMessage: `Document with ID ${id} is currently locked by another user and cannot be updated.`,\n overrideLock,\n req,\n })\n\n const originalDoc = await afterRead({\n collection: collectionConfig,\n context: req.context,\n depth: 0,\n doc: docWithLocales,\n draft: draftArg,\n fallbackLocale: null,\n global: null,\n locale,\n overrideAccess: true,\n req,\n showHiddenFields: true,\n })\n\n if (args.collection.config.auth) {\n ensureUsernameOrEmail<TSlug>({\n authOptions: args.collection.config.auth,\n collectionSlug: args.collection.config.slug,\n data: args.data,\n operation: 'update',\n originalDoc,\n req: args.req,\n })\n }\n\n // /////////////////////////////////////\n // Generate data for all files and sizes\n // /////////////////////////////////////\n\n const { data: newFileData, files: filesToUpload } = await generateFileData({\n collection,\n config,\n data,\n operation: 'update',\n overwriteExistingFiles,\n req,\n throwOnMissingFile: false,\n })\n\n data = newFileData\n\n // /////////////////////////////////////\n // Delete any associated files\n // /////////////////////////////////////\n\n await deleteAssociatedFiles({\n collectionConfig,\n config,\n doc: docWithLocales,\n files: filesToUpload,\n overrideDelete: false,\n req,\n })\n\n // /////////////////////////////////////\n // beforeValidate - Fields\n // /////////////////////////////////////\n\n data = await beforeValidate<DeepPartial<DataFromCollectionSlug<TSlug>>>({\n id,\n collection: collectionConfig,\n context: req.context,\n data,\n doc: originalDoc,\n global: null,\n operation: 'update',\n overrideAccess,\n req,\n })\n\n // /////////////////////////////////////\n // beforeValidate - Collection\n // /////////////////////////////////////\n\n await collectionConfig.hooks.beforeValidate.reduce(async (priorHook, hook) => {\n await priorHook\n\n data =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n data,\n operation: 'update',\n originalDoc,\n req,\n })) || data\n }, Promise.resolve())\n\n // /////////////////////////////////////\n // Write files to local storage\n // /////////////////////////////////////\n\n if (!collectionConfig.upload.disableLocalStorage) {\n await uploadFiles(payload, filesToUpload, req)\n }\n\n // /////////////////////////////////////\n // beforeChange - Collection\n // /////////////////////////////////////\n\n await collectionConfig.hooks.beforeChange.reduce(async (priorHook, hook) => {\n await priorHook\n\n data =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n data,\n operation: 'update',\n originalDoc,\n req,\n })) || data\n }, Promise.resolve())\n\n // /////////////////////////////////////\n // beforeChange - Fields\n // /////////////////////////////////////\n\n let publishedDocWithLocales = docWithLocales\n let versionSnapshotResult\n\n const beforeChangeArgs: Args<DataFromCollectionSlug<TSlug>> = {\n id,\n collection: collectionConfig,\n context: req.context,\n data: { ...data, id },\n doc: originalDoc,\n docWithLocales: undefined,\n global: null,\n operation: 'update',\n req,\n skipValidation:\n shouldSaveDraft &&\n collectionConfig.versions.drafts &&\n !collectionConfig.versions.drafts.validate &&\n data._status !== 'published',\n }\n\n if (publishSpecificLocale) {\n versionSnapshotResult = await beforeChange({\n ...beforeChangeArgs,\n docWithLocales,\n })\n\n const lastPublished = await getLatestCollectionVersion({\n id,\n config: collectionConfig,\n payload,\n published: true,\n query: findOneArgs,\n req,\n })\n\n publishedDocWithLocales = lastPublished ? lastPublished : {}\n }\n\n let result = await beforeChange({\n ...beforeChangeArgs,\n docWithLocales: publishedDocWithLocales,\n })\n\n // /////////////////////////////////////\n // Handle potential password update\n // /////////////////////////////////////\n\n const dataToUpdate: Record<string, unknown> = { ...result }\n\n if (shouldSavePassword && typeof password === 'string') {\n const { hash, salt } = await generatePasswordSaltHash({\n collection: collectionConfig,\n password,\n req,\n })\n dataToUpdate.salt = salt\n dataToUpdate.hash = hash\n delete dataToUpdate.password\n delete data.password\n }\n\n // /////////////////////////////////////\n // Update\n // /////////////////////////////////////\n\n if (!shouldSaveDraft || data._status === 'published') {\n result = await req.payload.db.updateOne({\n id,\n collection: collectionConfig.slug,\n data: dataToUpdate,\n locale,\n req,\n select,\n })\n }\n\n // /////////////////////////////////////\n // Create version\n // /////////////////////////////////////\n\n if (collectionConfig.versions) {\n result = await saveVersion({\n id,\n autosave,\n collection: collectionConfig,\n docWithLocales: result,\n draft: shouldSaveDraft,\n payload,\n publishSpecificLocale,\n req,\n select,\n snapshot: versionSnapshotResult,\n })\n }\n\n // /////////////////////////////////////\n // afterRead - Fields\n // /////////////////////////////////////\n\n result = await afterRead({\n collection: collectionConfig,\n context: req.context,\n depth,\n doc: result,\n draft: draftArg,\n fallbackLocale,\n global: null,\n locale,\n overrideAccess,\n populate,\n req,\n select,\n showHiddenFields,\n })\n\n // /////////////////////////////////////\n // afterRead - Collection\n // /////////////////////////////////////\n\n await collectionConfig.hooks.afterRead.reduce(async (priorHook, hook) => {\n await priorHook\n\n result =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n doc: result,\n req,\n })) || result\n }, Promise.resolve())\n\n // /////////////////////////////////////\n // afterChange - Fields\n // /////////////////////////////////////\n\n result = await afterChange({\n collection: collectionConfig,\n context: req.context,\n data,\n doc: result,\n global: null,\n operation: 'update',\n previousDoc: originalDoc,\n req,\n })\n\n // /////////////////////////////////////\n // afterChange - Collection\n // /////////////////////////////////////\n\n await collectionConfig.hooks.afterChange.reduce(async (priorHook, hook) => {\n await priorHook\n\n result =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n doc: result,\n operation: 'update',\n previousDoc: originalDoc,\n req,\n })) || result\n }, Promise.resolve())\n\n // /////////////////////////////////////\n // afterOperation - Collection\n // /////////////////////////////////////\n\n result = await buildAfterOperation({\n args,\n collection: collectionConfig,\n operation: 'updateByID',\n result,\n })\n\n await unlinkTempFiles({\n collectionConfig,\n config,\n req,\n })\n\n // /////////////////////////////////////\n // Return results\n // /////////////////////////////////////\n\n if (shouldCommit) {\n await commitTransaction(req)\n }\n\n return result as TransformCollectionWithSelect<TSlug, TSelect>\n } catch (error: unknown) {\n await killTransaction(args.req)\n throw error\n }\n}\n"],"names":["httpStatus","ensureUsernameOrEmail","executeAccess","generatePasswordSaltHash","hasWhereAccessResult","combineQueries","APIError","Forbidden","NotFound","afterChange","afterRead","beforeChange","beforeValidate","deleteAssociatedFiles","generateFileData","unlinkTempFiles","uploadFiles","checkDocumentLockStatus","commitTransaction","initTransaction","killTransaction","getLatestCollectionVersion","saveVersion","buildAfterOperation","updateByIDOperation","incomingArgs","args","shouldCommit","disableTransaction","req","collection","config","hooks","beforeOperation","reduce","priorHook","hook","context","operation","Promise","resolve","publishSpecificLocale","locale","id","autosave","collectionConfig","depth","draft","draftArg","overrideAccess","overrideLock","overwriteExistingFiles","populate","fallbackLocale","payload","select","showHiddenFields","BAD_REQUEST","data","password","shouldSaveDraft","Boolean","versions","drafts","shouldSavePassword","auth","accessResults","access","update","hasWherePolicy","findOneArgs","slug","where","equals","docWithLocales","query","t","collectionSlug","lockErrorMessage","originalDoc","doc","global","authOptions","newFileData","files","filesToUpload","throwOnMissingFile","overrideDelete","upload","disableLocalStorage","publishedDocWithLocales","versionSnapshotResult","beforeChangeArgs","undefined","skipValidation","validate","_status","lastP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WAAW;YACX6D;QACF;QAEA,MAAMpF,gBAAgB;YACpB8B;YACAd;YACAF;QACF;QAEA,wCAAwC;QACxC,iBAAiB;QACjB,wCAAwC;QAExC,IAAIF,cAAc;YAChB,MAAMT,kBAAkBW;QAC1B;QAEA,OAAOsE;IACT,EAAE,OAAOQ,OAAgB;QACvB,MAAMvF,gBAAgBM,KAAKG,GAAG;QAC9B,MAAM8E;IACR;AACF,EAAC"}
@@ -11,12 +11,12 @@ type Args = {
11
11
  * * Combines the access result for joined collection
12
12
  * * Combines the default join's `where`
13
13
  */
14
- export declare const sanitizeJoinQuery: ({ collectionConfig, joins: joinsQuery, overrideAccess, req, }: Args) => Promise<false | {
15
- [schemaPath: string]: false | {
14
+ export declare const sanitizeJoinQuery: ({ collectionConfig, joins: joinsQuery, overrideAccess, req, }: Args) => Promise<false | Partial<{
15
+ [x: string]: false | {
16
16
  limit?: number;
17
17
  sort?: string;
18
18
  where?: import("../types/index.js").Where;
19
19
  };
20
- }>;
20
+ }>>;
21
21
  export {};
22
22
  //# sourceMappingURL=sanitizeJoinQuery.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sanitizeJoinQuery.d.ts","sourceRoot":"","sources":["../../src/database/sanitizeJoinQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAA;AAC/E,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAOlE,KAAK,IAAI,GAAG;IACV,gBAAgB,EAAE,yBAAyB,CAAA;IAC3C,KAAK,CAAC,EAAE,SAAS,CAAA;IACjB,cAAc,EAAE,OAAO,CAAA;IACvB,GAAG,EAAE,cAAc,CAAA;CACpB,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,kEAK3B,IAAI;;;;;;EAkEN,CAAA"}
1
+ {"version":3,"file":"sanitizeJoinQuery.d.ts","sourceRoot":"","sources":["../../src/database/sanitizeJoinQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAA;AAC/E,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAOlE,KAAK,IAAI,GAAG;IACV,gBAAgB,EAAE,yBAAyB,CAAA;IAC3C,KAAK,CAAC,EAAE,SAAS,CAAA;IACjB,cAAc,EAAE,OAAO,CAAA;IACvB,GAAG,EAAE,cAAc,CAAA;CACpB,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,kEAK3B,IAAI;;;;;;GAkEN,CAAA"}
@@ -1,7 +1,7 @@
1
1
  import type { SanitizedCollectionConfig } from '../../../collections/config/types.js';
2
2
  import type { SanitizedGlobalConfig } from '../../../globals/config/types.js';
3
3
  import type { RequestContext } from '../../../index.js';
4
- import type { JsonObject, PayloadRequest, SelectType } from '../../../types/index.js';
4
+ import type { JsonObject, PayloadRequest, PopulateType, SelectType } from '../../../types/index.js';
5
5
  type Args<T extends JsonObject> = {
6
6
  collection: null | SanitizedCollectionConfig;
7
7
  context: RequestContext;
@@ -15,6 +15,7 @@ type Args<T extends JsonObject> = {
15
15
  global: null | SanitizedGlobalConfig;
16
16
  locale: string;
17
17
  overrideAccess: boolean;
18
+ populate?: PopulateType;
18
19
  req: PayloadRequest;
19
20
  select?: SelectType;
20
21
  showHiddenFields: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/fields/hooks/afterRead/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAA;AACrF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAA;AAC7E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAMrF,KAA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B,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,CAAC,CAAA;IACN,KAAK,EAAE,OAAO,CAAA;IACd,cAAc,EAAE,IAAI,GAAG,MAAM,CAAA;IAC7B,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,MAAM,EAAE,IAAI,GAAG,qBAAqB,CAAA;IACpC,MAAM,EAAE,MAAM,CAAA;IACd,cAAc,EAAE,OAAO,CAAA;IACvB,QAAQ,CAAC,EAAE,YAAY,CAAA;IACvB,GAAG,EAAE,cAAc,CAAA;IACnB,MAAM,CAAC,EAAE,UAAU,CAAA;IACnB,gBAAgB,EAAE,OAAO,CAAA;CAC1B,CAAA;AAED;;;;;;;;GAQG;AAEH,wBAAsB,SAAS,CAAC,CAAC,SAAS,UAAU,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAgE/E"}
@@ -10,7 +10,7 @@ import { traverseFields } from './traverseFields.js';
10
10
  * - Execute read access control
11
11
  * - Populate relationships
12
12
  */ export async function afterRead(args) {
13
- const { collection, context, currentDepth: incomingCurrentDepth, depth: incomingDepth, doc: incomingDoc, draft, fallbackLocale, findMany, flattenLocales = true, global, locale, overrideAccess, req, select, showHiddenFields } = args;
13
+ const { collection, context, currentDepth: incomingCurrentDepth, depth: incomingDepth, doc: incomingDoc, draft, fallbackLocale, findMany, flattenLocales = true, global, locale, overrideAccess, populate, req, select, showHiddenFields } = args;
14
14
  const doc = deepCopyObjectSimple(incomingDoc);
15
15
  const fieldPromises = [];
16
16
  const populationPromises = [];
@@ -35,6 +35,7 @@ import { traverseFields } from './traverseFields.js';
35
35
  locale,
36
36
  overrideAccess,
37
37
  path: [],
38
+ populate,
38
39
  populationPromises,
39
40
  req,
40
41
  schemaPath: [],
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/fields/hooks/afterRead/index.ts"],"sourcesContent":["import type { SanitizedCollectionConfig } from '../../../collections/config/types.js'\nimport type { SanitizedGlobalConfig } from '../../../globals/config/types.js'\nimport type { RequestContext } from '../../../index.js'\nimport type { JsonObject, PayloadRequest, SelectType } from '../../../types/index.js'\n\nimport { deepCopyObjectSimple } from '../../../utilities/deepCopyObject.js'\nimport { getSelectMode } from '../../../utilities/getSelectMode.js'\nimport { traverseFields } from './traverseFields.js'\n\ntype Args<T extends JsonObject> = {\n collection: null | SanitizedCollectionConfig\n context: RequestContext\n currentDepth?: number\n depth: number\n doc: T\n draft: boolean\n fallbackLocale: null | string\n findMany?: boolean\n flattenLocales?: boolean\n global: null | SanitizedGlobalConfig\n locale: string\n overrideAccess: boolean\n req: PayloadRequest\n select?: SelectType\n showHiddenFields: boolean\n}\n\n/**\n * This function is responsible for the following actions, in order:\n * - Remove hidden fields from response\n * - Flatten locales into requested locale. If the input doc contains all locales, the output doc after this function will only contain the requested locale.\n * - Sanitize outgoing data (point field, etc.)\n * - Execute field hooks\n * - Execute read access control\n * - Populate relationships\n */\n\nexport async function afterRead<T extends JsonObject>(args: Args<T>): Promise<T> {\n const {\n collection,\n context,\n currentDepth: incomingCurrentDepth,\n depth: incomingDepth,\n doc: incomingDoc,\n draft,\n fallbackLocale,\n findMany,\n flattenLocales = true,\n global,\n locale,\n overrideAccess,\n req,\n select,\n showHiddenFields,\n } = args\n\n const doc = deepCopyObjectSimple(incomingDoc)\n const fieldPromises = []\n const populationPromises = []\n\n let depth =\n incomingDepth || incomingDepth === 0\n ? parseInt(String(incomingDepth), 10)\n : req.payload.config.defaultDepth\n if (depth > req.payload.config.maxDepth) {\n depth = req.payload.config.maxDepth\n }\n\n const currentDepth = incomingCurrentDepth || 1\n\n traverseFields({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: collection?.fields || global?.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n path: [],\n populationPromises,\n req,\n schemaPath: [],\n select,\n selectMode: select ? getSelectMode(select) : undefined,\n showHiddenFields,\n siblingDoc: doc,\n })\n\n await Promise.all(fieldPromises)\n await Promise.all(populationPromises)\n\n return doc\n}\n"],"names":["deepCopyObjectSimple","getSelectMode","traverseFields","afterRead","args","collection","context","currentDepth","incomingCurrentDepth","depth","incomingDepth","doc","incomingDoc","draft","fallbackLocale","findMany","flattenLocales","global","locale","overrideAccess","req","select","showHiddenFields","fieldPromises","populationPromises","parseInt","String","payload","config","defaultDepth","maxDepth","fields","path","schemaPath","selectMode","undefined","siblingDoc","Promise","all"],"mappings":"AAKA,SAASA,oBAAoB,QAAQ,uCAAsC;AAC3E,SAASC,aAAa,QAAQ,sCAAqC;AACnE,SAASC,cAAc,QAAQ,sBAAqB;AAoBpD;;;;;;;;CAQC,GAED,OAAO,eAAeC,UAAgCC,IAAa;IACjE,MAAM,EACJC,UAAU,EACVC,OAAO,EACPC,cAAcC,oBAAoB,EAClCC,OAAOC,aAAa,EACpBC,KAAKC,WAAW,EAChBC,KAAK,EACLC,cAAc,EACdC,QAAQ,EACRC,iBAAiB,IAAI,EACrBC,MAAM,EACNC,MAAM,EACNC,cAAc,EACdC,GAAG,EACHC,MAAM,EACNC,gBAAgB,EACjB,GAAGlB;IAEJ,MAAMO,MAAMX,qBAAqBY;IACjC,MAAMW,gBAAgB,EAAE;IACxB,MAAMC,qBAAqB,EAAE;IAE7B,IAAIf,QACFC,iBAAiBA,kBAAkB,IAC/Be,SAASC,OAAOhB,gBAAgB,MAChCU,IAAIO,OAAO,CAACC,MAAM,CAACC,YAAY;IACrC,IAAIpB,QAAQW,IAAIO,OAAO,CAACC,MAAM,CAACE,QAAQ,EAAE;QACvCrB,QAAQW,IAAIO,OAAO,CAACC,MAAM,CAACE,QAAQ;IACrC;IAEA,MAAMvB,eAAeC,wBAAwB;IAE7CN,eAAe;QACbG;QACAC;QACAC;QACAE;QACAE;QACAE;QACAC;QACAS;QACAQ,QAAQ1B,YAAY0B,UAAUd,QAAQc;QACtChB;QACAC;QACAC;QACAC;QACAC;QACAa,MAAM,EAAE;QACRR;QACAJ;QACAa,YAAY,EAAE;QACdZ;QACAa,YAAYb,SAASpB,cAAcoB,UAAUc;QAC7Cb;QACAc,YAAYzB;IACd;IAEA,MAAM0B,QAAQC,GAAG,CAACf;IAClB,MAAMc,QAAQC,GAAG,CAACd;IAElB,OAAOb;AACT"}
1
+ {"version":3,"sources":["../../../../src/fields/hooks/afterRead/index.ts"],"sourcesContent":["import type { SanitizedCollectionConfig } from '../../../collections/config/types.js'\nimport type { SanitizedGlobalConfig } from '../../../globals/config/types.js'\nimport type { RequestContext } from '../../../index.js'\nimport type { JsonObject, PayloadRequest, PopulateType, SelectType } from '../../../types/index.js'\n\nimport { deepCopyObjectSimple } from '../../../utilities/deepCopyObject.js'\nimport { getSelectMode } from '../../../utilities/getSelectMode.js'\nimport { traverseFields } from './traverseFields.js'\n\ntype Args<T extends JsonObject> = {\n collection: null | SanitizedCollectionConfig\n context: RequestContext\n currentDepth?: number\n depth: number\n doc: T\n draft: boolean\n fallbackLocale: null | string\n findMany?: boolean\n flattenLocales?: boolean\n global: null | SanitizedGlobalConfig\n locale: string\n overrideAccess: boolean\n populate?: PopulateType\n req: PayloadRequest\n select?: SelectType\n showHiddenFields: boolean\n}\n\n/**\n * This function is responsible for the following actions, in order:\n * - Remove hidden fields from response\n * - Flatten locales into requested locale. If the input doc contains all locales, the output doc after this function will only contain the requested locale.\n * - Sanitize outgoing data (point field, etc.)\n * - Execute field hooks\n * - Execute read access control\n * - Populate relationships\n */\n\nexport async function afterRead<T extends JsonObject>(args: Args<T>): Promise<T> {\n const {\n collection,\n context,\n currentDepth: incomingCurrentDepth,\n depth: incomingDepth,\n doc: incomingDoc,\n draft,\n fallbackLocale,\n findMany,\n flattenLocales = true,\n global,\n locale,\n overrideAccess,\n populate,\n req,\n select,\n showHiddenFields,\n } = args\n\n const doc = deepCopyObjectSimple(incomingDoc)\n const fieldPromises = []\n const populationPromises = []\n\n let depth =\n incomingDepth || incomingDepth === 0\n ? parseInt(String(incomingDepth), 10)\n : req.payload.config.defaultDepth\n if (depth > req.payload.config.maxDepth) {\n depth = req.payload.config.maxDepth\n }\n\n const currentDepth = incomingCurrentDepth || 1\n\n traverseFields({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: collection?.fields || global?.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n path: [],\n populate,\n populationPromises,\n req,\n schemaPath: [],\n select,\n selectMode: select ? getSelectMode(select) : undefined,\n showHiddenFields,\n siblingDoc: doc,\n })\n\n await Promise.all(fieldPromises)\n await Promise.all(populationPromises)\n\n return doc\n}\n"],"names":["deepCopyObjectSimple","getSelectMode","traverseFields","afterRead","args","collection","context","currentDepth","incomingCurrentDepth","depth","incomingDepth","doc","incomingDoc","draft","fallbackLocale","findMany","flattenLocales","global","locale","overrideAccess","populate","req","select","showHiddenFields","fieldPromises","populationPromises","parseInt","String","payload","config","defaultDepth","maxDepth","fields","path","schemaPath","selectMode","undefined","siblingDoc","Promise","all"],"mappings":"AAKA,SAASA,oBAAoB,QAAQ,uCAAsC;AAC3E,SAASC,aAAa,QAAQ,sCAAqC;AACnE,SAASC,cAAc,QAAQ,sBAAqB;AAqBpD;;;;;;;;CAQC,GAED,OAAO,eAAeC,UAAgCC,IAAa;IACjE,MAAM,EACJC,UAAU,EACVC,OAAO,EACPC,cAAcC,oBAAoB,EAClCC,OAAOC,aAAa,EACpBC,KAAKC,WAAW,EAChBC,KAAK,EACLC,cAAc,EACdC,QAAQ,EACRC,iBAAiB,IAAI,EACrBC,MAAM,EACNC,MAAM,EACNC,cAAc,EACdC,QAAQ,EACRC,GAAG,EACHC,MAAM,EACNC,gBAAgB,EACjB,GAAGnB;IAEJ,MAAMO,MAAMX,qBAAqBY;IACjC,MAAMY,gBAAgB,EAAE;IACxB,MAAMC,qBAAqB,EAAE;IAE7B,IAAIhB,QACFC,iBAAiBA,kBAAkB,IAC/BgB,SAASC,OAAOjB,gBAAgB,MAChCW,IAAIO,OAAO,CAACC,MAAM,CAACC,YAAY;IACrC,IAAIrB,QAAQY,IAAIO,OAAO,CAACC,MAAM,CAACE,QAAQ,EAAE;QACvCtB,QAAQY,IAAIO,OAAO,CAACC,MAAM,CAACE,QAAQ;IACrC;IAEA,MAAMxB,eAAeC,wBAAwB;IAE7CN,eAAe;QACbG;QACAC;QACAC;QACAE;QACAE;QACAE;QACAC;QACAU;QACAQ,QAAQ3B,YAAY2B,UAAUf,QAAQe;QACtCjB;QACAC;QACAC;QACAC;QACAC;QACAc,MAAM,EAAE;QACRb;QACAK;QACAJ;QACAa,YAAY,EAAE;QACdZ;QACAa,YAAYb,SAASrB,cAAcqB,UAAUc;QAC7Cb;QACAc,YAAY1B;IACd;IAEA,MAAM2B,QAAQC,GAAG,CAACf;IAClB,MAAMc,QAAQC,GAAG,CAACd;IAElB,OAAOd;AACT"}
@@ -1,7 +1,7 @@
1
1
  import type { SanitizedCollectionConfig } from '../../../collections/config/types.js';
2
2
  import type { SanitizedGlobalConfig } from '../../../globals/config/types.js';
3
3
  import type { RequestContext } from '../../../index.js';
4
- import type { JsonObject, PayloadRequest, SelectMode, SelectType } from '../../../types/index.js';
4
+ import type { JsonObject, PayloadRequest, PopulateType, SelectMode, SelectType } from '../../../types/index.js';
5
5
  import type { Field, TabAsField } from '../../config/types.js';
6
6
  type Args = {
7
7
  collection: null | SanitizedCollectionConfig;
@@ -29,6 +29,7 @@ type Args = {
29
29
  * The parent's schemaPath (path without indexes).
30
30
  */
31
31
  parentSchemaPath: string[];
32
+ populate?: PopulateType;
32
33
  populationPromises: Promise<void>[];
33
34
  req: PayloadRequest;
34
35
  select?: SelectType;
@@ -38,6 +39,6 @@ type Args = {
38
39
  triggerAccessControl?: boolean;
39
40
  triggerHooks?: boolean;
40
41
  };
41
- export declare const promise: ({ collection, context, currentDepth, depth, doc, draft, fallbackLocale, field, fieldPromises, findMany, flattenLocales, global, locale, overrideAccess, parentPath, parentSchemaPath, populationPromises, req, select, selectMode, showHiddenFields, siblingDoc, triggerAccessControl, triggerHooks, }: Args) => Promise<void>;
42
+ export declare const promise: ({ collection, context, currentDepth, depth, doc, draft, fallbackLocale, field, fieldPromises, findMany, flattenLocales, global, locale, overrideAccess, parentPath, parentSchemaPath, populate, populationPromises, req, select, selectMode, showHiddenFields, siblingDoc, triggerAccessControl, triggerHooks, }: Args) => Promise<void>;
42
43
  export {};
43
44
  //# sourceMappingURL=promise.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"promise.d.ts","sourceRoot":"","sources":["../../../../src/fields/hooks/afterRead/promise.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAA;AACrF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAA;AAC7E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AACjG,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAS9D,KAAK,IAAI,GAAG;IACV,UAAU,EAAE,IAAI,GAAG,yBAAyB,CAAA;IAC5C,OAAO,EAAE,cAAc,CAAA;IACvB,YAAY,EAAE,MAAM,CAAA;IACpB,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,UAAU,CAAA;IACf,KAAK,EAAE,OAAO,CAAA;IACd,cAAc,EAAE,IAAI,GAAG,MAAM,CAAA;IAC7B,KAAK,EAAE,KAAK,GAAG,UAAU,CAAA;IACzB;;OAEG;IACH,aAAa,EAAE,OAAO,CAAC,IAAI,CAAC,EAAE,CAAA;IAC9B,QAAQ,EAAE,OAAO,CAAA;IACjB,cAAc,EAAE,OAAO,CAAA;IACvB,MAAM,EAAE,IAAI,GAAG,qBAAqB,CAAA;IACpC,MAAM,EAAE,IAAI,GAAG,M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AAM,CAAA;IAC7B,KAAK,EAAE,KAAK,GAAG,UAAU,CAAA;IACzB;;OAEG;IACH,aAAa,EAAE,OAAO,CAAC,IAAI,CAAC,EAAE,CAAA;IAC9B,QAAQ,EAAE,OAAO,CAAA;IACjB,cAAc,EAAE,OAAO,CAAA;IACvB,MAAM,EAAE,IAAI,GAAG,qBAAqB,CAAA;IACpC,MAAM,EAAE,IAAI,GAAG,MAAM,CAAA;IACrB,cAAc,EAAE,OAAO,CAAA;IACvB;;OAEG;IACH,UAAU,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAA;IAC/B;;OAEG;IACH,gBAAgB,EAAE,MAAM,EAAE,CAAA;IAC1B,QAAQ,CAAC,EAAE,YAAY,CAAA;IACvB,kBAAkB,EAAE,OAAO,CAAC,IAAI,CAAC,EAAE,CAAA;IACnC,GAAG,EAAE,cAAc,CAAA;IACnB,MAAM,CAAC,EAAE,UAAU,CAAA;IACnB,UAAU,CAAC,EAAE,UAAU,CAAA;IACvB,gBAAgB,EAAE,OAAO,CAAA;IACzB,UAAU,EAAE,UAAU,CAAA;IACtB,oBAAoB,CAAC,EAAE,OAAO,CAAA;IAC9B,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB,CAAA;AAUD,eAAO,MAAM,OAAO,qTA0BjB,IAAI,KAAG,OAAO,CAAC,IAAI,CAkrBrB,CAAA"}
@@ -11,7 +11,7 @@ import { traverseFields } from './traverseFields.js';
11
11
  // - Execute field hooks
12
12
  // - Execute read access control
13
13
  // - Populate relationships
14
- export const promise = async ({ collection, context, currentDepth, depth, doc, draft, fallbackLocale, field, fieldPromises, findMany, flattenLocales, global, locale, overrideAccess, parentPath, parentSchemaPath, populationPromises, req, select, selectMode, showHiddenFields, siblingDoc, triggerAccessControl = true, triggerHooks = true })=>{
14
+ export const promise = async ({ collection, context, currentDepth, depth, doc, draft, fallbackLocale, field, fieldPromises, findMany, flattenLocales, global, locale, overrideAccess, parentPath, parentSchemaPath, populate, populationPromises, req, select, selectMode, showHiddenFields, siblingDoc, triggerAccessControl = true, triggerHooks = true })=>{
15
15
  const { path: fieldPath, schemaPath: fieldSchemaPath } = getFieldPaths({
16
16
  field,
17
17
  parentPath,
@@ -205,6 +205,7 @@ export const promise = async ({ collection, context, currentDepth, depth, doc, d
205
205
  field,
206
206
  locale,
207
207
  overrideAccess,
208
+ populate,
208
209
  req,
209
210
  showHiddenFields,
210
211
  siblingDoc
@@ -235,6 +236,7 @@ export const promise = async ({ collection, context, currentDepth, depth, doc, d
235
236
  locale,
236
237
  overrideAccess,
237
238
  path: fieldPath,
239
+ populate,
238
240
  populationPromises,
239
241
  req,
240
242
  schemaPath: fieldSchemaPath,
@@ -275,6 +277,7 @@ export const promise = async ({ collection, context, currentDepth, depth, doc, d
275
277
  ...fieldPath,
276
278
  i
277
279
  ],
280
+ populate,
278
281
  populationPromises,
279
282
  req,
280
283
  schemaPath: fieldSchemaPath,
@@ -309,6 +312,7 @@ export const promise = async ({ collection, context, currentDepth, depth, doc, d
309
312
  ...fieldPath,
310
313
  i
311
314
  ],
315
+ populate,
312
316
  populationPromises,
313
317
  req,
314
318
  schemaPath: fieldSchemaPath,
@@ -372,6 +376,7 @@ export const promise = async ({ collection, context, currentDepth, depth, doc, d
372
376
  ...fieldPath,
373
377
  i
374
378
  ],
379
+ populate,
375
380
  populationPromises,
376
381
  req,
377
382
  schemaPath: fieldSchemaPath,
@@ -409,6 +414,7 @@ export const promise = async ({ collection, context, currentDepth, depth, doc, d
409
414
  ...fieldPath,
410
415
  i
411
416
  ],
417
+ populate,
412
418
  populationPromises,
413
419
  req,
414
420
  schemaPath: fieldSchemaPath,
@@ -445,6 +451,7 @@ export const promise = async ({ collection, context, currentDepth, depth, doc, d
445
451
  locale,
446
452
  overrideAccess,
447
453
  path: fieldPath,
454
+ populate,
448
455
  populationPromises,
449
456
  req,
450
457
  schemaPath: fieldSchemaPath,
@@ -488,6 +495,7 @@ export const promise = async ({ collection, context, currentDepth, depth, doc, d
488
495
  locale,
489
496
  overrideAccess,
490
497
  path: fieldPath,
498
+ populate,
491
499
  populationPromises,
492
500
  req,
493
501
  schemaPath: fieldSchemaPath,
@@ -521,6 +529,7 @@ export const promise = async ({ collection, context, currentDepth, depth, doc, d
521
529
  locale,
522
530
  overrideAccess,
523
531
  path: fieldPath,
532
+ populate,
524
533
  populationPromises,
525
534
  req,
526
535
  schemaPath: fieldSchemaPath,
@@ -567,6 +576,7 @@ export const promise = async ({ collection, context, currentDepth, depth, doc, d
567
576
  originalDoc: doc,
568
577
  overrideAccess,
569
578
  path: fieldPath,
579
+ populate,
570
580
  populationPromises,
571
581
  req,
572
582
  schemaPath: fieldSchemaPath,
@@ -600,6 +610,7 @@ export const promise = async ({ collection, context, currentDepth, depth, doc, d
600
610
  originalDoc: doc,
601
611
  overrideAccess,
602
612
  path: fieldPath,
613
+ populate,
603
614
  populationPromises,
604
615
  req,
605
616
  schemaPath: fieldSchemaPath,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/fields/hooks/afterRead/promise.ts"],"sourcesContent":["import type { RichTextAdapter } from '../../../admin/RichText.js'\nimport type { SanitizedCollectionConfig } from '../../../collections/config/types.js'\nimport type { SanitizedGlobalConfig } from '../../../globals/config/types.js'\nimport type { RequestContext } from '../../../index.js'\nimport type { JsonObject, PayloadRequest, SelectMode, SelectType } from '../../../types/index.js'\nimport type { Field, TabAsField } from '../../config/types.js'\n\nimport { MissingEditorProp } from '../../../errors/index.js'\nimport { fieldAffectsData, tabHasName } from '../../config/types.js'\nimport { getDefaultValue } from '../../getDefaultValue.js'\nimport { getFieldPaths } from '../../getFieldPaths.js'\nimport { relationshipPopulationPromise } from './relationshipPopulationPromise.js'\nimport { traverseFields } from './traverseFields.js'\n\ntype Args = {\n collection: null | SanitizedCollectionConfig\n context: RequestContext\n currentDepth: number\n depth: number\n doc: JsonObject\n draft: boolean\n fallbackLocale: null | string\n field: Field | TabAsField\n /**\n * fieldPromises are used for things like field hooks. They should be awaited before awaiting populationPromises\n */\n fieldPromises: Promise<void>[]\n findMany: boolean\n flattenLocales: boolean\n global: null | SanitizedGlobalConfig\n locale: null | string\n overrideAccess: boolean\n /**\n * The parent's path.\n */\n parentPath: (number | string)[]\n /**\n * The parent's schemaPath (path without indexes).\n */\n parentSchemaPath: string[]\n populationPromises: Promise<void>[]\n req: PayloadRequest\n select?: SelectType\n selectMode?: SelectMode\n showHiddenFields: boolean\n siblingDoc: JsonObject\n triggerAccessControl?: boolean\n triggerHooks?: boolean\n}\n\n// This function is responsible for the following actions, in order:\n// - Remove hidden fields from response\n// - Flatten locales into requested locale\n// - Sanitize outgoing data (point field, etc.)\n// - Execute field hooks\n// - Execute read access control\n// - Populate relationships\n\nexport const promise = async ({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n field,\n fieldPromises,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n parentPath,\n parentSchemaPath,\n populationPromises,\n req,\n select,\n selectMode,\n showHiddenFields,\n siblingDoc,\n triggerAccessControl = true,\n triggerHooks = true,\n}: Args): Promise<void> => {\n const { path: fieldPath, schemaPath: fieldSchemaPath } = getFieldPaths({\n field,\n parentPath,\n parentSchemaPath,\n })\n\n if (\n fieldAffectsData(field) &&\n field.hidden &&\n typeof siblingDoc[field.name] !== 'undefined' &&\n !showHiddenFields\n ) {\n delete siblingDoc[field.name]\n }\n\n if (fieldAffectsData(field) && select && selectMode) {\n if (selectMode === 'include') {\n if (!select[field.name]) {\n delete siblingDoc[field.name]\n return\n }\n }\n\n if (selectMode === 'exclude') {\n if (select[field.name] === false) {\n delete siblingDoc[field.name]\n return\n }\n }\n }\n\n const shouldHoistLocalizedValue =\n flattenLocales &&\n fieldAffectsData(field) &&\n typeof siblingDoc[field.name] === 'object' &&\n siblingDoc[field.name] !== null &&\n field.localized &&\n locale !== 'all' &&\n req.payload.config.localization\n\n if (shouldHoistLocalizedValue) {\n // replace actual value with localized value before sanitizing\n // { [locale]: fields } -> fields\n const value = siblingDoc[field.name][locale]\n\n let hoistedValue = value\n\n if (fallbackLocale && fallbackLocale !== locale) {\n const fallbackValue = siblingDoc[field.name][fallbackLocale]\n const isNullOrUndefined = typeof value === 'undefined' || value === null\n\n if (fallbackValue) {\n switch (field.type) {\n case 'text':\n case 'textarea': {\n if (value === '' || isNullOrUndefined) {\n hoistedValue = fallbackValue\n }\n break\n }\n\n default: {\n if (isNullOrUndefined) {\n hoistedValue = fallbackValue\n }\n break\n }\n }\n }\n }\n\n siblingDoc[field.name] = hoistedValue\n }\n\n // Sanitize outgoing field value\n switch (field.type) {\n case 'group': {\n // Fill groups with empty objects so fields with hooks within groups can populate\n // themselves virtually as necessary\n if (typeof siblingDoc[field.name] === 'undefined') {\n siblingDoc[field.name] = {}\n }\n\n break\n }\n case 'tabs': {\n field.tabs.forEach((tab) => {\n if (\n tabHasName(tab) &&\n (typeof siblingDoc[tab.name] === 'undefined' || siblingDoc[tab.name] === null)\n ) {\n siblingDoc[tab.name] = {}\n }\n })\n\n break\n }\n\n case 'richText': {\n if (!field?.editor) {\n throw new MissingEditorProp(field) // while we allow disabling editor functionality, you should not have any richText fields defined if you do not have an editor\n }\n if (typeof field?.editor === 'function') {\n throw new Error('Attempted to access unsanitized rich text editor.')\n }\n\n // Rich Text fields should use afterRead hooks to do population. The previous editor.populationPromises have been renamed to editor.graphQLPopulationPromises\n break\n }\n\n case 'point': {\n const pointDoc = siblingDoc[field.name] as Record<string, unknown>\n if (Array.isArray(pointDoc?.coordinates) && pointDoc.coordinates.length === 2) {\n siblingDoc[field.name] = pointDoc.coordinates\n } else {\n siblingDoc[field.name] = undefined\n }\n\n break\n }\n\n default: {\n break\n }\n }\n\n if (fieldAffectsData(field)) {\n // Execute hooks\n if (triggerHooks && field.hooks?.afterRead) {\n await field.hooks.afterRead.reduce(async (priorHook, currentHook) => {\n await priorHook\n\n const shouldRunHookOnAllLocales =\n field.localized &&\n (locale === 'all' || !flattenLocales) &&\n typeof siblingDoc[field.name] === 'object'\n\n if (shouldRunHookOnAllLocales) {\n const hookPromises = Object.entries(siblingDoc[field.name]).map(([locale, value]) =>\n (async () => {\n const hookedValue = await currentHook({\n collection,\n context,\n currentDepth,\n data: doc,\n depth,\n draft,\n field,\n findMany,\n global,\n operation: 'read',\n originalDoc: doc,\n overrideAccess,\n path: fieldPath,\n req,\n schemaPath: fieldSchemaPath,\n showHiddenFields,\n siblingData: siblingDoc,\n value,\n })\n\n if (hookedValue !== undefined) {\n siblingDoc[field.name][locale] = hookedValue\n }\n })(),\n )\n\n await Promise.all(hookPromises)\n } else {\n const hookedValue = await currentHook({\n collection,\n context,\n currentDepth,\n data: doc,\n depth,\n draft,\n field,\n findMany,\n global,\n operation: 'read',\n originalDoc: doc,\n overrideAccess,\n path: fieldPath,\n req,\n schemaPath: fieldSchemaPath,\n showHiddenFields,\n siblingData: siblingDoc,\n value: siblingDoc[field.name],\n })\n\n if (hookedValue !== undefined) {\n siblingDoc[field.name] = hookedValue\n }\n }\n }, Promise.resolve())\n }\n\n // Execute access control\n let allowDefaultValue = true\n if (triggerAccessControl && field.access && field.access.read) {\n const result = overrideAccess\n ? true\n : await field.access.read({\n id: doc.id as number | string,\n data: doc,\n doc,\n req,\n siblingData: siblingDoc,\n })\n\n if (!result) {\n allowDefaultValue = false\n delete siblingDoc[field.name]\n }\n }\n\n // Set defaultValue on the field for globals being returned without being first created\n // or collection documents created prior to having a default\n if (\n allowDefaultValue &&\n typeof siblingDoc[field.name] === 'undefined' &&\n typeof field.defaultValue !== 'undefined'\n ) {\n siblingDoc[field.name] = await getDefaultValue({\n defaultValue: field.defaultValue,\n locale,\n user: req.user,\n value: siblingDoc[field.name],\n })\n }\n\n if (field.type === 'relationship' || field.type === 'upload' || field.type === 'join') {\n populationPromises.push(\n relationshipPopulationPromise({\n currentDepth,\n depth,\n draft,\n fallbackLocale,\n field,\n locale,\n overrideAccess,\n req,\n showHiddenFields,\n siblingDoc,\n }),\n )\n }\n }\n\n switch (field.type) {\n case 'group': {\n let groupDoc = siblingDoc[field.name] as JsonObject\n if (typeof siblingDoc[field.name] !== 'object') {\n groupDoc = {}\n }\n\n const groupSelect = select?.[field.name]\n\n traverseFields({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: field.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n path: fieldPath,\n populationPromises,\n req,\n schemaPath: fieldSchemaPath,\n select: typeof groupSelect === 'object' ? groupSelect : undefined,\n selectMode,\n showHiddenFields,\n siblingDoc: groupDoc,\n triggerAccessControl,\n triggerHooks,\n })\n\n break\n }\n\n case 'array': {\n const rows = siblingDoc[field.name] as JsonObject\n\n const arraySelect = select?.[field.name]\n\n if (selectMode === 'include' && typeof arraySelect === 'object') {\n arraySelect.id = true\n }\n\n if (Array.isArray(rows)) {\n rows.forEach((row, i) => {\n traverseFields({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: field.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n path: [...fieldPath, i],\n populationPromises,\n req,\n schemaPath: fieldSchemaPath,\n select: typeof arraySelect === 'object' ? arraySelect : undefined,\n selectMode,\n showHiddenFields,\n siblingDoc: row || {},\n triggerAccessControl,\n triggerHooks,\n })\n })\n } else if (!shouldHoistLocalizedValue && typeof rows === 'object' && rows !== null) {\n Object.values(rows).forEach((localeRows) => {\n if (Array.isArray(localeRows)) {\n localeRows.forEach((row, i) => {\n traverseFields({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: field.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n path: [...fieldPath, i],\n populationPromises,\n req,\n schemaPath: fieldSchemaPath,\n showHiddenFields,\n siblingDoc: (row as JsonObject) || {},\n triggerAccessControl,\n triggerHooks,\n })\n })\n }\n })\n } else {\n siblingDoc[field.name] = []\n }\n break\n }\n\n case 'blocks': {\n const rows = siblingDoc[field.name]\n\n const blocksSelect = select?.[field.name]\n\n if (Array.isArray(rows)) {\n rows.forEach((row, i) => {\n const block = field.blocks.find(\n (blockType) => blockType.slug === (row as JsonObject).blockType,\n )\n\n let blockSelectMode = selectMode\n\n if (typeof blocksSelect === 'object') {\n // sanitize blocks: {cta: false} to blocks: {cta: {id: true, blockType: true}}\n if (selectMode === 'exclude' && blocksSelect[block.slug] === false) {\n blockSelectMode = 'include'\n blocksSelect[block.slug] = {\n id: true,\n blockType: true,\n }\n } else if (selectMode === 'include') {\n if (!blocksSelect[block.slug]) {\n blocksSelect[block.slug] = {}\n }\n\n if (typeof blocksSelect[block.slug] === 'object') {\n blocksSelect[block.slug]['id'] = true\n blocksSelect[block.slug]['blockType'] = true\n }\n }\n }\n\n const blockSelect = blocksSelect?.[block.slug]\n\n if (block) {\n traverseFields({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: block.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n path: [...fieldPath, i],\n populationPromises,\n req,\n schemaPath: fieldSchemaPath,\n select: typeof blockSelect === 'object' ? blockSelect : undefined,\n selectMode: blockSelectMode,\n showHiddenFields,\n siblingDoc: (row as JsonObject) || {},\n triggerAccessControl,\n triggerHooks,\n })\n }\n })\n } else if (!shouldHoistLocalizedValue && typeof rows === 'object' && rows !== null) {\n Object.values(rows).forEach((localeRows) => {\n if (Array.isArray(localeRows)) {\n localeRows.forEach((row, i) => {\n const block = field.blocks.find(\n (blockType) => blockType.slug === (row as JsonObject).blockType,\n )\n\n if (block) {\n traverseFields({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: block.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n path: [...fieldPath, i],\n populationPromises,\n req,\n schemaPath: fieldSchemaPath,\n showHiddenFields,\n siblingDoc: (row as JsonObject) || {},\n triggerAccessControl,\n triggerHooks,\n })\n }\n })\n }\n })\n } else {\n siblingDoc[field.name] = []\n }\n\n break\n }\n\n case 'row':\n case 'collapsible': {\n traverseFields({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: field.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n path: fieldPath,\n populationPromises,\n req,\n schemaPath: fieldSchemaPath,\n select,\n selectMode,\n showHiddenFields,\n siblingDoc,\n triggerAccessControl,\n triggerHooks,\n })\n\n break\n }\n\n case 'tab': {\n let tabDoc = siblingDoc\n let tabSelect: SelectType | undefined\n if (tabHasName(field)) {\n tabDoc = siblingDoc[field.name] as JsonObject\n if (typeof siblingDoc[field.name] !== 'object') {\n tabDoc = {}\n }\n\n if (typeof select?.[field.name] === 'object') {\n tabSelect = select?.[field.name] as SelectType\n }\n } else {\n tabSelect = select\n }\n\n traverseFields({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: field.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n path: fieldPath,\n populationPromises,\n req,\n schemaPath: fieldSchemaPath,\n select: tabSelect,\n selectMode,\n showHiddenFields,\n siblingDoc: tabDoc,\n triggerAccessControl,\n triggerHooks,\n })\n\n break\n }\n\n case 'tabs': {\n traverseFields({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: field.tabs.map((tab) => ({ ...tab, type: 'tab' })),\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n path: fieldPath,\n populationPromises,\n req,\n schemaPath: fieldSchemaPath,\n select,\n selectMode,\n showHiddenFields,\n siblingDoc,\n triggerAccessControl,\n triggerHooks,\n })\n break\n }\n\n case 'richText': {\n if (!field?.editor) {\n throw new MissingEditorProp(field) // while we allow disabling editor functionality, you should not have any richText fields defined if you do not have an editor\n }\n if (typeof field?.editor === 'function') {\n throw new Error('Attempted to access unsanitized rich text editor.')\n }\n\n const editor: RichTextAdapter = field?.editor\n\n if (editor?.hooks?.afterRead?.length) {\n await editor.hooks.afterRead.reduce(async (priorHook, currentHook) => {\n await priorHook\n\n const shouldRunHookOnAllLocales =\n field.localized &&\n (locale === 'all' || !flattenLocales) &&\n typeof siblingDoc[field.name] === 'object'\n\n if (shouldRunHookOnAllLocales) {\n const hookPromises = Object.entries(siblingDoc[field.name]).map(([locale, value]) =>\n (async () => {\n const hookedValue = await currentHook({\n collection,\n context,\n currentDepth,\n data: doc,\n depth,\n draft,\n fallbackLocale,\n field,\n fieldPromises,\n findMany,\n flattenLocales,\n global,\n locale,\n operation: 'read',\n originalDoc: doc,\n overrideAccess,\n path: fieldPath,\n populationPromises,\n req,\n schemaPath: fieldSchemaPath,\n showHiddenFields,\n siblingData: siblingDoc,\n triggerAccessControl,\n triggerHooks,\n value,\n })\n\n if (hookedValue !== undefined) {\n siblingDoc[field.name][locale] = hookedValue\n }\n })(),\n )\n\n await Promise.all(hookPromises)\n } else {\n const hookedValue = await currentHook({\n collection,\n context,\n currentDepth,\n data: doc,\n depth,\n draft,\n fallbackLocale,\n field,\n fieldPromises,\n findMany,\n flattenLocales,\n global,\n locale,\n operation: 'read',\n originalDoc: doc,\n overrideAccess,\n path: fieldPath,\n populationPromises,\n req,\n schemaPath: fieldSchemaPath,\n showHiddenFields,\n siblingData: siblingDoc,\n triggerAccessControl,\n triggerHooks,\n value: siblingDoc[field.name],\n })\n\n if (hookedValue !== undefined) {\n siblingDoc[field.name] = hookedValue\n }\n }\n }, Promise.resolve())\n }\n break\n }\n\n default: {\n break\n }\n }\n}\n"],"names":["MissingEditorProp","fieldAffectsData","tabHasName","getDefaultValue","getFieldPaths","relationshipPopulationPromise","traverseFields","promise","collection","context","currentDepth","depth","doc","draft","fallbackLocale","field","fieldPromises","findMany","flattenLocales","global","locale","overrideAccess","parentPath","parentSchemaPath","populationPromises","req","select","selectMode","showHiddenFields","siblingDoc","triggerAccessControl","triggerHooks","path","fieldPath","schemaPath","fieldSchemaPath","hidden","name","shouldHoistLocalizedValue","localized","payload","config","localization","value","hoistedValue","fallbackValue","isNullOrUndefined","type","tabs","forEach","tab","editor","Error","pointDoc","Array","isArray","coordinates","length","undefined","hooks","afterRead","reduce","priorHook","currentHook","shouldRunHookOnAllLocales","hookPromises","Object","entries","map","hookedValue","data","operation","originalDoc","siblingData","Promise","all","resolve","allowDefaultValue","access","read","result","id","defaultValue","user","push","groupDoc","groupSelect","fields","rows","arraySelect","row","i","values","localeRows","blocksSelect","block","blocks","find","blockType","slug","blockSelectMode","blockSelect","tabDoc","tabSelect"],"mappings":"AAOA,SAASA,iBAAiB,QAAQ,2BAA0B;AAC5D,SAASC,gBAAgB,EAAEC,UAAU,QAAQ,wBAAuB;AACpE,SAASC,eAAe,QAAQ,2BAA0B;AAC1D,SAASC,aAAa,QAAQ,yBAAwB;AACtD,SAASC,6BAA6B,QAAQ,qCAAoC;AAClF,SAASC,cAAc,QAAQ,sBAAqB;AAsCpD,oEAAoE;AACpE,uCAAuC;AACvC,0CAA0C;AAC1C,+CAA+C;AAC/C,wBAAwB;AACxB,gCAAgC;AAChC,2BAA2B;AAE3B,OAAO,MAAMC,UAAU,OAAO,EAC5BC,UAAU,EACVC,OAAO,EACPC,YAAY,EACZC,KAAK,EACLC,GAAG,EACHC,KAAK,EACLC,cAAc,EACdC,KAAK,EACLC,aAAa,EACbC,QAAQ,EACRC,cAAc,EACdC,MAAM,EACNC,MAAM,EACNC,cAAc,EACdC,UAAU,EACVC,gBAAgB,EAChBC,kBAAkB,EAClBC,GAAG,EACHC,MAAM,EACNC,UAAU,EACVC,gBAAgB,EAChBC,UAAU,EACVC,uBAAuB,IAAI,EAC3BC,eAAe,IAAI,EACd;IACL,MAAM,EAAEC,MAAMC,SAAS,EAAEC,YAAYC,eAAe,EAAE,GAAG/B,cAAc;QACrEW;QACAO;QACAC;IACF;IAEA,IACEtB,iBAAiBc,UACjBA,MAAMqB,MAAM,IACZ,OAAOP,UAAU,CA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;gCAC7B7B,UAAU,CAACd,MAAMsB,IAAI,CAAC,GAAGgC;4BAC3B;wBACF;oBACF,GAAGK,QAAQE,OAAO;gBACpB;gBACA;YACF;QAEA;YAAS;gBACP;YACF;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../../src/fields/hooks/afterRead/promise.ts"],"sourcesContent":["import type { RichTextAdapter } from '../../../admin/RichText.js'\nimport type { SanitizedCollectionConfig } from '../../../collections/config/types.js'\nimport type { SanitizedGlobalConfig } from '../../../globals/config/types.js'\nimport type { RequestContext } from '../../../index.js'\nimport type {\n JsonObject,\n PayloadRequest,\n PopulateType,\n SelectMode,\n SelectType,\n} from '../../../types/index.js'\nimport type { Field, TabAsField } from '../../config/types.js'\n\nimport { MissingEditorProp } from '../../../errors/index.js'\nimport { fieldAffectsData, tabHasName } from '../../config/types.js'\nimport { getDefaultValue } from '../../getDefaultValue.js'\nimport { getFieldPaths } from '../../getFieldPaths.js'\nimport { relationshipPopulationPromise } from './relationshipPopulationPromise.js'\nimport { traverseFields } from './traverseFields.js'\n\ntype Args = {\n collection: null | SanitizedCollectionConfig\n context: RequestContext\n currentDepth: number\n depth: number\n doc: JsonObject\n draft: boolean\n fallbackLocale: null | string\n field: Field | TabAsField\n /**\n * fieldPromises are used for things like field hooks. They should be awaited before awaiting populationPromises\n */\n fieldPromises: Promise<void>[]\n findMany: boolean\n flattenLocales: boolean\n global: null | SanitizedGlobalConfig\n locale: null | string\n overrideAccess: boolean\n /**\n * The parent's path.\n */\n parentPath: (number | string)[]\n /**\n * The parent's schemaPath (path without indexes).\n */\n parentSchemaPath: string[]\n populate?: PopulateType\n populationPromises: Promise<void>[]\n req: PayloadRequest\n select?: SelectType\n selectMode?: SelectMode\n showHiddenFields: boolean\n siblingDoc: JsonObject\n triggerAccessControl?: boolean\n triggerHooks?: boolean\n}\n\n// This function is responsible for the following actions, in order:\n// - Remove hidden fields from response\n// - Flatten locales into requested locale\n// - Sanitize outgoing data (point field, etc.)\n// - Execute field hooks\n// - Execute read access control\n// - Populate relationships\n\nexport const promise = async ({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n field,\n fieldPromises,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n parentPath,\n parentSchemaPath,\n populate,\n populationPromises,\n req,\n select,\n selectMode,\n showHiddenFields,\n siblingDoc,\n triggerAccessControl = true,\n triggerHooks = true,\n}: Args): Promise<void> => {\n const { path: fieldPath, schemaPath: fieldSchemaPath } = getFieldPaths({\n field,\n parentPath,\n parentSchemaPath,\n })\n\n if (\n fieldAffectsData(field) &&\n field.hidden &&\n typeof siblingDoc[field.name] !== 'undefined' &&\n !showHiddenFields\n ) {\n delete siblingDoc[field.name]\n }\n\n if (fieldAffectsData(field) && select && selectMode) {\n if (selectMode === 'include') {\n if (!select[field.name]) {\n delete siblingDoc[field.name]\n return\n }\n }\n\n if (selectMode === 'exclude') {\n if (select[field.name] === false) {\n delete siblingDoc[field.name]\n return\n }\n }\n }\n\n const shouldHoistLocalizedValue =\n flattenLocales &&\n fieldAffectsData(field) &&\n typeof siblingDoc[field.name] === 'object' &&\n siblingDoc[field.name] !== null &&\n field.localized &&\n locale !== 'all' &&\n req.payload.config.localization\n\n if (shouldHoistLocalizedValue) {\n // replace actual value with localized value before sanitizing\n // { [locale]: fields } -> fields\n const value = siblingDoc[field.name][locale]\n\n let hoistedValue = value\n\n if (fallbackLocale && fallbackLocale !== locale) {\n const fallbackValue = siblingDoc[field.name][fallbackLocale]\n const isNullOrUndefined = typeof value === 'undefined' || value === null\n\n if (fallbackValue) {\n switch (field.type) {\n case 'text':\n case 'textarea': {\n if (value === '' || isNullOrUndefined) {\n hoistedValue = fallbackValue\n }\n break\n }\n\n default: {\n if (isNullOrUndefined) {\n hoistedValue = fallbackValue\n }\n break\n }\n }\n }\n }\n\n siblingDoc[field.name] = hoistedValue\n }\n\n // Sanitize outgoing field value\n switch (field.type) {\n case 'group': {\n // Fill groups with empty objects so fields with hooks within groups can populate\n // themselves virtually as necessary\n if (typeof siblingDoc[field.name] === 'undefined') {\n siblingDoc[field.name] = {}\n }\n\n break\n }\n case 'tabs': {\n field.tabs.forEach((tab) => {\n if (\n tabHasName(tab) &&\n (typeof siblingDoc[tab.name] === 'undefined' || siblingDoc[tab.name] === null)\n ) {\n siblingDoc[tab.name] = {}\n }\n })\n\n break\n }\n\n case 'richText': {\n if (!field?.editor) {\n throw new MissingEditorProp(field) // while we allow disabling editor functionality, you should not have any richText fields defined if you do not have an editor\n }\n if (typeof field?.editor === 'function') {\n throw new Error('Attempted to access unsanitized rich text editor.')\n }\n\n // Rich Text fields should use afterRead hooks to do population. The previous editor.populationPromises have been renamed to editor.graphQLPopulationPromises\n break\n }\n\n case 'point': {\n const pointDoc = siblingDoc[field.name] as Record<string, unknown>\n if (Array.isArray(pointDoc?.coordinates) && pointDoc.coordinates.length === 2) {\n siblingDoc[field.name] = pointDoc.coordinates\n } else {\n siblingDoc[field.name] = undefined\n }\n\n break\n }\n\n default: {\n break\n }\n }\n\n if (fieldAffectsData(field)) {\n // Execute hooks\n if (triggerHooks && field.hooks?.afterRead) {\n await field.hooks.afterRead.reduce(async (priorHook, currentHook) => {\n await priorHook\n\n const shouldRunHookOnAllLocales =\n field.localized &&\n (locale === 'all' || !flattenLocales) &&\n typeof siblingDoc[field.name] === 'object'\n\n if (shouldRunHookOnAllLocales) {\n const hookPromises = Object.entries(siblingDoc[field.name]).map(([locale, value]) =>\n (async () => {\n const hookedValue = await currentHook({\n collection,\n context,\n currentDepth,\n data: doc,\n depth,\n draft,\n field,\n findMany,\n global,\n operation: 'read',\n originalDoc: doc,\n overrideAccess,\n path: fieldPath,\n req,\n schemaPath: fieldSchemaPath,\n showHiddenFields,\n siblingData: siblingDoc,\n value,\n })\n\n if (hookedValue !== undefined) {\n siblingDoc[field.name][locale] = hookedValue\n }\n })(),\n )\n\n await Promise.all(hookPromises)\n } else {\n const hookedValue = await currentHook({\n collection,\n context,\n currentDepth,\n data: doc,\n depth,\n draft,\n field,\n findMany,\n global,\n operation: 'read',\n originalDoc: doc,\n overrideAccess,\n path: fieldPath,\n req,\n schemaPath: fieldSchemaPath,\n showHiddenFields,\n siblingData: siblingDoc,\n value: siblingDoc[field.name],\n })\n\n if (hookedValue !== undefined) {\n siblingDoc[field.name] = hookedValue\n }\n }\n }, Promise.resolve())\n }\n\n // Execute access control\n let allowDefaultValue = true\n if (triggerAccessControl && field.access && field.access.read) {\n const result = overrideAccess\n ? true\n : await field.access.read({\n id: doc.id as number | string,\n data: doc,\n doc,\n req,\n siblingData: siblingDoc,\n })\n\n if (!result) {\n allowDefaultValue = false\n delete siblingDoc[field.name]\n }\n }\n\n // Set defaultValue on the field for globals being returned without being first created\n // or collection documents created prior to having a default\n if (\n allowDefaultValue &&\n typeof siblingDoc[field.name] === 'undefined' &&\n typeof field.defaultValue !== 'undefined'\n ) {\n siblingDoc[field.name] = await getDefaultValue({\n defaultValue: field.defaultValue,\n locale,\n user: req.user,\n value: siblingDoc[field.name],\n })\n }\n\n if (field.type === 'relationship' || field.type === 'upload' || field.type === 'join') {\n populationPromises.push(\n relationshipPopulationPromise({\n currentDepth,\n depth,\n draft,\n fallbackLocale,\n field,\n locale,\n overrideAccess,\n populate,\n req,\n showHiddenFields,\n siblingDoc,\n }),\n )\n }\n }\n\n switch (field.type) {\n case 'group': {\n let groupDoc = siblingDoc[field.name] as JsonObject\n if (typeof siblingDoc[field.name] !== 'object') {\n groupDoc = {}\n }\n\n const groupSelect = select?.[field.name]\n\n traverseFields({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: field.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n path: fieldPath,\n populate,\n populationPromises,\n req,\n schemaPath: fieldSchemaPath,\n select: typeof groupSelect === 'object' ? groupSelect : undefined,\n selectMode,\n showHiddenFields,\n siblingDoc: groupDoc,\n triggerAccessControl,\n triggerHooks,\n })\n\n break\n }\n\n case 'array': {\n const rows = siblingDoc[field.name] as JsonObject\n\n const arraySelect = select?.[field.name]\n\n if (selectMode === 'include' && typeof arraySelect === 'object') {\n arraySelect.id = true\n }\n\n if (Array.isArray(rows)) {\n rows.forEach((row, i) => {\n traverseFields({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: field.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n path: [...fieldPath, i],\n populate,\n populationPromises,\n req,\n schemaPath: fieldSchemaPath,\n select: typeof arraySelect === 'object' ? arraySelect : undefined,\n selectMode,\n showHiddenFields,\n siblingDoc: row || {},\n triggerAccessControl,\n triggerHooks,\n })\n })\n } else if (!shouldHoistLocalizedValue && typeof rows === 'object' && rows !== null) {\n Object.values(rows).forEach((localeRows) => {\n if (Array.isArray(localeRows)) {\n localeRows.forEach((row, i) => {\n traverseFields({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: field.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n path: [...fieldPath, i],\n populate,\n populationPromises,\n req,\n schemaPath: fieldSchemaPath,\n showHiddenFields,\n siblingDoc: (row as JsonObject) || {},\n triggerAccessControl,\n triggerHooks,\n })\n })\n }\n })\n } else {\n siblingDoc[field.name] = []\n }\n break\n }\n\n case 'blocks': {\n const rows = siblingDoc[field.name]\n\n const blocksSelect = select?.[field.name]\n\n if (Array.isArray(rows)) {\n rows.forEach((row, i) => {\n const block = field.blocks.find(\n (blockType) => blockType.slug === (row as JsonObject).blockType,\n )\n\n let blockSelectMode = selectMode\n\n if (typeof blocksSelect === 'object') {\n // sanitize blocks: {cta: false} to blocks: {cta: {id: true, blockType: true}}\n if (selectMode === 'exclude' && blocksSelect[block.slug] === false) {\n blockSelectMode = 'include'\n blocksSelect[block.slug] = {\n id: true,\n blockType: true,\n }\n } else if (selectMode === 'include') {\n if (!blocksSelect[block.slug]) {\n blocksSelect[block.slug] = {}\n }\n\n if (typeof blocksSelect[block.slug] === 'object') {\n blocksSelect[block.slug]['id'] = true\n blocksSelect[block.slug]['blockType'] = true\n }\n }\n }\n\n const blockSelect = blocksSelect?.[block.slug]\n\n if (block) {\n traverseFields({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: block.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n path: [...fieldPath, i],\n populate,\n populationPromises,\n req,\n schemaPath: fieldSchemaPath,\n select: typeof blockSelect === 'object' ? blockSelect : undefined,\n selectMode: blockSelectMode,\n showHiddenFields,\n siblingDoc: (row as JsonObject) || {},\n triggerAccessControl,\n triggerHooks,\n })\n }\n })\n } else if (!shouldHoistLocalizedValue && typeof rows === 'object' && rows !== null) {\n Object.values(rows).forEach((localeRows) => {\n if (Array.isArray(localeRows)) {\n localeRows.forEach((row, i) => {\n const block = field.blocks.find(\n (blockType) => blockType.slug === (row as JsonObject).blockType,\n )\n\n if (block) {\n traverseFields({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: block.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n path: [...fieldPath, i],\n populate,\n populationPromises,\n req,\n schemaPath: fieldSchemaPath,\n showHiddenFields,\n siblingDoc: (row as JsonObject) || {},\n triggerAccessControl,\n triggerHooks,\n })\n }\n })\n }\n })\n } else {\n siblingDoc[field.name] = []\n }\n\n break\n }\n\n case 'row':\n case 'collapsible': {\n traverseFields({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: field.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n path: fieldPath,\n populate,\n populationPromises,\n req,\n schemaPath: fieldSchemaPath,\n select,\n selectMode,\n showHiddenFields,\n siblingDoc,\n triggerAccessControl,\n triggerHooks,\n })\n\n break\n }\n\n case 'tab': {\n let tabDoc = siblingDoc\n let tabSelect: SelectType | undefined\n if (tabHasName(field)) {\n tabDoc = siblingDoc[field.name] as JsonObject\n if (typeof siblingDoc[field.name] !== 'object') {\n tabDoc = {}\n }\n\n if (typeof select?.[field.name] === 'object') {\n tabSelect = select?.[field.name] as SelectType\n }\n } else {\n tabSelect = select\n }\n\n traverseFields({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: field.fields,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n path: fieldPath,\n populate,\n populationPromises,\n req,\n schemaPath: fieldSchemaPath,\n select: tabSelect,\n selectMode,\n showHiddenFields,\n siblingDoc: tabDoc,\n triggerAccessControl,\n triggerHooks,\n })\n\n break\n }\n\n case 'tabs': {\n traverseFields({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n fields: field.tabs.map((tab) => ({ ...tab, type: 'tab' })),\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n path: fieldPath,\n populate,\n populationPromises,\n req,\n schemaPath: fieldSchemaPath,\n select,\n selectMode,\n showHiddenFields,\n siblingDoc,\n triggerAccessControl,\n triggerHooks,\n })\n break\n }\n\n case 'richText': {\n if (!field?.editor) {\n throw new MissingEditorProp(field) // while we allow disabling editor functionality, you should not have any richText fields defined if you do not have an editor\n }\n if (typeof field?.editor === 'function') {\n throw new Error('Attempted to access unsanitized rich text editor.')\n }\n\n const editor: RichTextAdapter = field?.editor\n\n if (editor?.hooks?.afterRead?.length) {\n await editor.hooks.afterRead.reduce(async (priorHook, currentHook) => {\n await priorHook\n\n const shouldRunHookOnAllLocales =\n field.localized &&\n (locale === 'all' || !flattenLocales) &&\n typeof siblingDoc[field.name] === 'object'\n\n if (shouldRunHookOnAllLocales) {\n const hookPromises = Object.entries(siblingDoc[field.name]).map(([locale, value]) =>\n (async () => {\n const hookedValue = await currentHook({\n collection,\n context,\n currentDepth,\n data: doc,\n depth,\n draft,\n fallbackLocale,\n field,\n fieldPromises,\n findMany,\n flattenLocales,\n global,\n locale,\n operation: 'read',\n originalDoc: doc,\n overrideAccess,\n path: fieldPath,\n populate,\n populationPromises,\n req,\n schemaPath: fieldSchemaPath,\n showHiddenFields,\n siblingData: siblingDoc,\n triggerAccessControl,\n triggerHooks,\n value,\n })\n\n if (hookedValue !== undefined) {\n siblingDoc[field.name][locale] = hookedValue\n }\n })(),\n )\n\n await Promise.all(hookPromises)\n } else {\n const hookedValue = await currentHook({\n collection,\n context,\n currentDepth,\n data: doc,\n depth,\n draft,\n fallbackLocale,\n field,\n fieldPromises,\n findMany,\n flattenLocales,\n global,\n locale,\n operation: 'read',\n originalDoc: doc,\n overrideAccess,\n path: fieldPath,\n populate,\n populationPromises,\n req,\n schemaPath: fieldSchemaPath,\n showHiddenFields,\n siblingData: siblingDoc,\n triggerAccessControl,\n triggerHooks,\n value: siblingDoc[field.name],\n })\n\n if (hookedValue !== undefined) {\n siblingDoc[field.name] = hookedValue\n }\n }\n }, Promise.resolve())\n }\n break\n }\n\n default: {\n break\n }\n }\n}\n"],"names":["MissingEditorProp","fieldAffectsData","tabHasName","getDefaultValue","getFieldPaths","relationshipPopulationPromise","traverseFields","promise","collection","context","currentDepth","depth","doc","draft","fallbackLocale","field","fieldPromises","findMany","flattenLocales","global","locale","overrideAccess","parentPath","parentSchemaPath","populate","populationPromises","req","select","selectMode","showHiddenFields","siblingDoc","triggerAccessControl","triggerHooks","path","fieldPath","schemaPath","fieldSchemaPath","hidden","name","shouldHoistLocalizedValue","localized","payload","config","localization","value","hoistedValue","fallbackValue","isNullOrUndefined","type","tabs","forEach","tab","editor","Error","pointDoc","Array","isArray","coordinates","length","undefined","hooks","afterRead","reduce","priorHook","currentHook","shouldRunHookOnAllLocales","hookPromises","Object","entries","map","hookedValue","data","operation","originalDoc","siblingData","Promise","all","resolve","allowDefaultValue","access","read","result","id","defaultValue","user","push","groupDoc","groupSelect","fields","rows","arraySelect","row","i","values","localeRows","blocksSelect","block","blocks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,OAAOY,UAAU,CAACf,MAAMuB,IAAI,CAAC,KAAK;wBAEpC,IAAI2B,2BAA2B;4BAC7B,MAAMC,eAAeC,OAAOC,OAAO,CAACtC,UAAU,CAACf,MAAMuB,IAAI,CAAC,EAAE+B,GAAG,CAAC,CAAC,CAACjD,QAAQwB,MAAM,GAC9E,AAAC,CAAA;oCACC,MAAM0B,cAAc,MAAMN,YAAY;wCACpCxD;wCACAC;wCACAC;wCACA6D,MAAM3D;wCACND;wCACAE;wCACAC;wCACAC;wCACAC;wCACAC;wCACAC;wCACAC;wCACAC;wCACAoD,WAAW;wCACXC,aAAa7D;wCACbS;wCACAY,MAAMC;wCACNV;wCACAC;wCACAC;wCACAS,YAAYC;wCACZP;wCACA6C,aAAa5C;wCACbC;wCACAC;wCACAY;oCACF;oCAEA,IAAI0B,gBAAgBX,WAAW;wCAC7B7B,UAAU,CAACf,MAAMuB,IAAI,CAAC,CAAClB,OAAO,GAAGkD;oCACnC;gCACF,CAAA;4BAGF,MAAMK,QAAQC,GAAG,CAACV;wBACpB,OAAO;4BACL,MAAMI,cAAc,MAAMN,YAAY;gCACpCxD;gCACAC;gCACAC;gCACA6D,MAAM3D;gCACND;gCACAE;gCACAC;gCACAC;gCACAC;gCACAC;gCACAC;gCACAC;gCACAC;gCACAoD,WAAW;gCACXC,aAAa7D;gCACbS;gCACAY,MAAMC;gCACNV;gCACAC;gCACAC;gCACAS,YAAYC;gCACZP;gCACA6C,aAAa5C;gCACbC;gCACAC;gCACAY,OAAOd,UAAU,CAACf,MAAMuB,IAAI,CAAC;4BAC/B;4BAEA,IAAIgC,gBAAgBX,WAAW;gCAC7B7B,UAAU,CAACf,MAAMuB,IAAI,CAAC,GAAGgC;4BAC3B;wBACF;oBACF,GAAGK,QAAQE,OAAO;gBACpB;gBACA;YACF;QAEA;YAAS;gBACP;YACF;IACF;AACF,EAAC"}
@@ -1,4 +1,4 @@
1
- import type { PayloadRequest } from '../../../types/index.js';
1
+ import type { PayloadRequest, PopulateType } from '../../../types/index.js';
2
2
  import type { JoinField, RelationshipField, UploadField } from '../../config/types.js';
3
3
  type PromiseArgs = {
4
4
  currentDepth: number;
@@ -8,10 +8,11 @@ type PromiseArgs = {
8
8
  field: JoinField | RelationshipField | UploadField;
9
9
  locale: null | string;
10
10
  overrideAccess: boolean;
11
+ populate?: PopulateType;
11
12
  req: PayloadRequest;
12
13
  showHiddenFields: boolean;
13
14
  siblingDoc: Record<string, any>;
14
15
  };
15
- export declare const relationshipPopulationPromise: ({ currentDepth, depth, draft, fallbackLocale, field, locale, overrideAccess, req, showHiddenFields, siblingDoc, }: PromiseArgs) => Promise<void>;
16
+ export declare const relationshipPopulationPromise: ({ currentDepth, depth, draft, fallbackLocale, field, locale, overrideAccess, populate: populateArg, req, showHiddenFields, siblingDoc, }: PromiseArgs) => Promise<void>;
16
17
  export {};
17
18
  //# sourceMappingURL=relationshipPopulationPromise.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"relationshipPopulationPromise.d.ts","sourceRoot":"","sources":["../../../../src/fields/hooks/afterRead/relationshipPopulationPromise.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAC7D,OAAO,KAAK,EAAE,SAAS,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAuGtF,KAAK,WAAW,GAAG;IACjB,YAAY,EAAE,MAAM,CAAA;IACpB,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,OAAO,CAAA;IACd,cAAc,EAAE,IAAI,GAAG,MAAM,CAAA;IAC7B,KAAK,EAAE,SAAS,GAAG,iBAAiB,GAAG,WAAW,CAAA;IAClD,MAAM,EAAE,IAAI,GAAG,MAAM,CAAA;IACrB,cAAc,EAAE,OAAO,CAAA;IACvB,GAAG,EAAE,cAAc,CAAA;IACnB,gBAAgB,EAAE,OAAO,CAAA;IACzB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CAChC,CAAA;AAED,eAAO,MAAM,6BAA6B,sHAWvC,WAAW,KAAG,OAAO,CAAC,IAAI,CA6G5B,CAAA"}
1
+ {"version":3,"file":"relationshipPopulationPromise.d.ts","sourceRoot":"","sources":["../../../../src/fields/hooks/afterRead/relationshipPopulationPromise.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAC3E,OAAO,KAAK,EAAE,SAAS,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AA2GtF,KAAK,WAAW,GAAG;IACjB,YAAY,EAAE,MAAM,CAAA;IACpB,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,OAAO,CAAA;IACd,cAAc,EAAE,IAAI,GAAG,MAAM,CAAA;IAC7B,KAAK,EAAE,SAAS,GAAG,iBAAiB,GAAG,WAAW,CAAA;IAClD,MAAM,EAAE,IAAI,GAAG,MAAM,CAAA;IACrB,cAAc,EAAE,OAAO,CAAA;IACvB,QAAQ,CAAC,EAAE,YAAY,CAAA;IACvB,GAAG,EAAE,cAAc,CAAA;IACnB,gBAAgB,EAAE,OAAO,CAAA;IACzB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CAChC,CAAA;AAED,eAAO,MAAM,6BAA6B,6IAYvC,WAAW,KAAG,OAAO,CAAC,IAAI,CAiH5B,CAAA"}