payload 3.0.0-beta.127 → 3.0.0-beta.129

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 (294) hide show
  1. package/dist/admin/RichText.d.ts +8 -21
  2. package/dist/admin/RichText.d.ts.map +1 -1
  3. package/dist/admin/RichText.js.map +1 -1
  4. package/dist/admin/elements/Cell.d.ts +7 -9
  5. package/dist/admin/elements/Cell.d.ts.map +1 -1
  6. package/dist/admin/elements/Cell.js.map +1 -1
  7. package/dist/admin/fields/Array.d.ts +3 -3
  8. package/dist/admin/fields/Array.d.ts.map +1 -1
  9. package/dist/admin/fields/Array.js.map +1 -1
  10. package/dist/admin/fields/Blocks.d.ts +2 -1
  11. package/dist/admin/fields/Blocks.d.ts.map +1 -1
  12. package/dist/admin/fields/Blocks.js.map +1 -1
  13. package/dist/admin/fields/Checkbox.d.ts +1 -0
  14. package/dist/admin/fields/Checkbox.d.ts.map +1 -1
  15. package/dist/admin/fields/Checkbox.js.map +1 -1
  16. package/dist/admin/fields/Code.d.ts +2 -1
  17. package/dist/admin/fields/Code.d.ts.map +1 -1
  18. package/dist/admin/fields/Code.js.map +1 -1
  19. package/dist/admin/fields/Collapsible.d.ts +5 -2
  20. package/dist/admin/fields/Collapsible.d.ts.map +1 -1
  21. package/dist/admin/fields/Collapsible.js.map +1 -1
  22. package/dist/admin/fields/Date.d.ts +1 -0
  23. package/dist/admin/fields/Date.d.ts.map +1 -1
  24. package/dist/admin/fields/Date.js.map +1 -1
  25. package/dist/admin/fields/Email.d.ts +1 -1
  26. package/dist/admin/fields/Email.d.ts.map +1 -1
  27. package/dist/admin/fields/Email.js.map +1 -1
  28. package/dist/admin/fields/Group.d.ts +5 -2
  29. package/dist/admin/fields/Group.d.ts.map +1 -1
  30. package/dist/admin/fields/Group.js.map +1 -1
  31. package/dist/admin/fields/Hidden.d.ts +7 -6
  32. package/dist/admin/fields/Hidden.d.ts.map +1 -1
  33. package/dist/admin/fields/Hidden.js.map +1 -1
  34. package/dist/admin/fields/JSON.d.ts +1 -0
  35. package/dist/admin/fields/JSON.d.ts.map +1 -1
  36. package/dist/admin/fields/JSON.js.map +1 -1
  37. package/dist/admin/fields/Join.d.ts +3 -1
  38. package/dist/admin/fields/Join.d.ts.map +1 -1
  39. package/dist/admin/fields/Join.js.map +1 -1
  40. package/dist/admin/fields/Number.d.ts +1 -0
  41. package/dist/admin/fields/Number.d.ts.map +1 -1
  42. package/dist/admin/fields/Number.js.map +1 -1
  43. package/dist/admin/fields/Point.d.ts +1 -0
  44. package/dist/admin/fields/Point.d.ts.map +1 -1
  45. package/dist/admin/fields/Point.js.map +1 -1
  46. package/dist/admin/fields/Radio.d.ts +1 -0
  47. package/dist/admin/fields/Radio.d.ts.map +1 -1
  48. package/dist/admin/fields/Radio.js.map +1 -1
  49. package/dist/admin/fields/Relationship.d.ts +1 -0
  50. package/dist/admin/fields/Relationship.d.ts.map +1 -1
  51. package/dist/admin/fields/Relationship.js.map +1 -1
  52. package/dist/admin/fields/RichText.d.ts +3 -2
  53. package/dist/admin/fields/RichText.d.ts.map +1 -1
  54. package/dist/admin/fields/RichText.js.map +1 -1
  55. package/dist/admin/fields/Row.d.ts +1 -2
  56. package/dist/admin/fields/Row.d.ts.map +1 -1
  57. package/dist/admin/fields/Row.js.map +1 -1
  58. package/dist/admin/fields/Select.d.ts +1 -0
  59. package/dist/admin/fields/Select.d.ts.map +1 -1
  60. package/dist/admin/fields/Select.js.map +1 -1
  61. package/dist/admin/fields/Tabs.d.ts +4 -2
  62. package/dist/admin/fields/Tabs.d.ts.map +1 -1
  63. package/dist/admin/fields/Tabs.js.map +1 -1
  64. package/dist/admin/fields/Text.d.ts +1 -0
  65. package/dist/admin/fields/Text.d.ts.map +1 -1
  66. package/dist/admin/fields/Text.js.map +1 -1
  67. package/dist/admin/fields/Textarea.d.ts +1 -0
  68. package/dist/admin/fields/Textarea.d.ts.map +1 -1
  69. package/dist/admin/fields/Textarea.js.map +1 -1
  70. package/dist/admin/fields/UI.d.ts +8 -0
  71. package/dist/admin/fields/UI.d.ts.map +1 -0
  72. package/dist/admin/fields/UI.js +3 -0
  73. package/dist/admin/fields/UI.js.map +1 -0
  74. package/dist/admin/fields/Upload.d.ts +1 -0
  75. package/dist/admin/fields/Upload.d.ts.map +1 -1
  76. package/dist/admin/fields/Upload.js.map +1 -1
  77. package/dist/admin/forms/Description.d.ts +1 -2
  78. package/dist/admin/forms/Description.d.ts.map +1 -1
  79. package/dist/admin/forms/Description.js.map +1 -1
  80. package/dist/admin/forms/Error.d.ts +0 -2
  81. package/dist/admin/forms/Error.d.ts.map +1 -1
  82. package/dist/admin/forms/Error.js.map +1 -1
  83. package/dist/admin/forms/Field.d.ts +53 -29
  84. package/dist/admin/forms/Field.d.ts.map +1 -1
  85. package/dist/admin/forms/Field.js.map +1 -1
  86. package/dist/admin/forms/Form.d.ts +46 -3
  87. package/dist/admin/forms/Form.d.ts.map +1 -1
  88. package/dist/admin/forms/Form.js.map +1 -1
  89. package/dist/admin/forms/Label.d.ts +1 -2
  90. package/dist/admin/forms/Label.d.ts.map +1 -1
  91. package/dist/admin/forms/Label.js.map +1 -1
  92. package/dist/admin/functions/index.d.ts +44 -0
  93. package/dist/admin/functions/index.d.ts.map +1 -0
  94. package/dist/admin/functions/index.js +3 -0
  95. package/dist/admin/functions/index.js.map +1 -0
  96. package/dist/admin/types.d.ts +63 -20
  97. package/dist/admin/types.d.ts.map +1 -1
  98. package/dist/admin/types.js +4 -1
  99. package/dist/admin/types.js.map +1 -1
  100. package/dist/admin/views/types.d.ts +9 -6
  101. package/dist/admin/views/types.d.ts.map +1 -1
  102. package/dist/admin/views/types.js.map +1 -1
  103. package/dist/assets/images/github-banner-nextjs-native.jpg +0 -0
  104. package/dist/auth/ensureUsernameOrEmail.js +4 -4
  105. package/dist/auth/ensureUsernameOrEmail.js.map +1 -1
  106. package/dist/auth/getFieldsToSign.js +13 -13
  107. package/dist/auth/getFieldsToSign.js.map +1 -1
  108. package/dist/auth/operations/local/auth.d.ts.map +1 -1
  109. package/dist/auth/operations/local/auth.js +2 -2
  110. package/dist/auth/operations/local/auth.js.map +1 -1
  111. package/dist/auth/operations/login.js +10 -10
  112. package/dist/auth/operations/login.js.map +1 -1
  113. package/dist/auth/strategies/local/generatePasswordSaltHash.js +2 -2
  114. package/dist/auth/strategies/local/generatePasswordSaltHash.js.map +1 -1
  115. package/dist/auth/strategies/local/register.js +4 -4
  116. package/dist/auth/strategies/local/register.js.map +1 -1
  117. package/dist/bin/generateImportMap/index.d.ts.map +1 -1
  118. package/dist/bin/generateImportMap/index.js +32 -5
  119. package/dist/bin/generateImportMap/index.js.map +1 -1
  120. package/dist/bin/generateImportMap/parsePayloadComponent.d.ts +1 -1
  121. package/dist/bin/generateImportMap/parsePayloadComponent.js +5 -5
  122. package/dist/bin/generateImportMap/parsePayloadComponent.js.map +1 -1
  123. package/dist/bin/migrate.js +17 -17
  124. package/dist/bin/migrate.js.map +1 -1
  125. package/dist/collections/config/client.d.ts +23 -35
  126. package/dist/collections/config/client.d.ts.map +1 -1
  127. package/dist/collections/config/client.js +104 -1
  128. package/dist/collections/config/client.js.map +1 -1
  129. package/dist/collections/config/sanitize.d.ts.map +1 -1
  130. package/dist/collections/config/sanitize.js +4 -2
  131. package/dist/collections/config/sanitize.js.map +1 -1
  132. package/dist/collections/config/types.d.ts +3 -3
  133. package/dist/collections/config/types.d.ts.map +1 -1
  134. package/dist/collections/config/types.js.map +1 -1
  135. package/dist/collections/operations/countVersions.d.ts +14 -0
  136. package/dist/collections/operations/countVersions.d.ts.map +1 -0
  137. package/dist/collections/operations/countVersions.js +74 -0
  138. package/dist/collections/operations/countVersions.js.map +1 -0
  139. package/dist/collections/operations/local/count.d.ts.map +1 -1
  140. package/dist/collections/operations/local/count.js +1 -0
  141. package/dist/collections/operations/local/count.js.map +1 -1
  142. package/dist/collections/operations/local/countVersions.d.ts +20 -0
  143. package/dist/collections/operations/local/countVersions.d.ts.map +1 -0
  144. package/dist/collections/operations/local/countVersions.js +20 -0
  145. package/dist/collections/operations/local/countVersions.js.map +1 -0
  146. package/dist/collections/operations/local/index.d.ts +2 -0
  147. package/dist/collections/operations/local/index.d.ts.map +1 -1
  148. package/dist/collections/operations/local/index.js +2 -0
  149. package/dist/collections/operations/local/index.js.map +1 -1
  150. package/dist/collections/operations/utils.d.ts +6 -0
  151. package/dist/collections/operations/utils.d.ts.map +1 -1
  152. package/dist/collections/operations/utils.js.map +1 -1
  153. package/dist/config/client.d.ts +10 -13
  154. package/dist/config/client.d.ts.map +1 -1
  155. package/dist/config/client.js +36 -0
  156. package/dist/config/client.js.map +1 -1
  157. package/dist/config/types.d.ts +20 -15
  158. package/dist/config/types.d.ts.map +1 -1
  159. package/dist/config/types.js.map +1 -1
  160. package/dist/database/getLocalizedPaths.js +1 -1
  161. package/dist/database/getLocalizedPaths.js.map +1 -1
  162. package/dist/database/sanitizeJoinQuery.js +6 -6
  163. package/dist/database/sanitizeJoinQuery.js.map +1 -1
  164. package/dist/database/types.d.ts +14 -0
  165. package/dist/database/types.d.ts.map +1 -1
  166. package/dist/database/types.js.map +1 -1
  167. package/dist/errors/ValidationError.d.ts +1 -1
  168. package/dist/errors/ValidationError.d.ts.map +1 -1
  169. package/dist/errors/ValidationError.js +1 -1
  170. package/dist/errors/ValidationError.js.map +1 -1
  171. package/dist/exports/shared.d.ts +3 -1
  172. package/dist/exports/shared.d.ts.map +1 -1
  173. package/dist/exports/shared.js +3 -1
  174. package/dist/exports/shared.js.map +1 -1
  175. package/dist/fields/config/client.d.ts +16 -1
  176. package/dist/fields/config/client.d.ts.map +1 -1
  177. package/dist/fields/config/client.js +229 -1
  178. package/dist/fields/config/client.js.map +1 -1
  179. package/dist/fields/config/sanitize.d.ts +2 -2
  180. package/dist/fields/config/sanitize.d.ts.map +1 -1
  181. package/dist/fields/config/sanitize.js +7 -21
  182. package/dist/fields/config/sanitize.js.map +1 -1
  183. package/dist/fields/config/sanitizeJoinField.d.ts +2 -2
  184. package/dist/fields/config/sanitizeJoinField.d.ts.map +1 -1
  185. package/dist/fields/config/sanitizeJoinField.js +2 -2
  186. package/dist/fields/config/sanitizeJoinField.js.map +1 -1
  187. package/dist/fields/config/types.d.ts +28 -171
  188. package/dist/fields/config/types.d.ts.map +1 -1
  189. package/dist/fields/config/types.js.map +1 -1
  190. package/dist/fields/getFieldPaths.d.ts +25 -8
  191. package/dist/fields/getFieldPaths.d.ts.map +1 -1
  192. package/dist/fields/getFieldPaths.js +9 -37
  193. package/dist/fields/getFieldPaths.js.map +1 -1
  194. package/dist/fields/hooks/afterChange/promise.d.ts +2 -1
  195. package/dist/fields/hooks/afterChange/promise.d.ts.map +1 -1
  196. package/dist/fields/hooks/afterChange/promise.js +66 -62
  197. package/dist/fields/hooks/afterChange/promise.js.map +1 -1
  198. package/dist/fields/hooks/afterChange/traverseFields.d.ts.map +1 -1
  199. package/dist/fields/hooks/afterChange/traverseFields.js +2 -1
  200. package/dist/fields/hooks/afterChange/traverseFields.js.map +1 -1
  201. package/dist/fields/hooks/afterRead/promise.d.ts +2 -1
  202. package/dist/fields/hooks/afterRead/promise.d.ts.map +1 -1
  203. package/dist/fields/hooks/afterRead/promise.js +107 -103
  204. package/dist/fields/hooks/afterRead/promise.js.map +1 -1
  205. package/dist/fields/hooks/afterRead/traverseFields.d.ts.map +1 -1
  206. package/dist/fields/hooks/afterRead/traverseFields.js +2 -1
  207. package/dist/fields/hooks/afterRead/traverseFields.js.map +1 -1
  208. package/dist/fields/hooks/beforeChange/index.d.ts.map +1 -1
  209. package/dist/fields/hooks/beforeChange/index.js.map +1 -1
  210. package/dist/fields/hooks/beforeChange/promise.d.ts +8 -5
  211. package/dist/fields/hooks/beforeChange/promise.d.ts.map +1 -1
  212. package/dist/fields/hooks/beforeChange/promise.js +99 -110
  213. package/dist/fields/hooks/beforeChange/promise.js.map +1 -1
  214. package/dist/fields/hooks/beforeChange/traverseFields.d.ts +2 -4
  215. package/dist/fields/hooks/beforeChange/traverseFields.d.ts.map +1 -1
  216. package/dist/fields/hooks/beforeChange/traverseFields.js +2 -1
  217. package/dist/fields/hooks/beforeChange/traverseFields.js.map +1 -1
  218. package/dist/fields/hooks/beforeDuplicate/promise.d.ts +2 -1
  219. package/dist/fields/hooks/beforeDuplicate/promise.d.ts.map +1 -1
  220. package/dist/fields/hooks/beforeDuplicate/promise.js +47 -43
  221. package/dist/fields/hooks/beforeDuplicate/promise.js.map +1 -1
  222. package/dist/fields/hooks/beforeDuplicate/traverseFields.d.ts.map +1 -1
  223. package/dist/fields/hooks/beforeDuplicate/traverseFields.js +2 -1
  224. package/dist/fields/hooks/beforeDuplicate/traverseFields.js.map +1 -1
  225. package/dist/fields/hooks/beforeValidate/promise.d.ts +2 -1
  226. package/dist/fields/hooks/beforeValidate/promise.d.ts.map +1 -1
  227. package/dist/fields/hooks/beforeValidate/promise.js +105 -101
  228. package/dist/fields/hooks/beforeValidate/promise.js.map +1 -1
  229. package/dist/fields/hooks/beforeValidate/traverseFields.d.ts.map +1 -1
  230. package/dist/fields/hooks/beforeValidate/traverseFields.js +2 -1
  231. package/dist/fields/hooks/beforeValidate/traverseFields.js.map +1 -1
  232. package/dist/globals/config/client.d.ts +18 -25
  233. package/dist/globals/config/client.d.ts.map +1 -1
  234. package/dist/globals/config/client.js +53 -1
  235. package/dist/globals/config/client.js.map +1 -1
  236. package/dist/globals/config/sanitize.d.ts.map +1 -1
  237. package/dist/globals/config/sanitize.js +3 -1
  238. package/dist/globals/config/sanitize.js.map +1 -1
  239. package/dist/globals/operations/countGlobalVersions.d.ts +13 -0
  240. package/dist/globals/operations/countGlobalVersions.d.ts.map +1 -0
  241. package/dist/globals/operations/countGlobalVersions.js +49 -0
  242. package/dist/globals/operations/countGlobalVersions.js.map +1 -0
  243. package/dist/globals/operations/local/countGlobalVersions.d.ts +20 -0
  244. package/dist/globals/operations/local/countGlobalVersions.d.ts.map +1 -0
  245. package/dist/globals/operations/local/countGlobalVersions.js +20 -0
  246. package/dist/globals/operations/local/countGlobalVersions.js.map +1 -0
  247. package/dist/globals/operations/local/index.d.ts +2 -0
  248. package/dist/globals/operations/local/index.d.ts.map +1 -1
  249. package/dist/globals/operations/local/index.js +2 -0
  250. package/dist/globals/operations/local/index.js.map +1 -1
  251. package/dist/index.d.ts +28 -12
  252. package/dist/index.d.ts.map +1 -1
  253. package/dist/index.js +21 -2
  254. package/dist/index.js.map +1 -1
  255. package/dist/queues/config/jobsCollection.d.ts.map +1 -1
  256. package/dist/queues/config/jobsCollection.js +2 -11
  257. package/dist/queues/config/jobsCollection.js.map +1 -1
  258. package/dist/queues/config/types/workflowTypes.d.ts +2 -1
  259. package/dist/queues/config/types/workflowTypes.d.ts.map +1 -1
  260. package/dist/queues/config/types/workflowTypes.js.map +1 -1
  261. package/dist/queues/localAPI.d.ts +2 -0
  262. package/dist/queues/localAPI.d.ts.map +1 -1
  263. package/dist/queues/localAPI.js +13 -0
  264. package/dist/queues/localAPI.js.map +1 -1
  265. package/dist/utilities/configToJSONSchema.js +232 -232
  266. package/dist/utilities/configToJSONSchema.js.map +1 -1
  267. package/dist/utilities/createLocalReq.d.ts +1 -1
  268. package/dist/utilities/createLocalReq.d.ts.map +1 -1
  269. package/dist/utilities/createLocalReq.js +4 -4
  270. package/dist/utilities/createLocalReq.js.map +1 -1
  271. package/dist/utilities/deepCopyObject.d.ts +1 -0
  272. package/dist/utilities/deepCopyObject.d.ts.map +1 -1
  273. package/dist/utilities/deepCopyObject.js +23 -0
  274. package/dist/utilities/deepCopyObject.js.map +1 -1
  275. package/dist/utilities/fieldSchemaToJSON.js +17 -17
  276. package/dist/utilities/fieldSchemaToJSON.js.map +1 -1
  277. package/dist/utilities/formatErrors.d.ts +6 -0
  278. package/dist/utilities/formatErrors.d.ts.map +1 -0
  279. package/dist/utilities/formatErrors.js +56 -0
  280. package/dist/utilities/formatErrors.js.map +1 -0
  281. package/dist/utilities/telemetry/conf/index.js +2 -2
  282. package/dist/utilities/telemetry/conf/index.js.map +1 -1
  283. package/dist/versions/saveVersion.d.ts.map +1 -1
  284. package/dist/versions/saveVersion.js +1 -7
  285. package/dist/versions/saveVersion.js.map +1 -1
  286. package/dist/versions/types.d.ts +1 -1
  287. package/dist/versions/types.d.ts.map +1 -1
  288. package/dist/versions/types.js.map +1 -1
  289. package/license.md +22 -0
  290. package/package.json +3 -3
  291. package/dist/utilities/mergeListSearchAndWhere.d.ts +0 -12
  292. package/dist/utilities/mergeListSearchAndWhere.d.ts.map +0 -1
  293. package/dist/utilities/mergeListSearchAndWhere.js +0 -57
  294. package/dist/utilities/mergeListSearchAndWhere.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/fields/hooks/afterRead/traverseFields.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 {\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 { promise } from './promise.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 /**\n * fieldPromises are used for things like field hooks. They should be awaited before awaiting populationPromises\n */\n fieldPromises: Promise<void>[]\n fields: (Field | TabAsField)[]\n findMany: boolean\n flattenLocales: boolean\n global: null | SanitizedGlobalConfig\n locale: null | string\n overrideAccess: boolean\n path: (number | string)[]\n populate?: PopulateType\n populationPromises: Promise<void>[]\n req: PayloadRequest\n schemaPath: string[]\n select?: SelectType\n selectMode?: SelectMode\n showHiddenFields: boolean\n siblingDoc: JsonObject\n triggerAccessControl?: boolean\n triggerHooks?: boolean\n}\n\nexport const traverseFields = ({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n 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,\n showHiddenFields,\n siblingDoc,\n triggerAccessControl = true,\n triggerHooks = true,\n}: Args): void => {\n fields.forEach((field) => {\n fieldPromises.push(\n promise({\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: path,\n parentSchemaPath: schemaPath,\n populate,\n populationPromises,\n req,\n select,\n selectMode,\n showHiddenFields,\n siblingDoc,\n triggerAccessControl,\n triggerHooks,\n }),\n )\n })\n}\n"],"names":["promise","traverseFields","collection","context","currentDepth","depth","doc","draft","fallbackLocale","fieldPromises","fields","findMany","flattenLocales","global","locale","overrideAccess","path","populate","populationPromises","req","schemaPath","select","selectMode","showHiddenFields","siblingDoc","triggerAccessControl","triggerHooks","forEach","field","push","parentPath","parentSchemaPath"],"mappings":"AAYA,SAASA,OAAO,QAAQ,eAAc;AAiCtC,OAAO,MAAMC,iBAAiB,CAAC,EAC7BC,UAAU,EACVC,OAAO,EACPC,YAAY,EACZC,KAAK,EACLC,GAAG,EACHC,KAAK,EACLC,cAAc,EACdC,aAAa,EACbC,MAAM,EACNC,QAAQ,EACRC,cAAc,EACdC,MAAM,EACNC,MAAM,EACNC,cAAc,EACdC,IAAI,EACJC,QAAQ,EACRC,kBAAkB,EAClBC,GAAG,EACHC,UAAU,EACVC,MAAM,EACNC,UAAU,EACVC,gBAAgB,EAChBC,UAAU,EACVC,uBAAuB,IAAI,EAC3BC,eAAe,IAAI,EACd;IACLhB,OAAOiB,OAAO,CAAC,CAACC;QACdnB,cAAcoB,IAAI,CAChB7B,QAAQ;YACNE;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAoB;YACAnB;YACAE;YACAC;YACAC;YACAC;YACAC;YACAe,YAAYd;YACZe,kBAAkBX;YAClBH;YACAC;YACAC;YACAE;YACAC;YACAC;YACAC;YACAC;YACAC;QACF;IAEJ;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../../src/fields/hooks/afterRead/traverseFields.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 {\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 { promise } from './promise.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 /**\n * fieldPromises are used for things like field hooks. They should be awaited before awaiting populationPromises\n */\n fieldPromises: Promise<void>[]\n fields: (Field | TabAsField)[]\n findMany: boolean\n flattenLocales: boolean\n global: null | SanitizedGlobalConfig\n locale: null | string\n overrideAccess: boolean\n path: (number | string)[]\n populate?: PopulateType\n populationPromises: Promise<void>[]\n req: PayloadRequest\n schemaPath: string[]\n select?: SelectType\n selectMode?: SelectMode\n showHiddenFields: boolean\n siblingDoc: JsonObject\n triggerAccessControl?: boolean\n triggerHooks?: boolean\n}\n\nexport const traverseFields = ({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n fieldPromises,\n 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,\n showHiddenFields,\n siblingDoc,\n triggerAccessControl = true,\n triggerHooks = true,\n}: Args): void => {\n fields.forEach((field, fieldIndex) => {\n fieldPromises.push(\n promise({\n collection,\n context,\n currentDepth,\n depth,\n doc,\n draft,\n fallbackLocale,\n field,\n fieldIndex,\n fieldPromises,\n findMany,\n flattenLocales,\n global,\n locale,\n overrideAccess,\n parentPath: path,\n parentSchemaPath: schemaPath,\n populate,\n populationPromises,\n req,\n select,\n selectMode,\n showHiddenFields,\n siblingDoc,\n triggerAccessControl,\n triggerHooks,\n }),\n )\n })\n}\n"],"names":["promise","traverseFields","collection","context","currentDepth","depth","doc","draft","fallbackLocale","fieldPromises","fields","findMany","flattenLocales","global","locale","overrideAccess","path","populate","populationPromises","req","schemaPath","select","selectMode","showHiddenFields","siblingDoc","triggerAccessControl","triggerHooks","forEach","field","fieldIndex","push","parentPath","parentSchemaPath"],"mappings":"AAYA,SAASA,OAAO,QAAQ,eAAc;AAiCtC,OAAO,MAAMC,iBAAiB,CAAC,EAC7BC,UAAU,EACVC,OAAO,EACPC,YAAY,EACZC,KAAK,EACLC,GAAG,EACHC,KAAK,EACLC,cAAc,EACdC,aAAa,EACbC,MAAM,EACNC,QAAQ,EACRC,cAAc,EACdC,MAAM,EACNC,MAAM,EACNC,cAAc,EACdC,IAAI,EACJC,QAAQ,EACRC,kBAAkB,EAClBC,GAAG,EACHC,UAAU,EACVC,MAAM,EACNC,UAAU,EACVC,gBAAgB,EAChBC,UAAU,EACVC,uBAAuB,IAAI,EAC3BC,eAAe,IAAI,EACd;IACLhB,OAAOiB,OAAO,CAAC,CAACC,OAAOC;QACrBpB,cAAcqB,IAAI,CAChB9B,QAAQ;YACNE;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAoB;YACAC;YACApB;YACAE;YACAC;YACAC;YACAC;YACAC;YACAgB,YAAYf;YACZgB,kBAAkBZ;YAClBH;YACAC;YACAC;YACAE;YACAC;YACAC;YACAC;YACAC;YACAC;QACF;IAEJ;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/fields/hooks/beforeChange/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,SAAS,EA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AAG,MAAM,CAAA;IACpB,SAAS,EAAE,SAAS,CAAA;IACpB,GAAG,EAAE,cAAc,CAAA;IACnB,cAAc,CAAC,EAAE,OAAO,CAAA;CACzB,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,YAAY,GAAU,CAAC,SAAS,UAAU,iHAWpD,IAAI,CAAC,CAAC,CAAC,KAAG,OAAO,CAAC,CAAC,CA4CrB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/fields/hooks/beforeChange/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, Operation, PayloadRequest } from '../../../types/index.js'\n\nimport { ValidationError } from '../../../errors/index.js'\nimport { deepCopyObjectSimple } from '../../../utilities/deepCopyObject.js'\nimport { traverseFields } from './traverseFields.js'\nexport type Args<T extends JsonObject> = {\n collection: null | SanitizedCollectionConfig\n context: RequestContext\n data: T\n doc: T\n docWithLocales: JsonObject\n global: null | SanitizedGlobalConfig\n id?: number | string\n operation: Operation\n req: PayloadRequest\n skipValidation?: boolean\n}\n\n/**\n * This function is responsible for the following actions, in order:\n * - Run condition\n * - Execute field hooks\n * - Validate data\n * - Transform data for storage\n * - Unflatten locales. The input `data` is the normal document for one locale. The output result will become the document with locales.\n */\nexport const beforeChange = async <T extends JsonObject>({\n id,\n collection,\n context,\n data: incomingData,\n doc,\n docWithLocales,\n global,\n operation,\n req,\n skipValidation,\n}: Args<T>): Promise<T> => {\n const data = deepCopyObjectSimple(incomingData)\n const mergeLocaleActions = []\n const errors: { field: string; message: string }[] = []\n\n await traverseFields({\n id,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n errors,\n fields: collection?.fields || global?.fields,\n global,\n mergeLocaleActions,\n operation,\n path: [],\n req,\n schemaPath: [],\n siblingData: data,\n siblingDoc: doc,\n siblingDocWithLocales: docWithLocales,\n skipValidation,\n })\n\n if (errors.length > 0) {\n throw new ValidationError(\n {\n id,\n collection: collection?.slug,\n errors,\n global: global?.slug,\n },\n req.t,\n )\n }\n\n await mergeLocaleActions.reduce(async (priorAction, action) => {\n await priorAction\n await action()\n }, Promise.resolve())\n\n return data\n}\n"],"names":["ValidationError","deepCopyObjectSimple","traverseFields","beforeChange","id","collection","context","data","incomingData","doc","docWithLocales","global","operation","req","skipValidation","mergeLocaleActions","errors","fields","path","schemaPath","siblingData","siblingDoc","siblingDocWithLocales","length","slug","t","reduce","priorAction","action","Promise","resolve"],"mappings":"AAKA,SAASA,eAAe,QAAQ,2BAA0B;AAC1D,SAASC,oBAAoB,QAAQ,uCAAsC;AAC3E,SAASC,cAAc,QAAQ,sBAAqB;AAcpD;;;;;;;CAOC,GACD,OAAO,MAAMC,eAAe,OAA6B,EACvDC,EAAE,EACFC,UAAU,EACVC,OAAO,EACPC,MAAMC,YAAY,EAClBC,GAAG,EACHC,cAAc,EACdC,MAAM,EACNC,SAAS,EACTC,GAAG,EACHC,cAAc,EACN;IACR,MAAMP,OAAON,qBAAqBO;IAClC,MAAMO,qBAAqB,EAAE;IAC7B,MAAMC,SAA+C,EAAE;IAEvD,MAAMd,eAAe;QACnBE;QACAC;QACAC;QACAC;QACAE;QACAC;QACAM;QACAC,QAAQZ,YAAYY,UAAUN,QAAQM;QACtCN;QACAI;QACAH;QACAM,MAAM,EAAE;QACRL;QACAM,YAAY,EAAE;QACdC,aAAab;QACbc,YAAYZ;QACZa,uBAAuBZ;QACvBI;IACF;IAEA,IAAIE,OAAOO,MAAM,GAAG,GAAG;QACrB,MAAM,IAAIvB,gBACR;YACEI;YACAC,YAAYA,YAAYmB;YACxBR;YACAL,QAAQA,QAAQa;QAClB,GACAX,IAAIY,CAAC;IAET;IAEA,MAAMV,mBAAmBW,MAAM,CAAC,OAAOC,aAAaC;QAClD,MAAMD;QACN,MAAMC;IACR,GAAGC,QAAQC,OAAO;IAElB,OAAOvB;AACT,EAAC"}
1
+ {"version":3,"sources":["../../../../src/fields/hooks/beforeChange/index.ts"],"sourcesContent":["import type { SanitizedCollectionConfig } from '../../../collections/config/types.js'\nimport type { ValidationFieldError } from '../../../errors/index.js'\nimport type { SanitizedGlobalConfig } from '../../../globals/config/types.js'\nimport type { RequestContext } from '../../../index.js'\nimport type { JsonObject, Operation, PayloadRequest } from '../../../types/index.js'\n\nimport { ValidationError } from '../../../errors/index.js'\nimport { deepCopyObjectSimple } from '../../../utilities/deepCopyObject.js'\nimport { traverseFields } from './traverseFields.js'\nexport type Args<T extends JsonObject> = {\n collection: null | SanitizedCollectionConfig\n context: RequestContext\n data: T\n doc: T\n docWithLocales: JsonObject\n global: null | SanitizedGlobalConfig\n id?: number | string\n operation: Operation\n req: PayloadRequest\n skipValidation?: boolean\n}\n\n/**\n * This function is responsible for the following actions, in order:\n * - Run condition\n * - Execute field hooks\n * - Validate data\n * - Transform data for storage\n * - Unflatten locales. The input `data` is the normal document for one locale. The output result will become the document with locales.\n */\nexport const beforeChange = async <T extends JsonObject>({\n id,\n collection,\n context,\n data: incomingData,\n doc,\n docWithLocales,\n global,\n operation,\n req,\n skipValidation,\n}: Args<T>): Promise<T> => {\n const data = deepCopyObjectSimple(incomingData)\n const mergeLocaleActions = []\n const errors: ValidationFieldError[] = []\n\n await traverseFields({\n id,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n errors,\n fields: collection?.fields || global?.fields,\n global,\n mergeLocaleActions,\n operation,\n path: [],\n req,\n schemaPath: [],\n siblingData: data,\n siblingDoc: doc,\n siblingDocWithLocales: docWithLocales,\n skipValidation,\n })\n\n if (errors.length > 0) {\n throw new ValidationError(\n {\n id,\n collection: collection?.slug,\n errors,\n global: global?.slug,\n },\n req.t,\n )\n }\n\n await mergeLocaleActions.reduce(async (priorAction, action) => {\n await priorAction\n await action()\n }, Promise.resolve())\n\n return data\n}\n"],"names":["ValidationError","deepCopyObjectSimple","traverseFields","beforeChange","id","collection","context","data","incomingData","doc","docWithLocales","global","operation","req","skipValidation","mergeLocaleActions","errors","fields","path","schemaPath","siblingData","siblingDoc","siblingDocWithLocales","length","slug","t","reduce","priorAction","action","Promise","resolve"],"mappings":"AAMA,SAASA,eAAe,QAAQ,2BAA0B;AAC1D,SAASC,oBAAoB,QAAQ,uCAAsC;AAC3E,SAASC,cAAc,QAAQ,sBAAqB;AAcpD;;;;;;;CAOC,GACD,OAAO,MAAMC,eAAe,OAA6B,EACvDC,EAAE,EACFC,UAAU,EACVC,OAAO,EACPC,MAAMC,YAAY,EAClBC,GAAG,EACHC,cAAc,EACdC,MAAM,EACNC,SAAS,EACTC,GAAG,EACHC,cAAc,EACN;IACR,MAAMP,OAAON,qBAAqBO;IAClC,MAAMO,qBAAqB,EAAE;IAC7B,MAAMC,SAAiC,EAAE;IAEzC,MAAMd,eAAe;QACnBE;QACAC;QACAC;QACAC;QACAE;QACAC;QACAM;QACAC,QAAQZ,YAAYY,UAAUN,QAAQM;QACtCN;QACAI;QACAH;QACAM,MAAM,EAAE;QACRL;QACAM,YAAY,EAAE;QACdC,aAAab;QACbc,YAAYZ;QACZa,uBAAuBZ;QACvBI;IACF;IAEA,IAAIE,OAAOO,MAAM,GAAG,GAAG;QACrB,MAAM,IAAIvB,gBACR;YACEI;YACAC,YAAYA,YAAYmB;YACxBR;YACAL,QAAQA,QAAQa;QAClB,GACAX,IAAIY,CAAC;IAET;IAEA,MAAMV,mBAAmBW,MAAM,CAAC,OAAOC,aAAaC;QAClD,MAAMD;QACN,MAAMC;IACR,GAAGC,QAAQC,OAAO;IAElB,OAAOvB;AACT,EAAC"}
@@ -1,4 +1,5 @@
1
1
  import type { SanitizedCollectionConfig } from '../../../collections/config/types.js';
2
+ import type { ValidationFieldError } from '../../../errors/index.js';
2
3
  import type { SanitizedGlobalConfig } from '../../../globals/config/types.js';
3
4
  import type { RequestContext } from '../../../index.js';
4
5
  import type { JsonObject, Operation, PayloadRequest } from '../../../types/index.js';
@@ -9,11 +10,13 @@ type Args = {
9
10
  data: JsonObject;
10
11
  doc: JsonObject;
11
12
  docWithLocales: JsonObject;
12
- errors: {
13
- field: string;
14
- message: string;
15
- }[];
13
+ errors: ValidationFieldError[];
16
14
  field: Field | TabAsField;
15
+ /**
16
+ * The index of the field as it appears in the parent's fields array. This is used to construct the field path / schemaPath
17
+ * for unnamed fields like rows and collapsibles.
18
+ */
19
+ fieldIndex: number;
17
20
  global: null | SanitizedGlobalConfig;
18
21
  id?: number | string;
19
22
  mergeLocaleActions: (() => Promise<void>)[];
@@ -32,6 +35,6 @@ type Args = {
32
35
  siblingDocWithLocales?: JsonObject;
33
36
  skipValidation: boolean;
34
37
  };
35
- export declare const promise: ({ id, collection, context, data, doc, docWithLocales, errors, field, global, mergeLocaleActions, operation, parentPath, parentSchemaPath, req, siblingData, siblingDoc, siblingDocWithLocales, skipValidation, }: Args) => Promise<void>;
38
+ export declare const promise: ({ id, collection, context, data, doc, docWithLocales, errors, field, fieldIndex, global, mergeLocaleActions, operation, parentPath, parentSchemaPath, req, siblingData, siblingDoc, siblingDocWithLocales, skipValidation, }: Args) => Promise<void>;
36
39
  export {};
37
40
  //# sourceMappingURL=promise.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"promise.d.ts","sourceRoot":"","sources":["../../../../src/fields/hooks/beforeChange/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,SAAS,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AACpF,OAAO,KAAK,EAAE,KAAK,EAAiB,UAAU,EAAmB,MAAM,uBAAuB,CAAA;AAS9F,KAAK,IAAI,GAAG;IACV,UAAU,EAAE,IAAI,GAAG,yBAAyB,CAAA;IAC5C,OAAO,EAAE,cAAc,CAAA;I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,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAS9D,KAAK,IAAI,GAAG;IACV,UAAU,EAAE,IAAI,GAAG,yBAAyB,CAAA;IAC5C,OAAO,EAAE,cAAc,CAAA;IACvB,IAAI,EAAE,UAAU,CAAA;IAChB,GAAG,EAAE,UAAU,CAAA;IACf,cAAc,EAAE,UAAU,CAAA;IAC1B,MAAM,EAAE,oBAAoB,EAAE,CAAA;IAC9B,KAAK,EAAE,KAAK,GAAG,UAAU,CAAA;IACzB;;;OAGG;IACH,UAAU,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,IAAI,GAAG,qBAAqB,CAAA;IACpC,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACpB,kBAAkB,EAAE,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,CAAA;IAC3C,SAAS,EAAE,SAAS,CAAA;IACpB;;OAEG;IACH,UAAU,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAA;IAC/B;;OAEG;IACH,gBAAgB,EAAE,MAAM,EAAE,CAAA;IAC1B,GAAG,EAAE,cAAc,CAAA;IACnB,WAAW,EAAE,UAAU,CAAA;IACvB,UAAU,EAAE,UAAU,CAAA;IACtB,qBAAqB,CAAC,EAAE,UAAU,CAAA;IAClC,cAAc,EAAE,OAAO,CAAA;CACxB,CAAA;AAUD,eAAO,MAAM,OAAO,iOAoBjB,IAAI,KAAG,OAAO,CAAC,IAAI,CA2ZrB,CAAA"}
@@ -11,7 +11,7 @@ import { traverseFields } from './traverseFields.js';
11
11
  // - Transform data for storage
12
12
  // - beforeDuplicate hooks (if duplicate)
13
13
  // - Unflatten locales
14
- export const promise = async ({ id, collection, context, data, doc, docWithLocales, errors, field, global, mergeLocaleActions, operation, parentPath, parentSchemaPath, req, siblingData, siblingDoc, siblingDocWithLocales, skipValidation })=>{
14
+ export const promise = async ({ id, collection, context, data, doc, docWithLocales, errors, field, fieldIndex, global, mergeLocaleActions, operation, parentPath, parentSchemaPath, req, siblingData, siblingDoc, siblingDocWithLocales, skipValidation })=>{
15
15
  const passesCondition = field.admin?.condition ? Boolean(field.admin.condition(data, siblingData, {
16
16
  user: req.user
17
17
  })) : true;
@@ -19,11 +19,15 @@ export const promise = async ({ id, collection, context, data, doc, docWithLocal
19
19
  const { localization } = req.payload.config;
20
20
  const defaultLocale = localization ? localization?.defaultLocale : 'en';
21
21
  const operationLocale = req.locale || defaultLocale;
22
- const { path: fieldPath, schemaPath: fieldSchemaPath } = getFieldPaths({
22
+ const { path: _fieldPath, schemaPath: _fieldSchemaPath } = getFieldPaths({
23
23
  field,
24
- parentPath,
25
- parentSchemaPath
24
+ index: fieldIndex,
25
+ parentIndexPath: '',
26
+ parentPath: parentPath.join('.'),
27
+ parentSchemaPath: parentSchemaPath.join('.')
26
28
  });
29
+ const fieldPath = _fieldPath ? _fieldPath.split('.') : [];
30
+ const fieldSchemaPath = _fieldSchemaPath ? _fieldSchemaPath.split('.') : [];
27
31
  if (fieldAffectsData(field)) {
28
32
  // skip validation if the field is localized and the incoming data is null
29
33
  if (field.localized && operationLocale !== defaultLocale) {
@@ -87,26 +91,11 @@ export const promise = async ({ id, collection, context, data, doc, docWithLocal
87
91
  });
88
92
  if (typeof validationResult === 'string') {
89
93
  errors.push({
90
- field: fieldPath.join('.'),
91
- message: validationResult
94
+ message: validationResult,
95
+ path: fieldPath.join('.')
92
96
  });
93
97
  }
94
98
  }
95
- const beforeDuplicateArgs = {
96
- collection,
97
- context,
98
- data,
99
- field,
100
- global: undefined,
101
- path: fieldPath,
102
- previousSiblingDoc: siblingDoc,
103
- previousValue: siblingDoc[field.name],
104
- req,
105
- schemaPath: parentSchemaPath,
106
- siblingData,
107
- siblingDocWithLocales,
108
- value: siblingData[field.name]
109
- };
110
99
  // Push merge locale action if applicable
111
100
  if (localization && field.localized) {
112
101
  mergeLocaleActions.push(async ()=>{
@@ -131,53 +120,6 @@ export const promise = async ({ id, collection, context, data, doc, docWithLocal
131
120
  }
132
121
  }
133
122
  switch(field.type){
134
- case 'point':
135
- {
136
- // Transform point data for storage
137
- if (Array.isArray(siblingData[field.name]) && siblingData[field.name][0] !== null && siblingData[field.name][1] !== null) {
138
- siblingData[field.name] = {
139
- type: 'Point',
140
- coordinates: [
141
- parseFloat(siblingData[field.name][0]),
142
- parseFloat(siblingData[field.name][1])
143
- ]
144
- };
145
- }
146
- break;
147
- }
148
- case 'group':
149
- {
150
- if (typeof siblingData[field.name] !== 'object') {
151
- siblingData[field.name] = {};
152
- }
153
- if (typeof siblingDoc[field.name] !== 'object') {
154
- siblingDoc[field.name] = {};
155
- }
156
- if (typeof siblingDocWithLocales[field.name] !== 'object') {
157
- siblingDocWithLocales[field.name] = {};
158
- }
159
- await traverseFields({
160
- id,
161
- collection,
162
- context,
163
- data,
164
- doc,
165
- docWithLocales,
166
- errors,
167
- fields: field.fields,
168
- global,
169
- mergeLocaleActions,
170
- operation,
171
- path: fieldPath,
172
- req,
173
- schemaPath: fieldSchemaPath,
174
- siblingData: siblingData[field.name],
175
- siblingDoc: siblingDoc[field.name],
176
- siblingDocWithLocales: siblingDocWithLocales[field.name],
177
- skipValidation: skipValidationFromHere
178
- });
179
- break;
180
- }
181
123
  case 'array':
182
124
  {
183
125
  const rows = siblingData[field.name];
@@ -252,8 +194,8 @@ export const promise = async ({ id, collection, context, data, doc, docWithLocal
252
194
  }
253
195
  break;
254
196
  }
255
- case 'row':
256
197
  case 'collapsible':
198
+ case 'row':
257
199
  {
258
200
  await traverseFields({
259
201
  id,
@@ -277,6 +219,94 @@ export const promise = async ({ id, collection, context, data, doc, docWithLocal
277
219
  });
278
220
  break;
279
221
  }
222
+ case 'group':
223
+ {
224
+ if (typeof siblingData[field.name] !== 'object') {
225
+ siblingData[field.name] = {};
226
+ }
227
+ if (typeof siblingDoc[field.name] !== 'object') {
228
+ siblingDoc[field.name] = {};
229
+ }
230
+ if (typeof siblingDocWithLocales[field.name] !== 'object') {
231
+ siblingDocWithLocales[field.name] = {};
232
+ }
233
+ await traverseFields({
234
+ id,
235
+ collection,
236
+ context,
237
+ data,
238
+ doc,
239
+ docWithLocales,
240
+ errors,
241
+ fields: field.fields,
242
+ global,
243
+ mergeLocaleActions,
244
+ operation,
245
+ path: fieldPath,
246
+ req,
247
+ schemaPath: fieldSchemaPath,
248
+ siblingData: siblingData[field.name],
249
+ siblingDoc: siblingDoc[field.name],
250
+ siblingDocWithLocales: siblingDocWithLocales[field.name],
251
+ skipValidation: skipValidationFromHere
252
+ });
253
+ break;
254
+ }
255
+ case 'point':
256
+ {
257
+ // Transform point data for storage
258
+ if (Array.isArray(siblingData[field.name]) && siblingData[field.name][0] !== null && siblingData[field.name][1] !== null) {
259
+ siblingData[field.name] = {
260
+ type: 'Point',
261
+ coordinates: [
262
+ parseFloat(siblingData[field.name][0]),
263
+ parseFloat(siblingData[field.name][1])
264
+ ]
265
+ };
266
+ }
267
+ break;
268
+ }
269
+ case 'richText':
270
+ {
271
+ if (!field?.editor) {
272
+ 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
273
+ ;
274
+ }
275
+ if (typeof field?.editor === 'function') {
276
+ throw new Error('Attempted to access unsanitized rich text editor.');
277
+ }
278
+ const editor = field?.editor;
279
+ if (editor?.hooks?.beforeChange?.length) {
280
+ await editor.hooks.beforeChange.reduce(async (priorHook, currentHook)=>{
281
+ await priorHook;
282
+ const hookedValue = await currentHook({
283
+ collection,
284
+ context,
285
+ data,
286
+ docWithLocales,
287
+ errors,
288
+ field,
289
+ global,
290
+ mergeLocaleActions,
291
+ operation,
292
+ originalDoc: doc,
293
+ path: fieldPath,
294
+ previousSiblingDoc: siblingDoc,
295
+ previousValue: siblingDoc[field.name],
296
+ req,
297
+ schemaPath: parentSchemaPath,
298
+ siblingData,
299
+ siblingDocWithLocales,
300
+ skipValidation,
301
+ value: siblingData[field.name]
302
+ });
303
+ if (hookedValue !== undefined) {
304
+ siblingData[field.name] = hookedValue;
305
+ }
306
+ }, Promise.resolve());
307
+ }
308
+ break;
309
+ }
280
310
  case 'tab':
281
311
  {
282
312
  let tabSiblingData = siblingData;
@@ -345,47 +375,6 @@ export const promise = async ({ id, collection, context, data, doc, docWithLocal
345
375
  });
346
376
  break;
347
377
  }
348
- case 'richText':
349
- {
350
- if (!field?.editor) {
351
- 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
352
- ;
353
- }
354
- if (typeof field?.editor === 'function') {
355
- throw new Error('Attempted to access unsanitized rich text editor.');
356
- }
357
- const editor = field?.editor;
358
- if (editor?.hooks?.beforeChange?.length) {
359
- await editor.hooks.beforeChange.reduce(async (priorHook, currentHook)=>{
360
- await priorHook;
361
- const hookedValue = await currentHook({
362
- collection,
363
- context,
364
- data,
365
- docWithLocales,
366
- errors,
367
- field,
368
- global,
369
- mergeLocaleActions,
370
- operation,
371
- originalDoc: doc,
372
- path: fieldPath,
373
- previousSiblingDoc: siblingDoc,
374
- previousValue: siblingDoc[field.name],
375
- req,
376
- schemaPath: parentSchemaPath,
377
- siblingData,
378
- siblingDocWithLocales,
379
- skipValidation,
380
- value: siblingData[field.name]
381
- });
382
- if (hookedValue !== undefined) {
383
- siblingData[field.name] = hookedValue;
384
- }
385
- }, Promise.resolve());
386
- }
387
- break;
388
- }
389
378
  default:
390
379
  {
391
380
  break;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/fields/hooks/beforeChange/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, Operation, PayloadRequest } from '../../../types/index.js'\nimport type { Field, FieldHookArgs, TabAsField, ValidateOptions } from '../../config/types.js'\n\nimport { MissingEditorProp } from '../../../errors/index.js'\nimport { deepMergeWithSourceArrays } from '../../../utilities/deepMerge.js'\nimport { fieldAffectsData, tabHasName } from '../../config/types.js'\nimport { getFieldPaths } from '../../getFieldPaths.js'\nimport { getExistingRowDoc } from './getExistingRowDoc.js'\nimport { traverseFields } from './traverseFields.js'\n\ntype Args = {\n collection: null | SanitizedCollectionConfig\n context: RequestContext\n data: JsonObject\n doc: JsonObject\n docWithLocales: JsonObject\n errors: { field: string; message: string }[]\n field: Field | TabAsField\n global: null | SanitizedGlobalConfig\n id?: number | string\n mergeLocaleActions: (() => Promise<void>)[]\n operation: Operation\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 req: PayloadRequest\n siblingData: JsonObject\n siblingDoc: JsonObject\n siblingDocWithLocales?: JsonObject\n skipValidation: boolean\n}\n\n// This function is responsible for the following actions, in order:\n// - Run condition\n// - Execute field hooks\n// - Validate data\n// - Transform data for storage\n// - beforeDuplicate hooks (if duplicate)\n// - Unflatten locales\n\nexport const promise = async ({\n id,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n errors,\n field,\n global,\n mergeLocaleActions,\n operation,\n parentPath,\n parentSchemaPath,\n req,\n siblingData,\n siblingDoc,\n siblingDocWithLocales,\n skipValidation,\n}: Args): Promise<void> => {\n const passesCondition = field.admin?.condition\n ? Boolean(field.admin.condition(data, siblingData, { user: req.user }))\n : true\n let skipValidationFromHere = skipValidation || !passesCondition\n const { localization } = req.payload.config\n const defaultLocale = localization ? localization?.defaultLocale : 'en'\n const operationLocale = req.locale || defaultLocale\n\n const { path: fieldPath, schemaPath: fieldSchemaPath } = getFieldPaths({\n field,\n parentPath,\n parentSchemaPath,\n })\n\n if (fieldAffectsData(field)) {\n // skip validation if the field is localized and the incoming data is null\n if (field.localized && operationLocale !== defaultLocale) {\n if (['array', 'blocks'].includes(field.type) && siblingData[field.name] === null) {\n skipValidationFromHere = true\n }\n }\n\n // Execute hooks\n if (field.hooks?.beforeChange) {\n await field.hooks.beforeChange.reduce(async (priorHook, currentHook) => {\n await priorHook\n\n const hookedValue = await currentHook({\n collection,\n context,\n data,\n field,\n global,\n operation,\n originalDoc: doc,\n path: fieldPath,\n previousSiblingDoc: siblingDoc,\n previousValue: siblingDoc[field.name],\n req,\n schemaPath: parentSchemaPath,\n siblingData,\n siblingDocWithLocales,\n value: siblingData[field.name],\n })\n\n if (hookedValue !== undefined) {\n siblingData[field.name] = hookedValue\n }\n }, Promise.resolve())\n }\n\n // Validate\n if (!skipValidationFromHere && 'validate' in field && field.validate) {\n const valueToValidate = siblingData[field.name]\n let jsonError: object\n\n if (field.type === 'json' && typeof siblingData[field.name] === 'string') {\n try {\n JSON.parse(siblingData[field.name] as string)\n } catch (e) {\n jsonError = e\n }\n }\n\n const validationResult = await field.validate(\n valueToValidate as never,\n {\n ...field,\n id,\n collectionSlug: collection?.slug,\n data: deepMergeWithSourceArrays(doc, data),\n jsonError,\n operation,\n preferences: { fields: {} },\n previousValue: siblingDoc[field.name],\n req,\n siblingData: deepMergeWithSourceArrays(siblingDoc, siblingData),\n } as any,\n )\n\n if (typeof validationResult === 'string') {\n errors.push({\n field: fieldPath.join('.'),\n message: validationResult,\n })\n }\n }\n\n const beforeDuplicateArgs: FieldHookArgs = {\n collection,\n context,\n data,\n field,\n global: undefined,\n path: fieldPath,\n previousSiblingDoc: siblingDoc,\n previousValue: siblingDoc[field.name],\n req,\n schemaPath: parentSchemaPath,\n siblingData,\n siblingDocWithLocales,\n value: siblingData[field.name],\n }\n\n // Push merge locale action if applicable\n if (localization && field.localized) {\n mergeLocaleActions.push(async () => {\n const localeData = await localization.localeCodes.reduce(\n async (localizedValuesPromise: Promise<JsonObject>, locale) => {\n const localizedValues = await localizedValuesPromise\n const fieldValue =\n locale === req.locale\n ? siblingData[field.name]\n : siblingDocWithLocales?.[field.name]?.[locale]\n\n // const result = await localizedValues\n // update locale value if it's not undefined\n if (typeof fieldValue !== 'undefined') {\n return {\n ...localizedValues,\n [locale]: fieldValue,\n }\n }\n\n return localizedValuesPromise\n },\n Promise.resolve({}),\n )\n\n // If there are locales with data, set the data\n if (Object.keys(localeData).length > 0) {\n siblingData[field.name] = localeData\n }\n })\n }\n }\n\n switch (field.type) {\n case 'point': {\n // Transform point data for storage\n if (\n Array.isArray(siblingData[field.name]) &&\n siblingData[field.name][0] !== null &&\n siblingData[field.name][1] !== null\n ) {\n siblingData[field.name] = {\n type: 'Point',\n coordinates: [\n parseFloat(siblingData[field.name][0]),\n parseFloat(siblingData[field.name][1]),\n ],\n }\n }\n\n break\n }\n\n case 'group': {\n if (typeof siblingData[field.name] !== 'object') {\n siblingData[field.name] = {}\n }\n if (typeof siblingDoc[field.name] !== 'object') {\n siblingDoc[field.name] = {}\n }\n if (typeof siblingDocWithLocales[field.name] !== 'object') {\n siblingDocWithLocales[field.name] = {}\n }\n\n await traverseFields({\n id,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n errors,\n fields: field.fields,\n global,\n mergeLocaleActions,\n operation,\n path: fieldPath,\n req,\n schemaPath: fieldSchemaPath,\n siblingData: siblingData[field.name] as JsonObject,\n siblingDoc: siblingDoc[field.name] as JsonObject,\n siblingDocWithLocales: siblingDocWithLocales[field.name] as JsonObject,\n skipValidation: skipValidationFromHere,\n })\n\n break\n }\n\n case 'array': {\n const rows = siblingData[field.name]\n\n if (Array.isArray(rows)) {\n const promises = []\n rows.forEach((row, i) => {\n promises.push(\n traverseFields({\n id,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n errors,\n fields: field.fields,\n global,\n mergeLocaleActions,\n operation,\n path: [...fieldPath, i],\n req,\n schemaPath: fieldSchemaPath,\n siblingData: row as JsonObject,\n siblingDoc: getExistingRowDoc(row as JsonObject, siblingDoc[field.name]),\n siblingDocWithLocales: getExistingRowDoc(\n row as JsonObject,\n siblingDocWithLocales[field.name],\n ),\n skipValidation: skipValidationFromHere,\n }),\n )\n })\n\n await Promise.all(promises)\n }\n\n break\n }\n\n case 'blocks': {\n const rows = siblingData[field.name]\n if (Array.isArray(rows)) {\n const promises = []\n rows.forEach((row, i) => {\n const rowSiblingDoc = getExistingRowDoc(row as JsonObject, siblingDoc[field.name])\n const rowSiblingDocWithLocales = getExistingRowDoc(\n row as JsonObject,\n siblingDocWithLocales ? siblingDocWithLocales[field.name] : {},\n )\n\n const blockTypeToMatch = (row as JsonObject).blockType || rowSiblingDoc.blockType\n const block = field.blocks.find((blockType) => blockType.slug === blockTypeToMatch)\n\n if (block) {\n promises.push(\n traverseFields({\n id,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n errors,\n fields: block.fields,\n global,\n mergeLocaleActions,\n operation,\n path: [...fieldPath, i],\n req,\n schemaPath: fieldSchemaPath,\n siblingData: row as JsonObject,\n siblingDoc: rowSiblingDoc,\n siblingDocWithLocales: rowSiblingDocWithLocales,\n skipValidation: skipValidationFromHere,\n }),\n )\n }\n })\n\n await Promise.all(promises)\n }\n\n break\n }\n\n case 'row':\n case 'collapsible': {\n await traverseFields({\n id,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n errors,\n fields: field.fields,\n global,\n mergeLocaleActions,\n operation,\n path: fieldPath,\n req,\n schemaPath: fieldSchemaPath,\n siblingData,\n siblingDoc,\n siblingDocWithLocales,\n skipValidation: skipValidationFromHere,\n })\n\n break\n }\n\n case 'tab': {\n let tabSiblingData = siblingData\n let tabSiblingDoc = siblingDoc\n let tabSiblingDocWithLocales = siblingDocWithLocales\n\n if (tabHasName(field)) {\n if (typeof siblingData[field.name] !== 'object') {\n siblingData[field.name] = {}\n }\n if (typeof siblingDoc[field.name] !== 'object') {\n siblingDoc[field.name] = {}\n }\n if (typeof siblingDocWithLocales[field.name] !== 'object') {\n siblingDocWithLocales[field.name] = {}\n }\n\n tabSiblingData = siblingData[field.name] as JsonObject\n tabSiblingDoc = siblingDoc[field.name] as JsonObject\n tabSiblingDocWithLocales = siblingDocWithLocales[field.name] as JsonObject\n }\n\n await traverseFields({\n id,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n errors,\n fields: field.fields,\n global,\n mergeLocaleActions,\n operation,\n path: fieldPath,\n req,\n schemaPath: fieldSchemaPath,\n siblingData: tabSiblingData,\n siblingDoc: tabSiblingDoc,\n siblingDocWithLocales: tabSiblingDocWithLocales,\n skipValidation: skipValidationFromHere,\n })\n\n break\n }\n\n case 'tabs': {\n await traverseFields({\n id,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n errors,\n fields: field.tabs.map((tab) => ({ ...tab, type: 'tab' })),\n global,\n mergeLocaleActions,\n operation,\n path: fieldPath,\n req,\n schemaPath: fieldSchemaPath,\n siblingData,\n siblingDoc,\n siblingDocWithLocales,\n skipValidation: skipValidationFromHere,\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 const editor: RichTextAdapter = field?.editor\n\n if (editor?.hooks?.beforeChange?.length) {\n await editor.hooks.beforeChange.reduce(async (priorHook, currentHook) => {\n await priorHook\n\n const hookedValue = await currentHook({\n collection,\n context,\n data,\n docWithLocales,\n errors,\n field,\n global,\n mergeLocaleActions,\n operation,\n originalDoc: doc,\n path: fieldPath,\n previousSiblingDoc: siblingDoc,\n previousValue: siblingDoc[field.name],\n req,\n schemaPath: parentSchemaPath,\n siblingData,\n siblingDocWithLocales,\n skipValidation,\n value: siblingData[field.name],\n })\n\n if (hookedValue !== undefined) {\n siblingData[field.name] = hookedValue\n }\n }, Promise.resolve())\n }\n\n break\n }\n\n default: {\n break\n }\n }\n}\n"],"names":["MissingEditorProp","deepMergeWithSourceArrays","fieldAffectsData","tabHasName","getFieldPaths","getExistingRowDoc","traverseFields","promise","id","collection","context","data","doc","docWithLocales","errors","field","global","mergeLocaleActions","operation","parentPath","parentSchemaPath","req","siblingData","siblingDoc","siblingDocWithLocales","skipValidation","passesCondition","admin","condition","Boolean","user","skipValidationFromHere","localization","payload","config","defaultLocale","operationLocale","locale","path","fieldPath","schemaPath","fieldSchemaPath","localized","includes","type","name","hooks","beforeChange","reduce","priorHook","currentHook","hookedValue","originalDoc","previousSiblingDoc","previousValue","value","undefined","Promise","resolve","validate","valueToValidate","jsonError","JSON","parse","e","validationResult","collectionSlug","slug","preferences","fields","push","join","message","beforeDuplicateArgs","localeData","localeCodes","localizedValuesPromise","localizedValues","fieldValue","Object","keys","length","Array","isArray","coordinates","parseFloat","rows","promises","forEach","row","i","all","rowSiblingDoc","rowSiblingDocWithLocales","blockTypeToMatch","blockType","block","blocks","find","tabSiblingData","tabSiblingDoc","tabSiblingDocWithLocales","tabs","map","tab","editor","Error"],"mappings":"AAOA,SAASA,iBAAiB,QAAQ,2BAA0B;AAC5D,SAASC,yBAAyB,QAAQ,kCAAiC;AAC3E,SAASC,gBAAgB,EAAEC,UAAU,QAAQ,wBAAuB;AACpE,SAASC,aAAa,QAAQ,yBAAwB;AACtD,SAASC,iBAAiB,QAAQ,yBAAwB;AAC1D,SAASC,cAAc,QAAQ,sBAAqB;AA6BpD,oEAAoE;AACpE,kBAAkB;AAClB,wBAAwB;AACxB,kBAAkB;AAClB,+BAA+B;AAC/B,yCAAyC;AACzC,sBAAsB;AAEtB,OAAO,MAAMC,UAAU,OAAO,EAC5BC,EAAE,EACFC,UAAU,EACVC,OAAO,EACPC,IAAI,EACJC,GAAG,EACHC,cAAc,EACdC,MAAM,EACNC,KAAK,EACLC,MAAM,EACNC,kBAAkB,EAClBC,SAAS,EACTC,UAAU,EACVC,gBAAgB,EAChBC,GAAG,EACHC,WAAW,EACXC,UAAU,EACVC,qBAAqB,EACrBC,cAAc,EACT;IACL,MAAMC,kBAAkBX,MAAMY,KAAK,EAAEC,YACjCC,QAAQd,MAAMY,KAAK,CAACC,SAAS,CAACjB,MAAMW,aAAa;QAAEQ,MAAMT,IAAIS,IAAI;IAAC,MAClE;IACJ,IAAIC,yBAAyBN,kBAAkB,CAACC;IAChD,MAAM,EAAEM,YAAY,EAAE,GAAGX,IAAIY,OAAO,CAACC,MAAM;IA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AEN,MAAME,cAAc,MAAMD,YAAY;4BACpCzC;4BACAC;4BACAC;4BACAE;4BACAC;4BACAC;4BACAC;4BACAC;4BACAC;4BACAkC,aAAaxC;4BACb0B,MAAMC;4BACNc,oBAAoB9B;4BACpB+B,eAAe/B,UAAU,CAACR,MAAM8B,IAAI,CAAC;4BACrCxB;4BACAmB,YAAYpB;4BACZE;4BACAE;4BACAC;4BACA8B,OAAOjC,WAAW,CAACP,MAAM8B,IAAI,CAAC;wBAChC;wBAEA,IAAIM,gBAAgBK,WAAW;4BAC7BlC,WAAW,CAACP,MAAM8B,IAAI,CAAC,GAAGM;wBAC5B;oBACF,GAAGM,QAAQC,OAAO;gBACpB;gBAEA;YACF;QAEA;YAAS;gBACP;YACF;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../../src/fields/hooks/beforeChange/promise.ts"],"sourcesContent":["import type { RichTextAdapter } from '../../../admin/RichText.js'\nimport type { SanitizedCollectionConfig } from '../../../collections/config/types.js'\nimport type { ValidationFieldError } from '../../../errors/index.js'\nimport type { SanitizedGlobalConfig } from '../../../globals/config/types.js'\nimport type { RequestContext } from '../../../index.js'\nimport type { JsonObject, Operation, PayloadRequest } from '../../../types/index.js'\nimport type { Field, TabAsField } from '../../config/types.js'\n\nimport { MissingEditorProp } from '../../../errors/index.js'\nimport { deepMergeWithSourceArrays } from '../../../utilities/deepMerge.js'\nimport { fieldAffectsData, tabHasName } from '../../config/types.js'\nimport { getFieldPaths } from '../../getFieldPaths.js'\nimport { getExistingRowDoc } from './getExistingRowDoc.js'\nimport { traverseFields } from './traverseFields.js'\n\ntype Args = {\n collection: null | SanitizedCollectionConfig\n context: RequestContext\n data: JsonObject\n doc: JsonObject\n docWithLocales: JsonObject\n errors: ValidationFieldError[]\n field: Field | TabAsField\n /**\n * The index of the field as it appears in the parent's fields array. This is used to construct the field path / schemaPath\n * for unnamed fields like rows and collapsibles.\n */\n fieldIndex: number\n global: null | SanitizedGlobalConfig\n id?: number | string\n mergeLocaleActions: (() => Promise<void>)[]\n operation: Operation\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 req: PayloadRequest\n siblingData: JsonObject\n siblingDoc: JsonObject\n siblingDocWithLocales?: JsonObject\n skipValidation: boolean\n}\n\n// This function is responsible for the following actions, in order:\n// - Run condition\n// - Execute field hooks\n// - Validate data\n// - Transform data for storage\n// - beforeDuplicate hooks (if duplicate)\n// - Unflatten locales\n\nexport const promise = async ({\n id,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n errors,\n field,\n fieldIndex,\n global,\n mergeLocaleActions,\n operation,\n parentPath,\n parentSchemaPath,\n req,\n siblingData,\n siblingDoc,\n siblingDocWithLocales,\n skipValidation,\n}: Args): Promise<void> => {\n const passesCondition = field.admin?.condition\n ? Boolean(field.admin.condition(data, siblingData, { user: req.user }))\n : true\n let skipValidationFromHere = skipValidation || !passesCondition\n const { localization } = req.payload.config\n const defaultLocale = localization ? localization?.defaultLocale : 'en'\n const operationLocale = req.locale || defaultLocale\n\n const { path: _fieldPath, schemaPath: _fieldSchemaPath } = getFieldPaths({\n field,\n index: fieldIndex,\n parentIndexPath: '', // Doesn't matter, as unnamed fields do not affect data, and hooks are only run on fields that affect data\n parentPath: parentPath.join('.'),\n parentSchemaPath: parentSchemaPath.join('.'),\n })\n const fieldPath = _fieldPath ? _fieldPath.split('.') : []\n const fieldSchemaPath = _fieldSchemaPath ? _fieldSchemaPath.split('.') : []\n\n if (fieldAffectsData(field)) {\n // skip validation if the field is localized and the incoming data is null\n if (field.localized && operationLocale !== defaultLocale) {\n if (['array', 'blocks'].includes(field.type) && siblingData[field.name] === null) {\n skipValidationFromHere = true\n }\n }\n\n // Execute hooks\n if (field.hooks?.beforeChange) {\n await field.hooks.beforeChange.reduce(async (priorHook, currentHook) => {\n await priorHook\n\n const hookedValue = await currentHook({\n collection,\n context,\n data,\n field,\n global,\n operation,\n originalDoc: doc,\n path: fieldPath,\n previousSiblingDoc: siblingDoc,\n previousValue: siblingDoc[field.name],\n req,\n schemaPath: parentSchemaPath,\n siblingData,\n siblingDocWithLocales,\n value: siblingData[field.name],\n })\n\n if (hookedValue !== undefined) {\n siblingData[field.name] = hookedValue\n }\n }, Promise.resolve())\n }\n\n // Validate\n if (!skipValidationFromHere && 'validate' in field && field.validate) {\n const valueToValidate = siblingData[field.name]\n let jsonError: object\n\n if (field.type === 'json' && typeof siblingData[field.name] === 'string') {\n try {\n JSON.parse(siblingData[field.name] as string)\n } catch (e) {\n jsonError = e\n }\n }\n\n const validationResult = await field.validate(\n valueToValidate as never,\n {\n ...field,\n id,\n collectionSlug: collection?.slug,\n data: deepMergeWithSourceArrays(doc, data),\n jsonError,\n operation,\n preferences: { fields: {} },\n previousValue: siblingDoc[field.name],\n req,\n siblingData: deepMergeWithSourceArrays(siblingDoc, siblingData),\n } as any,\n )\n\n if (typeof validationResult === 'string') {\n errors.push({\n message: validationResult,\n path: fieldPath.join('.'),\n })\n }\n }\n\n // Push merge locale action if applicable\n if (localization && field.localized) {\n mergeLocaleActions.push(async () => {\n const localeData = await localization.localeCodes.reduce(\n async (localizedValuesPromise: Promise<JsonObject>, locale) => {\n const localizedValues = await localizedValuesPromise\n const fieldValue =\n locale === req.locale\n ? siblingData[field.name]\n : siblingDocWithLocales?.[field.name]?.[locale]\n\n // const result = await localizedValues\n // update locale value if it's not undefined\n if (typeof fieldValue !== 'undefined') {\n return {\n ...localizedValues,\n [locale]: fieldValue,\n }\n }\n\n return localizedValuesPromise\n },\n Promise.resolve({}),\n )\n\n // If there are locales with data, set the data\n if (Object.keys(localeData).length > 0) {\n siblingData[field.name] = localeData\n }\n })\n }\n }\n\n switch (field.type) {\n case 'array': {\n const rows = siblingData[field.name]\n\n if (Array.isArray(rows)) {\n const promises = []\n rows.forEach((row, i) => {\n promises.push(\n traverseFields({\n id,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n errors,\n fields: field.fields,\n global,\n mergeLocaleActions,\n operation,\n path: [...fieldPath, i],\n req,\n schemaPath: fieldSchemaPath,\n siblingData: row as JsonObject,\n siblingDoc: getExistingRowDoc(row as JsonObject, siblingDoc[field.name]),\n siblingDocWithLocales: getExistingRowDoc(\n row as JsonObject,\n siblingDocWithLocales[field.name],\n ),\n skipValidation: skipValidationFromHere,\n }),\n )\n })\n\n await Promise.all(promises)\n }\n\n break\n }\n\n case 'blocks': {\n const rows = siblingData[field.name]\n if (Array.isArray(rows)) {\n const promises = []\n rows.forEach((row, i) => {\n const rowSiblingDoc = getExistingRowDoc(row as JsonObject, siblingDoc[field.name])\n const rowSiblingDocWithLocales = getExistingRowDoc(\n row as JsonObject,\n siblingDocWithLocales ? siblingDocWithLocales[field.name] : {},\n )\n\n const blockTypeToMatch = (row as JsonObject).blockType || rowSiblingDoc.blockType\n const block = field.blocks.find((blockType) => blockType.slug === blockTypeToMatch)\n\n if (block) {\n promises.push(\n traverseFields({\n id,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n errors,\n fields: block.fields,\n global,\n mergeLocaleActions,\n operation,\n path: [...fieldPath, i],\n req,\n schemaPath: fieldSchemaPath,\n siblingData: row as JsonObject,\n siblingDoc: rowSiblingDoc,\n siblingDocWithLocales: rowSiblingDocWithLocales,\n skipValidation: skipValidationFromHere,\n }),\n )\n }\n })\n\n await Promise.all(promises)\n }\n\n break\n }\n\n case 'collapsible':\n\n case 'row': {\n await traverseFields({\n id,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n errors,\n fields: field.fields,\n global,\n mergeLocaleActions,\n operation,\n path: fieldPath,\n req,\n schemaPath: fieldSchemaPath,\n siblingData,\n siblingDoc,\n siblingDocWithLocales,\n skipValidation: skipValidationFromHere,\n })\n\n break\n }\n\n case 'group': {\n if (typeof siblingData[field.name] !== 'object') {\n siblingData[field.name] = {}\n }\n if (typeof siblingDoc[field.name] !== 'object') {\n siblingDoc[field.name] = {}\n }\n if (typeof siblingDocWithLocales[field.name] !== 'object') {\n siblingDocWithLocales[field.name] = {}\n }\n\n await traverseFields({\n id,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n errors,\n fields: field.fields,\n global,\n mergeLocaleActions,\n operation,\n path: fieldPath,\n req,\n schemaPath: fieldSchemaPath,\n siblingData: siblingData[field.name] as JsonObject,\n siblingDoc: siblingDoc[field.name] as JsonObject,\n siblingDocWithLocales: siblingDocWithLocales[field.name] as JsonObject,\n skipValidation: skipValidationFromHere,\n })\n\n break\n }\n case 'point': {\n // Transform point data for storage\n if (\n Array.isArray(siblingData[field.name]) &&\n siblingData[field.name][0] !== null &&\n siblingData[field.name][1] !== null\n ) {\n siblingData[field.name] = {\n type: 'Point',\n coordinates: [\n parseFloat(siblingData[field.name][0]),\n parseFloat(siblingData[field.name][1]),\n ],\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 const editor: RichTextAdapter = field?.editor\n\n if (editor?.hooks?.beforeChange?.length) {\n await editor.hooks.beforeChange.reduce(async (priorHook, currentHook) => {\n await priorHook\n\n const hookedValue = await currentHook({\n collection,\n context,\n data,\n docWithLocales,\n errors,\n field,\n global,\n mergeLocaleActions,\n operation,\n originalDoc: doc,\n path: fieldPath,\n previousSiblingDoc: siblingDoc,\n previousValue: siblingDoc[field.name],\n req,\n schemaPath: parentSchemaPath,\n siblingData,\n siblingDocWithLocales,\n skipValidation,\n value: siblingData[field.name],\n })\n\n if (hookedValue !== undefined) {\n siblingData[field.name] = hookedValue\n }\n }, Promise.resolve())\n }\n\n break\n }\n\n case 'tab': {\n let tabSiblingData = siblingData\n let tabSiblingDoc = siblingDoc\n let tabSiblingDocWithLocales = siblingDocWithLocales\n\n if (tabHasName(field)) {\n if (typeof siblingData[field.name] !== 'object') {\n siblingData[field.name] = {}\n }\n if (typeof siblingDoc[field.name] !== 'object') {\n siblingDoc[field.name] = {}\n }\n if (typeof siblingDocWithLocales[field.name] !== 'object') {\n siblingDocWithLocales[field.name] = {}\n }\n\n tabSiblingData = siblingData[field.name] as JsonObject\n tabSiblingDoc = siblingDoc[field.name] as JsonObject\n tabSiblingDocWithLocales = siblingDocWithLocales[field.name] as JsonObject\n }\n\n await traverseFields({\n id,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n errors,\n fields: field.fields,\n global,\n mergeLocaleActions,\n operation,\n path: fieldPath,\n req,\n schemaPath: fieldSchemaPath,\n siblingData: tabSiblingData,\n siblingDoc: tabSiblingDoc,\n siblingDocWithLocales: tabSiblingDocWithLocales,\n skipValidation: skipValidationFromHere,\n })\n\n break\n }\n\n case 'tabs': {\n await traverseFields({\n id,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n errors,\n fields: field.tabs.map((tab) => ({ ...tab, type: 'tab' })),\n global,\n mergeLocaleActions,\n operation,\n path: fieldPath,\n req,\n schemaPath: fieldSchemaPath,\n siblingData,\n siblingDoc,\n siblingDocWithLocales,\n skipValidation: skipValidationFromHere,\n })\n\n break\n }\n\n default: {\n break\n }\n }\n}\n"],"names":["MissingEditorProp","deepMergeWithSourceArrays","fieldAffectsData","tabHasName","getFieldPaths","getExistingRowDoc","traverseFields","promise","id","collection","context","data","doc","docWithLocales","errors","field","fieldIndex","global","mergeLocaleActions","operation","parentPath","parentSchemaPath","req","siblingData","siblingDoc","siblingDocWithLocales","skipValidation","passesCondition","admin","condition","Boolean","user","skipValidationFromHere","localization","payload","config","defaultLocale","operationLocale","locale","path","_fieldPath","schemaPath","_fieldSchemaPath","index","parentIndexPath","join","fieldPath","split","fieldSchemaPath","localized","includes","type","name","hooks","beforeChange","reduce","priorHook","currentHook","hookedValue","originalDoc","previousSiblingDoc","previousValue","value","undefined","Promise","resolve","validate","valueToValidate","jsonError","JSON","parse","e","validationResult","collectionSlug","slug","preferences","fields","push","message","localeData","localeCodes","localizedValuesPromise","localizedValues","fieldValue","Object","keys","length","rows","Array","isArray","promises","forEach","row","i","all","rowSiblingDoc","rowSiblingDocWithLocales","blockTypeToMatch","blockType","block","blocks","find","coordinates","parseFloat","editor","Error","tabSiblingData","tabSiblingDoc","tabSiblingDocWithLocales","tabs","map","tab"],"mappings":"AAQA,SAASA,iBAAiB,QAAQ,2BAA0B;AAC5D,SAASC,yBAAyB,QAAQ,kCAAiC;AAC3E,SAASC,gBAAgB,EAAEC,UAAU,QAAQ,wBAAuB;AACpE,SAASC,aAAa,QAAQ,yBAAwB;AACtD,SAASC,iBAAiB,QAAQ,yBAAwB;AAC1D,SAASC,cAAc,QAAQ,sBAAqB;AAkCpD,oEAAoE;AACpE,kBAAkB;AAClB,wBAAwB;AACxB,kBAAkB;AAClB,+BAA+B;AAC/B,yCAAyC;AACzC,sBAAsB;AAEtB,OAAO,MAAMC,UAAU,OAAO,EAC5BC,EAAE,EACFC,UAAU,EACVC,OAAO,EACPC,IAAI,EACJC,GAAG,EACHC,cAAc,EACdC,MAAM,EACNC,KAAK,EACLC,UAAU,EACVC,MAAM,EACNC,kBAAkB,EAClBC,SAAS,EACTC,UAAU,EACVC,gBAAgB,EAChBC,GAAG,EACHC,WAAW,EACXC,UAAU,EACVC,qBAAqB,EACrBC,cAAc,EACT;IACL,MAAMC,kBAAkBZ,MAAMa,KAAK,EAAEC,YACjCC,QAAQf,MAAMa,KAAK,CAACC,SAAS,CAAClB,MAAMY,aAAa;QAAEQ,MAAMT,IAAIS,IAAI;IAAC,MAClE;IACJ,IAAIC,yBAAyBN,kBAAkB,CAACC;IAChD,MAAM,EAAEM,YAAY,EAAE,GAAGX,IAAIY,OAAO,CAACC,MAAM;IAC3C,MAAMC,gBAAgBH,eAAeA,cAAcG,gBAAgB;IACnE,MAAMC,kBAAkBf,IAAIgB,MAAM,IAAIF;IAEtC,MAAM,EAAEG,MAAMC,UAAU,EAAEC,YAAYC,gBAAgB,EAAE,GAAGtC,cAAc;QACvEW;QACA4B,OAAO3B;QACP4B,iBAAiB;QACjBx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F,IAAI,CAACC,GAAG,CAAC,CAACC,MAAS,CAAA;4BAAE,GAAGA,GAAG;4BAAE5D,MAAM;wBAAM,CAAA;oBACvDlC;oBACAC;oBACAC;oBACAoB,MAAMO;oBACNxB;oBACAmB,YAAYO;oBACZzB;oBACAC;oBACAC;oBACAC,gBAAgBM;gBAClB;gBAEA;YACF;QAEA;YAAS;gBACP;YACF;IACF;AACF,EAAC"}
@@ -1,4 +1,5 @@
1
1
  import type { SanitizedCollectionConfig } from '../../../collections/config/types.js';
2
+ import type { ValidationFieldError } from '../../../errors/index.js';
2
3
  import type { SanitizedGlobalConfig } from '../../../globals/config/types.js';
3
4
  import type { RequestContext } from '../../../index.js';
4
5
  import type { JsonObject, Operation, PayloadRequest } from '../../../types/index.js';
@@ -15,10 +16,7 @@ type Args = {
15
16
  * The original data with locales (not modified by any hooks)
16
17
  */
17
18
  docWithLocales: JsonObject;
18
- errors: {
19
- field: string;
20
- message: string;
21
- }[];
19
+ errors: ValidationFieldError[];
22
20
  fields: (Field | TabAsField)[];
23
21
  global: null | SanitizedGlobalConfig;
24
22
  id?: number | string;
@@ -1 +1 @@
1
- {"version":3,"file":"traverseFields.d.ts","sourceRoot":"","sources":["../../../../src/fields/hooks/beforeChange/traverseFields.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,SAAS,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AACpF,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAI9D,KAAK,IAAI,GAAG;IACV,UAAU,EAAE,IAAI,GAAG,yBAAyB,CAAA;IAC5C,OAAO,EAAE,cAAc,CAAA;IACvB,IAAI,EA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E,MAAM,yBAAyB,CAAA;AACpF,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAI9D,KAAK,IAAI,GAAG;IACV,UAAU,EAAE,IAAI,GAAG,yBAAyB,CAAA;IAC5C,OAAO,EAAE,cAAc,CAAA;IACvB,IAAI,EAAE,UAAU,CAAA;IAChB;;OAEG;IACH,GAAG,EAAE,UAAU,CAAA;IACf;;OAEG;IACH,cAAc,EAAE,UAAU,CAAA;IAC1B,MAAM,EAAE,oBAAoB,EAAE,CAAA;IAC9B,MAAM,EAAE,CAAC,KAAK,GAAG,UAAU,CAAC,EAAE,CAAA;IAC9B,MAAM,EAAE,IAAI,GAAG,qBAAqB,CAAA;IACpC,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACpB,kBAAkB,EAAE,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,CAAA;IAC3C,SAAS,EAAE,SAAS,CAAA;IACpB,IAAI,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAA;IACzB,GAAG,EAAE,cAAc,CAAA;IACnB,UAAU,EAAE,MAAM,EAAE,CAAA;IACpB,WAAW,EAAE,UAAU,CAAA;IACvB;;OAEG;IACH,UAAU,EAAE,UAAU,CAAA;IACtB;;OAEG;IACH,qBAAqB,EAAE,UAAU,CAAA;IACjC,cAAc,CAAC,EAAE,OAAO,CAAA;CACzB,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,0MAmBxB,IAAI,KAAG,OAAO,CAAC,IAAI,CA8BrB,CAAA"}
@@ -8,7 +8,7 @@ import { promise } from './promise.js';
8
8
  * - Unflatten locales. The input `data` is the normal document for one locale. The output result will become the document with locales.
9
9
  */ export const traverseFields = async ({ id, collection, context, data, doc, docWithLocales, errors, fields, global, mergeLocaleActions, operation, path, req, schemaPath, siblingData, siblingDoc, siblingDocWithLocales, skipValidation })=>{
10
10
  const promises = [];
11
- fields.forEach((field)=>{
11
+ fields.forEach((field, fieldIndex)=>{
12
12
  promises.push(promise({
13
13
  id,
14
14
  collection,
@@ -18,6 +18,7 @@ import { promise } from './promise.js';
18
18
  docWithLocales,
19
19
  errors,
20
20
  field,
21
+ fieldIndex,
21
22
  global,
22
23
  mergeLocaleActions,
23
24
  operation,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/fields/hooks/beforeChange/traverseFields.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, Operation, PayloadRequest } from '../../../types/index.js'\nimport type { Field, TabAsField } from '../../config/types.js'\n\nimport { promise } from './promise.js'\n\ntype Args = {\n collection: null | SanitizedCollectionConfig\n context: RequestContext\n data: JsonObject\n /**\n * The original data (not modified by any hooks)\n */\n doc: JsonObject\n /**\n * The original data with locales (not modified by any hooks)\n */\n docWithLocales: JsonObject\n errors: { field: string; message: string }[]\n fields: (Field | TabAsField)[]\n global: null | SanitizedGlobalConfig\n id?: number | string\n mergeLocaleActions: (() => Promise<void>)[]\n operation: Operation\n path: (number | string)[]\n req: PayloadRequest\n schemaPath: string[]\n siblingData: JsonObject\n /**\n * The original siblingData (not modified by any hooks)\n */\n siblingDoc: JsonObject\n /**\n * The original siblingData with locales (not modified by any hooks)\n */\n siblingDocWithLocales: JsonObject\n skipValidation?: boolean\n}\n\n/**\n * This function is responsible for the following actions, in order:\n * - Run condition\n * - Execute field hooks\n * - Validate data\n * - Transform data for storage\n * - Unflatten locales. The input `data` is the normal document for one locale. The output result will become the document with locales.\n */\nexport const traverseFields = async ({\n id,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n errors,\n fields,\n global,\n mergeLocaleActions,\n operation,\n path,\n req,\n schemaPath,\n siblingData,\n siblingDoc,\n siblingDocWithLocales,\n skipValidation,\n}: Args): Promise<void> => {\n const promises = []\n\n fields.forEach((field) => {\n promises.push(\n promise({\n id,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n errors,\n field,\n global,\n mergeLocaleActions,\n operation,\n parentPath: path,\n parentSchemaPath: schemaPath,\n req,\n siblingData,\n siblingDoc,\n siblingDocWithLocales,\n skipValidation,\n }),\n )\n })\n\n await Promise.all(promises)\n}\n"],"names":["promise","traverseFields","id","collection","context","data","doc","docWithLocales","errors","fields","global","mergeLocaleActions","operation","path","req","schemaPath","siblingData","siblingDoc","siblingDocWithLocales","skipValidation","promises","forEach","field","push","parentPath","parentSchemaPath","Promise","all"],"mappings":"AAMA,SAASA,OAAO,QAAQ,eAAc;AAmCtC;;;;;;;CAOC,GACD,OAAO,MAAMC,iBAAiB,OAAO,EACnCC,EAAE,EACFC,UAAU,EACVC,OAAO,EACPC,IAAI,EACJC,GAAG,EACHC,cAAc,EACdC,MAAM,EACNC,MAAM,EACNC,MAAM,EACNC,kBAAkB,EAClBC,SAAS,EACTC,IAAI,EACJC,GAAG,EACHC,UAAU,EACVC,WAAW,EACXC,UAAU,EACVC,qBAAqB,EACrBC,cAAc,EACT;IACL,MAAMC,WAAW,EAAE;IAEnBX,OAAOY,OAAO,CAAC,CAACC;QACdF,SAASG,IAAI,CACXvB,QAAQ;YACNE;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAc;YACAZ;YACAC;YACAC;YACAY,YAAYX;YACZY,kBAAkBV;YAClBD;YACAE;YACAC;YACAC;YACAC;QACF;IAEJ;IAEA,MAAMO,QAAQC,GAAG,CAACP;AACpB,EAAC"}
1
+ {"version":3,"sources":["../../../../src/fields/hooks/beforeChange/traverseFields.ts"],"sourcesContent":["import type { SanitizedCollectionConfig } from '../../../collections/config/types.js'\nimport type { ValidationFieldError } from '../../../errors/index.js'\nimport type { SanitizedGlobalConfig } from '../../../globals/config/types.js'\nimport type { RequestContext } from '../../../index.js'\nimport type { JsonObject, Operation, PayloadRequest } from '../../../types/index.js'\nimport type { Field, TabAsField } from '../../config/types.js'\n\nimport { promise } from './promise.js'\n\ntype Args = {\n collection: null | SanitizedCollectionConfig\n context: RequestContext\n data: JsonObject\n /**\n * The original data (not modified by any hooks)\n */\n doc: JsonObject\n /**\n * The original data with locales (not modified by any hooks)\n */\n docWithLocales: JsonObject\n errors: ValidationFieldError[]\n fields: (Field | TabAsField)[]\n global: null | SanitizedGlobalConfig\n id?: number | string\n mergeLocaleActions: (() => Promise<void>)[]\n operation: Operation\n path: (number | string)[]\n req: PayloadRequest\n schemaPath: string[]\n siblingData: JsonObject\n /**\n * The original siblingData (not modified by any hooks)\n */\n siblingDoc: JsonObject\n /**\n * The original siblingData with locales (not modified by any hooks)\n */\n siblingDocWithLocales: JsonObject\n skipValidation?: boolean\n}\n\n/**\n * This function is responsible for the following actions, in order:\n * - Run condition\n * - Execute field hooks\n * - Validate data\n * - Transform data for storage\n * - Unflatten locales. The input `data` is the normal document for one locale. The output result will become the document with locales.\n */\nexport const traverseFields = async ({\n id,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n errors,\n fields,\n global,\n mergeLocaleActions,\n operation,\n path,\n req,\n schemaPath,\n siblingData,\n siblingDoc,\n siblingDocWithLocales,\n skipValidation,\n}: Args): Promise<void> => {\n const promises = []\n\n fields.forEach((field, fieldIndex) => {\n promises.push(\n promise({\n id,\n collection,\n context,\n data,\n doc,\n docWithLocales,\n errors,\n field,\n fieldIndex,\n global,\n mergeLocaleActions,\n operation,\n parentPath: path,\n parentSchemaPath: schemaPath,\n req,\n siblingData,\n siblingDoc,\n siblingDocWithLocales,\n skipValidation,\n }),\n )\n })\n\n await Promise.all(promises)\n}\n"],"names":["promise","traverseFields","id","collection","context","data","doc","docWithLocales","errors","fields","global","mergeLocaleActions","operation","path","req","schemaPath","siblingData","siblingDoc","siblingDocWithLocales","skipValidation","promises","forEach","field","fieldIndex","push","parentPath","parentSchemaPath","Promise","all"],"mappings":"AAOA,SAASA,OAAO,QAAQ,eAAc;AAmCtC;;;;;;;CAOC,GACD,OAAO,MAAMC,iBAAiB,OAAO,EACnCC,EAAE,EACFC,UAAU,EACVC,OAAO,EACPC,IAAI,EACJC,GAAG,EACHC,cAAc,EACdC,MAAM,EACNC,MAAM,EACNC,MAAM,EACNC,kBAAkB,EAClBC,SAAS,EACTC,IAAI,EACJC,GAAG,EACHC,UAAU,EACVC,WAAW,EACXC,UAAU,EACVC,qBAAqB,EACrBC,cAAc,EACT;IACL,MAAMC,WAAW,EAAE;IAEnBX,OAAOY,OAAO,CAAC,CAACC,OAAOC;QACrBH,SAASI,IAAI,CACXxB,QAAQ;YACNE;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAc;YACAC;YACAb;YACAC;YACAC;YACAa,YAAYZ;YACZa,kBAAkBX;YAClBD;YACAE;YACAC;YACAC;YACAC;QACF;IAEJ;IAEA,MAAMQ,QAAQC,GAAG,CAACR;AACpB,EAAC"}
@@ -7,6 +7,7 @@ type Args<T> = {
7
7
  context: RequestContext;
8
8
  doc: T;
9
9
  field: Field | TabAsField;
10
+ fieldIndex: number;
10
11
  id?: number | string;
11
12
  overrideAccess: boolean;
12
13
  parentPath: (number | string)[];
@@ -14,6 +15,6 @@ type Args<T> = {
14
15
  req: PayloadRequest;
15
16
  siblingDoc: JsonObject;
16
17
  };
17
- export declare const promise: <T>({ id, collection, context, doc, field, overrideAccess, parentPath, parentSchemaPath, req, siblingDoc, }: Args<T>) => Promise<void>;
18
+ export declare const promise: <T>({ id, collection, context, doc, field, fieldIndex, overrideAccess, parentPath, parentSchemaPath, req, siblingDoc, }: Args<T>) => Promise<void>;
18
19
  export {};
19
20
  //# sourceMappingURL=promise.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"promise.d.ts","sourceRoot":"","sources":["../../../../src/fields/hooks/beforeDuplicate/promise.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAA;AACrF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AACvD,OAAO,KAAK,EAAE,UAAU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