payload 3.84.1 → 4.0.0-internal.d28e9fb

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 (400) hide show
  1. package/README.md +5 -5
  2. package/dist/admin/elements/Nav.d.ts +13 -0
  3. package/dist/admin/elements/Nav.d.ts.map +1 -1
  4. package/dist/admin/elements/Nav.js.map +1 -1
  5. package/dist/admin/functions/index.d.ts +1 -38
  6. package/dist/admin/functions/index.d.ts.map +1 -1
  7. package/dist/admin/functions/index.js.map +1 -1
  8. package/dist/admin/types.d.ts +5 -4
  9. package/dist/admin/types.d.ts.map +1 -1
  10. package/dist/admin/types.js.map +1 -1
  11. package/dist/admin/views/hierarchyList.d.ts +9 -0
  12. package/dist/admin/views/hierarchyList.d.ts.map +1 -0
  13. package/dist/admin/views/hierarchyList.js +3 -0
  14. package/dist/admin/views/hierarchyList.js.map +1 -0
  15. package/dist/admin/views/index.d.ts +1 -3
  16. package/dist/admin/views/index.d.ts.map +1 -1
  17. package/dist/admin/views/index.js.map +1 -1
  18. package/dist/admin/views/list.d.ts +43 -2
  19. package/dist/admin/views/list.d.ts.map +1 -1
  20. package/dist/admin/views/list.js.map +1 -1
  21. package/dist/bin/generateImportMap/iterateCollections.d.ts.map +1 -1
  22. package/dist/bin/generateImportMap/iterateCollections.js +1 -0
  23. package/dist/bin/generateImportMap/iterateCollections.js.map +1 -1
  24. package/dist/bin/generateImportMap/iterateConfig.d.ts.map +1 -1
  25. package/dist/bin/generateImportMap/iterateConfig.js +7 -0
  26. package/dist/bin/generateImportMap/iterateConfig.js.map +1 -1
  27. package/dist/bin/generateImportMap/iterateGlobals.d.ts.map +1 -1
  28. package/dist/bin/generateImportMap/iterateGlobals.js +20 -8
  29. package/dist/bin/generateImportMap/iterateGlobals.js.map +1 -1
  30. package/dist/bin/index.d.ts.map +1 -1
  31. package/dist/bin/index.js +1 -3
  32. package/dist/bin/index.js.map +1 -1
  33. package/dist/collections/config/client.d.ts +4 -2
  34. package/dist/collections/config/client.d.ts.map +1 -1
  35. package/dist/collections/config/client.js +13 -1
  36. package/dist/collections/config/client.js.map +1 -1
  37. package/dist/collections/config/defaults.js +1 -1
  38. package/dist/collections/config/defaults.js.map +1 -1
  39. package/dist/collections/config/sanitize.d.ts.map +1 -1
  40. package/dist/collections/config/sanitize.js +231 -184
  41. package/dist/collections/config/sanitize.js.map +1 -1
  42. package/dist/collections/config/types.d.ts +76 -91
  43. package/dist/collections/config/types.d.ts.map +1 -1
  44. package/dist/collections/config/types.js.map +1 -1
  45. package/dist/collections/operations/create.d.ts.map +1 -1
  46. package/dist/collections/operations/create.js +24 -19
  47. package/dist/collections/operations/create.js.map +1 -1
  48. package/dist/collections/operations/delete.d.ts.map +1 -1
  49. package/dist/collections/operations/delete.js +7 -2
  50. package/dist/collections/operations/delete.js.map +1 -1
  51. package/dist/collections/operations/deleteByID.d.ts.map +1 -1
  52. package/dist/collections/operations/deleteByID.js +7 -2
  53. package/dist/collections/operations/deleteByID.js.map +1 -1
  54. package/dist/collections/operations/find.d.ts.map +1 -1
  55. package/dist/collections/operations/find.js +7 -2
  56. package/dist/collections/operations/find.js.map +1 -1
  57. package/dist/collections/operations/findByID.d.ts.map +1 -1
  58. package/dist/collections/operations/findByID.js +10 -5
  59. package/dist/collections/operations/findByID.js.map +1 -1
  60. package/dist/collections/operations/findVersionByID.d.ts.map +1 -1
  61. package/dist/collections/operations/findVersionByID.js +6 -4
  62. package/dist/collections/operations/findVersionByID.js.map +1 -1
  63. package/dist/collections/operations/findVersions.d.ts.map +1 -1
  64. package/dist/collections/operations/findVersions.js +6 -4
  65. package/dist/collections/operations/findVersions.js.map +1 -1
  66. package/dist/collections/operations/restoreVersion.d.ts.map +1 -1
  67. package/dist/collections/operations/restoreVersion.js +7 -2
  68. package/dist/collections/operations/restoreVersion.js.map +1 -1
  69. package/dist/collections/operations/update.d.ts.map +1 -1
  70. package/dist/collections/operations/update.js +7 -2
  71. package/dist/collections/operations/update.js.map +1 -1
  72. package/dist/collections/operations/updateByID.d.ts.map +1 -1
  73. package/dist/collections/operations/updateByID.js +7 -2
  74. package/dist/collections/operations/updateByID.js.map +1 -1
  75. package/dist/collections/operations/utilities/update.d.ts.map +1 -1
  76. package/dist/collections/operations/utilities/update.js +5 -4
  77. package/dist/collections/operations/utilities/update.js.map +1 -1
  78. package/dist/config/client.d.ts.map +1 -1
  79. package/dist/config/client.js +0 -10
  80. package/dist/config/client.js.map +1 -1
  81. package/dist/config/defaults.d.ts.map +1 -1
  82. package/dist/config/defaults.js +0 -15
  83. package/dist/config/defaults.js.map +1 -1
  84. package/dist/config/orderable/index.d.ts.map +1 -1
  85. package/dist/config/orderable/index.js +0 -4
  86. package/dist/config/orderable/index.js.map +1 -1
  87. package/dist/config/sanitize.d.ts.map +1 -1
  88. package/dist/config/sanitize.js +252 -266
  89. package/dist/config/sanitize.js.map +1 -1
  90. package/dist/config/types.d.ts +120 -13
  91. package/dist/config/types.d.ts.map +1 -1
  92. package/dist/config/types.js.map +1 -1
  93. package/dist/exports/internal.d.ts +1 -0
  94. package/dist/exports/internal.d.ts.map +1 -1
  95. package/dist/exports/internal.js +1 -0
  96. package/dist/exports/internal.js.map +1 -1
  97. package/dist/exports/shared.d.ts +5 -3
  98. package/dist/exports/shared.d.ts.map +1 -1
  99. package/dist/exports/shared.js +3 -2
  100. package/dist/exports/shared.js.map +1 -1
  101. package/dist/fields/baseFields/slug/index.d.ts.map +1 -1
  102. package/dist/fields/baseFields/slug/index.js +6 -4
  103. package/dist/fields/baseFields/slug/index.js.map +1 -1
  104. package/dist/fields/config/client.d.ts.map +1 -1
  105. package/dist/fields/config/client.js +3 -2
  106. package/dist/fields/config/client.js.map +1 -1
  107. package/dist/fields/config/sanitize.d.ts.map +1 -1
  108. package/dist/fields/config/sanitize.js +335 -322
  109. package/dist/fields/config/sanitize.js.map +1 -1
  110. package/dist/fields/config/sanitizeJoinField.d.ts.map +1 -1
  111. package/dist/fields/config/sanitizeJoinField.js +3 -0
  112. package/dist/fields/config/sanitizeJoinField.js.map +1 -1
  113. package/dist/fields/config/types.d.ts +17 -73
  114. package/dist/fields/config/types.d.ts.map +1 -1
  115. package/dist/fields/config/types.js +11 -1
  116. package/dist/fields/config/types.js.map +1 -1
  117. package/dist/fields/isFieldDisabled.d.ts +12 -0
  118. package/dist/fields/isFieldDisabled.d.ts.map +1 -0
  119. package/dist/fields/isFieldDisabled.js +15 -0
  120. package/dist/fields/isFieldDisabled.js.map +1 -0
  121. package/dist/fields/isFieldDisabled.spec.js +134 -0
  122. package/dist/fields/isFieldDisabled.spec.js.map +1 -0
  123. package/dist/fields/validations.js +1 -1
  124. package/dist/fields/validations.js.map +1 -1
  125. package/dist/globals/config/client.d.ts +1 -1
  126. package/dist/globals/config/client.d.ts.map +1 -1
  127. package/dist/globals/config/client.js +2 -1
  128. package/dist/globals/config/client.js.map +1 -1
  129. package/dist/globals/config/sanitize.d.ts.map +1 -1
  130. package/dist/globals/config/sanitize.js +132 -122
  131. package/dist/globals/config/sanitize.js.map +1 -1
  132. package/dist/globals/config/types.d.ts +4 -57
  133. package/dist/globals/config/types.d.ts.map +1 -1
  134. package/dist/globals/config/types.js.map +1 -1
  135. package/dist/globals/operations/findOne.d.ts.map +1 -1
  136. package/dist/globals/operations/findOne.js +7 -2
  137. package/dist/globals/operations/findOne.js.map +1 -1
  138. package/dist/globals/operations/findVersionByID.d.ts.map +1 -1
  139. package/dist/globals/operations/findVersionByID.js +6 -4
  140. package/dist/globals/operations/findVersionByID.js.map +1 -1
  141. package/dist/globals/operations/findVersions.d.ts.map +1 -1
  142. package/dist/globals/operations/findVersions.js +6 -4
  143. package/dist/globals/operations/findVersions.js.map +1 -1
  144. package/dist/globals/operations/update.d.ts.map +1 -1
  145. package/dist/globals/operations/update.js +7 -2
  146. package/dist/globals/operations/update.js.map +1 -1
  147. package/dist/hierarchy/addHierarchyToCollection.d.ts +9 -0
  148. package/dist/hierarchy/addHierarchyToCollection.d.ts.map +1 -0
  149. package/dist/hierarchy/addHierarchyToCollection.js +76 -0
  150. package/dist/hierarchy/addHierarchyToCollection.js.map +1 -0
  151. package/dist/hierarchy/buildParentField.d.ts +11 -0
  152. package/dist/hierarchy/buildParentField.d.ts.map +1 -0
  153. package/dist/hierarchy/buildParentField.js +42 -0
  154. package/dist/hierarchy/buildParentField.js.map +1 -0
  155. package/dist/hierarchy/constants.d.ts +15 -0
  156. package/dist/hierarchy/constants.d.ts.map +1 -0
  157. package/dist/hierarchy/constants.js +11 -0
  158. package/dist/hierarchy/constants.js.map +1 -0
  159. package/dist/hierarchy/createFolderField.d.ts +39 -0
  160. package/dist/hierarchy/createFolderField.d.ts.map +1 -0
  161. package/dist/hierarchy/createFolderField.js +54 -0
  162. package/dist/hierarchy/createFolderField.js.map +1 -0
  163. package/dist/hierarchy/createTagField.d.ts +44 -0
  164. package/dist/hierarchy/createTagField.d.ts.map +1 -0
  165. package/dist/hierarchy/createTagField.js +48 -0
  166. package/dist/hierarchy/createTagField.js.map +1 -0
  167. package/dist/hierarchy/getInitialTreeData.d.ts +27 -0
  168. package/dist/hierarchy/getInitialTreeData.d.ts.map +1 -0
  169. package/dist/hierarchy/getInitialTreeData.js +125 -0
  170. package/dist/hierarchy/getInitialTreeData.js.map +1 -0
  171. package/dist/hierarchy/hooks/collectionAfterDelete.d.ts +14 -0
  172. package/dist/hierarchy/hooks/collectionAfterDelete.d.ts.map +1 -0
  173. package/dist/hierarchy/hooks/collectionAfterDelete.js +21 -0
  174. package/dist/hierarchy/hooks/collectionAfterDelete.js.map +1 -0
  175. package/dist/hierarchy/hooks/collectionAfterRead.d.ts +27 -0
  176. package/dist/hierarchy/hooks/collectionAfterRead.d.ts.map +1 -0
  177. package/dist/hierarchy/hooks/collectionAfterRead.js +72 -0
  178. package/dist/hierarchy/hooks/collectionAfterRead.js.map +1 -0
  179. package/dist/hierarchy/hooks/collectionBeforeChange.d.ts +19 -0
  180. package/dist/hierarchy/hooks/collectionBeforeChange.d.ts.map +1 -0
  181. package/dist/hierarchy/hooks/collectionBeforeChange.js +90 -0
  182. package/dist/hierarchy/hooks/collectionBeforeChange.js.map +1 -0
  183. package/dist/hierarchy/hooks/collectionBeforeDelete.d.ts +15 -0
  184. package/dist/hierarchy/hooks/collectionBeforeDelete.d.ts.map +1 -0
  185. package/dist/hierarchy/hooks/collectionBeforeDelete.js +20 -0
  186. package/dist/hierarchy/hooks/collectionBeforeDelete.js.map +1 -0
  187. package/dist/hierarchy/hooks/collectionBeforeOperation.d.ts +33 -0
  188. package/dist/hierarchy/hooks/collectionBeforeOperation.d.ts.map +1 -0
  189. package/dist/hierarchy/hooks/collectionBeforeOperation.js +66 -0
  190. package/dist/hierarchy/hooks/collectionBeforeOperation.js.map +1 -0
  191. package/dist/hierarchy/hooks/ensureSafeCollectionsChange.d.ts +8 -0
  192. package/dist/hierarchy/hooks/ensureSafeCollectionsChange.d.ts.map +1 -0
  193. package/dist/hierarchy/hooks/ensureSafeCollectionsChange.js +108 -0
  194. package/dist/hierarchy/hooks/ensureSafeCollectionsChange.js.map +1 -0
  195. package/dist/hierarchy/injectHierarchyButton.d.ts +14 -0
  196. package/dist/hierarchy/injectHierarchyButton.d.ts.map +1 -0
  197. package/dist/hierarchy/injectHierarchyButton.js +37 -0
  198. package/dist/hierarchy/injectHierarchyButton.js.map +1 -0
  199. package/dist/hierarchy/presets.d.ts +13 -0
  200. package/dist/hierarchy/presets.d.ts.map +1 -0
  201. package/dist/hierarchy/presets.js +52 -0
  202. package/dist/hierarchy/presets.js.map +1 -0
  203. package/dist/hierarchy/resolveHierarchyCollections.d.ts +23 -0
  204. package/dist/hierarchy/resolveHierarchyCollections.d.ts.map +1 -0
  205. package/dist/hierarchy/resolveHierarchyCollections.js +321 -0
  206. package/dist/hierarchy/resolveHierarchyCollections.js.map +1 -0
  207. package/dist/hierarchy/sanitizeHierarchyCollection.d.ts +14 -0
  208. package/dist/hierarchy/sanitizeHierarchyCollection.d.ts.map +1 -0
  209. package/dist/hierarchy/sanitizeHierarchyCollection.js +117 -0
  210. package/dist/hierarchy/sanitizeHierarchyCollection.js.map +1 -0
  211. package/dist/hierarchy/types.d.ts +155 -0
  212. package/dist/hierarchy/types.d.ts.map +1 -0
  213. package/dist/hierarchy/types.js +6 -0
  214. package/dist/hierarchy/types.js.map +1 -0
  215. package/dist/hierarchy/utils/buildLocalizedHierarchyPaths.d.ts +77 -0
  216. package/dist/hierarchy/utils/buildLocalizedHierarchyPaths.d.ts.map +1 -0
  217. package/dist/hierarchy/utils/buildLocalizedHierarchyPaths.js +77 -0
  218. package/dist/hierarchy/utils/buildLocalizedHierarchyPaths.js.map +1 -0
  219. package/dist/hierarchy/utils/computePaths.d.ts +31 -0
  220. package/dist/hierarchy/utils/computePaths.d.ts.map +1 -0
  221. package/dist/hierarchy/utils/computePaths.js +445 -0
  222. package/dist/hierarchy/utils/computePaths.js.map +1 -0
  223. package/dist/hierarchy/utils/findUseAsTitle.d.ts +14 -0
  224. package/dist/hierarchy/utils/findUseAsTitle.d.ts.map +1 -0
  225. package/dist/hierarchy/utils/findUseAsTitle.js +89 -0
  226. package/dist/hierarchy/utils/findUseAsTitle.js.map +1 -0
  227. package/dist/hierarchy/utils/getAncestors.d.ts +34 -0
  228. package/dist/hierarchy/utils/getAncestors.d.ts.map +1 -0
  229. package/dist/hierarchy/utils/getAncestors.js +94 -0
  230. package/dist/hierarchy/utils/getAncestors.js.map +1 -0
  231. package/dist/hierarchy/utils/getLocalizedValue.d.ts +30 -0
  232. package/dist/hierarchy/utils/getLocalizedValue.d.ts.map +1 -0
  233. package/dist/hierarchy/utils/getLocalizedValue.js +46 -0
  234. package/dist/hierarchy/utils/getLocalizedValue.js.map +1 -0
  235. package/dist/hierarchy/utils/getLocalizedValue.spec.js +250 -0
  236. package/dist/hierarchy/utils/getLocalizedValue.spec.js.map +1 -0
  237. package/dist/index.bundled.d.ts +709 -530
  238. package/dist/index.d.ts +28 -8
  239. package/dist/index.d.ts.map +1 -1
  240. package/dist/index.js +31 -8
  241. package/dist/index.js.map +1 -1
  242. package/dist/preferences/keys.d.ts +8 -4
  243. package/dist/preferences/keys.d.ts.map +1 -1
  244. package/dist/preferences/keys.js +7 -4
  245. package/dist/preferences/keys.js.map +1 -1
  246. package/dist/preferences/types.d.ts +1 -1
  247. package/dist/preferences/types.d.ts.map +1 -1
  248. package/dist/preferences/types.js.map +1 -1
  249. package/dist/query-presets/config.d.ts.map +1 -1
  250. package/dist/query-presets/config.js +5 -1
  251. package/dist/query-presets/config.js.map +1 -1
  252. package/dist/queues/config/types/index.d.ts +0 -21
  253. package/dist/queues/config/types/index.d.ts.map +1 -1
  254. package/dist/queues/config/types/index.js.map +1 -1
  255. package/dist/queues/config/types/taskTypes.d.ts +0 -20
  256. package/dist/queues/config/types/taskTypes.d.ts.map +1 -1
  257. package/dist/queues/config/types/taskTypes.js.map +1 -1
  258. package/dist/queues/errors/handleWorkflowError.d.ts.map +1 -1
  259. package/dist/queues/errors/handleWorkflowError.js +9 -1
  260. package/dist/queues/errors/handleWorkflowError.js.map +1 -1
  261. package/dist/queues/localAPI.d.ts.map +1 -1
  262. package/dist/queues/localAPI.js +26 -67
  263. package/dist/queues/localAPI.js.map +1 -1
  264. package/dist/queues/operations/handleSchedules/index.d.ts.map +1 -1
  265. package/dist/queues/operations/handleSchedules/index.js +1 -4
  266. package/dist/queues/operations/handleSchedules/index.js.map +1 -1
  267. package/dist/queues/operations/runJobs/index.d.ts.map +1 -1
  268. package/dist/queues/operations/runJobs/index.js +40 -37
  269. package/dist/queues/operations/runJobs/index.js.map +1 -1
  270. package/dist/queues/operations/runJobs/runJob/getRunTaskFunction.d.ts.map +1 -1
  271. package/dist/queues/operations/runJobs/runJob/getRunTaskFunction.js +3 -22
  272. package/dist/queues/operations/runJobs/runJob/getRunTaskFunction.js.map +1 -1
  273. package/dist/queues/operations/runJobs/runJob/getUpdateJobFunction.d.ts.map +1 -1
  274. package/dist/queues/operations/runJobs/runJob/getUpdateJobFunction.js +0 -2
  275. package/dist/queues/operations/runJobs/runJob/getUpdateJobFunction.js.map +1 -1
  276. package/dist/queues/utilities/updateJob.d.ts +1 -3
  277. package/dist/queues/utilities/updateJob.d.ts.map +1 -1
  278. package/dist/queues/utilities/updateJob.js +2 -18
  279. package/dist/queues/utilities/updateJob.js.map +1 -1
  280. package/dist/types/index.d.ts +44 -0
  281. package/dist/types/index.d.ts.map +1 -1
  282. package/dist/types/index.js.map +1 -1
  283. package/dist/uploads/getBaseFields.d.ts.map +1 -1
  284. package/dist/uploads/getBaseFields.js +35 -69
  285. package/dist/uploads/getBaseFields.js.map +1 -1
  286. package/dist/uploads/getSafeFilename.d.ts +9 -4
  287. package/dist/uploads/getSafeFilename.d.ts.map +1 -1
  288. package/dist/uploads/getSafeFilename.js +5 -5
  289. package/dist/uploads/getSafeFilename.js.map +1 -1
  290. package/dist/utilities/appendDateTimezoneSelectFields.d.ts +13 -0
  291. package/dist/utilities/appendDateTimezoneSelectFields.d.ts.map +1 -0
  292. package/dist/utilities/appendDateTimezoneSelectFields.js +47 -0
  293. package/dist/utilities/appendDateTimezoneSelectFields.js.map +1 -0
  294. package/dist/utilities/appendUploadSelectFields.d.ts.map +1 -1
  295. package/dist/utilities/appendUploadSelectFields.js +3 -0
  296. package/dist/utilities/appendUploadSelectFields.js.map +1 -1
  297. package/dist/utilities/extractID.js +1 -1
  298. package/dist/utilities/extractID.js.map +1 -1
  299. package/dist/utilities/flattenAllFields.d.ts.map +1 -1
  300. package/dist/utilities/flattenAllFields.js +102 -93
  301. package/dist/utilities/flattenAllFields.js.map +1 -1
  302. package/dist/utilities/formatAdminURL.d.ts +13 -2
  303. package/dist/utilities/formatAdminURL.d.ts.map +1 -1
  304. package/dist/utilities/formatAdminURL.js.map +1 -1
  305. package/dist/utilities/handleEndpoints.d.ts.map +1 -1
  306. package/dist/utilities/handleEndpoints.js +0 -1
  307. package/dist/utilities/handleEndpoints.js.map +1 -1
  308. package/dist/utilities/resolveSelect.d.ts +16 -0
  309. package/dist/utilities/resolveSelect.d.ts.map +1 -0
  310. package/dist/utilities/resolveSelect.js +19 -0
  311. package/dist/utilities/resolveSelect.js.map +1 -0
  312. package/dist/utilities/sanitizeProfiler.d.ts +38 -0
  313. package/dist/utilities/sanitizeProfiler.d.ts.map +1 -0
  314. package/dist/utilities/sanitizeProfiler.js +101 -0
  315. package/dist/utilities/sanitizeProfiler.js.map +1 -0
  316. package/dist/utilities/sanitizeSelect.d.ts +1 -2
  317. package/dist/utilities/sanitizeSelect.d.ts.map +1 -1
  318. package/dist/utilities/sanitizeSelect.js +19 -25
  319. package/dist/utilities/sanitizeSelect.js.map +1 -1
  320. package/dist/versions/baseFields.d.ts.map +1 -1
  321. package/dist/versions/baseFields.js +3 -2
  322. package/dist/versions/baseFields.js.map +1 -1
  323. package/dist/versions/buildCollectionFields.d.ts.map +1 -1
  324. package/dist/versions/buildCollectionFields.js +0 -1
  325. package/dist/versions/buildCollectionFields.js.map +1 -1
  326. package/dist/versions/buildGlobalFields.d.ts.map +1 -1
  327. package/dist/versions/buildGlobalFields.js +0 -1
  328. package/dist/versions/buildGlobalFields.js.map +1 -1
  329. package/dist/versions/payloadPackageList.d.ts.map +1 -1
  330. package/dist/versions/payloadPackageList.js +0 -1
  331. package/dist/versions/payloadPackageList.js.map +1 -1
  332. package/package.json +4 -4
  333. package/dist/admin/views/folderList.d.ts +0 -56
  334. package/dist/admin/views/folderList.d.ts.map +0 -1
  335. package/dist/admin/views/folderList.js +0 -3
  336. package/dist/admin/views/folderList.js.map +0 -1
  337. package/dist/folders/addFolderCollection.d.ts +0 -10
  338. package/dist/folders/addFolderCollection.d.ts.map +0 -1
  339. package/dist/folders/addFolderCollection.js +0 -26
  340. package/dist/folders/addFolderCollection.js.map +0 -1
  341. package/dist/folders/addFolderFieldToCollection.d.ts +0 -8
  342. package/dist/folders/addFolderFieldToCollection.d.ts.map +0 -1
  343. package/dist/folders/addFolderFieldToCollection.js +0 -20
  344. package/dist/folders/addFolderFieldToCollection.js.map +0 -1
  345. package/dist/folders/buildFolderField.d.ts +0 -8
  346. package/dist/folders/buildFolderField.d.ts.map +0 -1
  347. package/dist/folders/buildFolderField.js +0 -87
  348. package/dist/folders/buildFolderField.js.map +0 -1
  349. package/dist/folders/constants.d.ts +0 -3
  350. package/dist/folders/constants.d.ts.map +0 -1
  351. package/dist/folders/constants.js +0 -4
  352. package/dist/folders/constants.js.map +0 -1
  353. package/dist/folders/createFolderCollection.d.ts +0 -11
  354. package/dist/folders/createFolderCollection.d.ts.map +0 -1
  355. package/dist/folders/createFolderCollection.js +0 -115
  356. package/dist/folders/createFolderCollection.js.map +0 -1
  357. package/dist/folders/hooks/deleteSubfoldersAfterDelete.d.ts +0 -8
  358. package/dist/folders/hooks/deleteSubfoldersAfterDelete.d.ts.map +0 -1
  359. package/dist/folders/hooks/deleteSubfoldersAfterDelete.js +0 -15
  360. package/dist/folders/hooks/deleteSubfoldersAfterDelete.js.map +0 -1
  361. package/dist/folders/hooks/dissasociateAfterDelete.d.ts +0 -8
  362. package/dist/folders/hooks/dissasociateAfterDelete.d.ts.map +0 -1
  363. package/dist/folders/hooks/dissasociateAfterDelete.js +0 -20
  364. package/dist/folders/hooks/dissasociateAfterDelete.js.map +0 -1
  365. package/dist/folders/hooks/ensureSafeCollectionsChange.d.ts +0 -5
  366. package/dist/folders/hooks/ensureSafeCollectionsChange.d.ts.map +0 -1
  367. package/dist/folders/hooks/ensureSafeCollectionsChange.js +0 -107
  368. package/dist/folders/hooks/ensureSafeCollectionsChange.js.map +0 -1
  369. package/dist/folders/hooks/reparentChildFolder.d.ts +0 -24
  370. package/dist/folders/hooks/reparentChildFolder.d.ts.map +0 -1
  371. package/dist/folders/hooks/reparentChildFolder.js +0 -72
  372. package/dist/folders/hooks/reparentChildFolder.js.map +0 -1
  373. package/dist/folders/types.d.ts +0 -118
  374. package/dist/folders/types.d.ts.map +0 -1
  375. package/dist/folders/types.js +0 -3
  376. package/dist/folders/types.js.map +0 -1
  377. package/dist/folders/utils/buildFolderWhereConstraints.d.ts +0 -13
  378. package/dist/folders/utils/buildFolderWhereConstraints.d.ts.map +0 -1
  379. package/dist/folders/utils/buildFolderWhereConstraints.js +0 -45
  380. package/dist/folders/utils/buildFolderWhereConstraints.js.map +0 -1
  381. package/dist/folders/utils/formatFolderOrDocumentItem.d.ts +0 -12
  382. package/dist/folders/utils/formatFolderOrDocumentItem.d.ts.map +0 -1
  383. package/dist/folders/utils/formatFolderOrDocumentItem.js +0 -30
  384. package/dist/folders/utils/formatFolderOrDocumentItem.js.map +0 -1
  385. package/dist/folders/utils/getFolderBreadcrumbs.d.ts +0 -14
  386. package/dist/folders/utils/getFolderBreadcrumbs.d.ts.map +0 -1
  387. package/dist/folders/utils/getFolderBreadcrumbs.js +0 -45
  388. package/dist/folders/utils/getFolderBreadcrumbs.js.map +0 -1
  389. package/dist/folders/utils/getFolderData.d.ts +0 -33
  390. package/dist/folders/utils/getFolderData.d.ts.map +0 -1
  391. package/dist/folders/utils/getFolderData.js +0 -88
  392. package/dist/folders/utils/getFolderData.js.map +0 -1
  393. package/dist/folders/utils/getFoldersAndDocumentsFromJoin.d.ts +0 -24
  394. package/dist/folders/utils/getFoldersAndDocumentsFromJoin.d.ts.map +0 -1
  395. package/dist/folders/utils/getFoldersAndDocumentsFromJoin.js +0 -66
  396. package/dist/folders/utils/getFoldersAndDocumentsFromJoin.js.map +0 -1
  397. package/dist/folders/utils/getOrphanedDocs.d.ts +0 -15
  398. package/dist/folders/utils/getOrphanedDocs.d.ts.map +0 -1
  399. package/dist/folders/utils/getOrphanedDocs.js +0 -40
  400. package/dist/folders/utils/getOrphanedDocs.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/hierarchy/resolveHierarchyCollections.ts"],"sourcesContent":["import type { CollectionConfig, SanitizedCollectionConfig } from '../collections/config/types.js'\nimport type { Config } from '../config/types.js'\nimport type {\n JoinField,\n Option,\n RelationshipField,\n SelectField,\n Validate,\n} from '../fields/config/types.js'\nimport type { Document } from '../types/index.js'\nimport type {\n HierarchyJoinFieldConfig,\n SanitizedHierarchyConfig,\n SanitizedHierarchyRelatedCollection,\n} from './types.js'\n\nimport { sanitizeJoinField } from '../fields/config/sanitizeJoinField.js'\nimport { fieldAffectsData } from '../fields/config/types.js'\nimport { extractID } from '../utilities/extractID.js'\nimport { flattenAllFields } from '../utilities/flattenAllFields.js'\nimport { getHierarchyFieldName } from './constants.js'\nimport { hierarchyCollectionAfterDelete } from './hooks/collectionAfterDelete.js'\nimport { injectHierarchyButton } from './injectHierarchyButton.js'\n\n/**\n * Resolves hierarchy relationships across collections.\n *\n * This function runs after individual collection sanitization to establish\n * cross-collection hierarchy relationships. It discovers which collections\n * reference each hierarchy and configures the necessary fields, components,\n * and hooks.\n *\n * @remarks\n * Must be called after all collections are sanitized.\n *\n * **What it does:**\n * - Discovers related collections by scanning for hierarchy relationship fields\n * - Injects `HierarchyButton` component when `custom.hierarchy.injectHeaderButton` is set\n * - Adds `collectionSpecific` validation to ensure hierarchy items accept the document type\n * - Injects the `hierarchyType` select field when `collectionSpecific` is enabled\n * - Injects join field when `joinField` is configured\n * - Adds `afterDelete` hook to clear hierarchy references when items are deleted\n * - Populates `relatedCollections` in the sanitized hierarchy config\n */\nexport const resolveHierarchyCollections = (config: Config): void => {\n const hierarchyCollections =\n config.collections?.filter((col) => col.hierarchy && typeof col.hierarchy === 'object') || []\n\n for (const hierarchyCollection of hierarchyCollections) {\n const hierarchy = hierarchyCollection.hierarchy\n\n // TypeScript guard - hierarchy is guaranteed to be an object by the filter above\n if (!hierarchy || typeof hierarchy !== 'object') {\n continue\n }\n\n const hierarchyConfig = hierarchy as SanitizedHierarchyConfig\n const defaultFieldName = getHierarchyFieldName(hierarchyCollection.slug)\n const parentFieldName = hierarchyConfig.parentFieldName ?? defaultFieldName\n const isParentFieldNameOverridden = parentFieldName !== defaultFieldName\n const collectionSpecific = hierarchyConfig.collectionSpecific\n const typeFieldName = collectionSpecific ? collectionSpecific.fieldName : undefined\n const allowHasMany = hierarchyConfig.allowHasMany ?? true\n\n // Build relatedCollections by scanning all collections for hierarchy fields\n const sanitizedRelatedCollections: Record<string, SanitizedHierarchyRelatedCollection> = {}\n\n const selfParentField = hierarchyCollection.fields.find(\n (field) =>\n fieldAffectsData(field) &&\n field.name === parentFieldName &&\n field.type === 'relationship' &&\n (field as RelationshipField).relationTo === hierarchyCollection.slug,\n ) as RelationshipField | undefined\n\n // Check if the hierarchy collection's own parent field should be replaced with a header button\n if (selfParentField?.custom?.hierarchy?.injectHeaderButton === true) {\n injectHierarchyButton({\n collection: hierarchyCollection,\n fieldName: parentFieldName,\n hierarchyCollectionSlug: hierarchyCollection.slug,\n parentFieldName: hierarchyConfig.parentFieldName,\n })\n }\n\n for (const collection of config.collections || []) {\n // Skip the hierarchy collection itself (handled above)\n if (collection.slug === hierarchyCollection.slug) {\n continue\n }\n\n // Find hierarchy field by the default name (what createFolderField uses)\n const hierarchyField = collection.fields.find(\n (field) =>\n fieldAffectsData(field) &&\n field.name === defaultFieldName &&\n field.type === 'relationship' &&\n (field as RelationshipField).relationTo === hierarchyCollection.slug,\n ) as RelationshipField | undefined\n\n // If parentFieldName is overridden, rename the field to match\n if (hierarchyField && isParentFieldNameOverridden) {\n hierarchyField.name = parentFieldName\n }\n\n if (!hierarchyField) {\n continue\n }\n\n const fieldHasMany = hierarchyField.hasMany ?? allowHasMany\n\n // If collectionSpecific, inject validation to check hierarchy allows this collection type\n if (collectionSpecific) {\n injectCollectionSpecificValidation({\n hierarchyField,\n hierarchySlug: hierarchyCollection.slug,\n typeFieldName: typeFieldName!,\n })\n }\n\n // Store discovered collection with hasMany info\n sanitizedRelatedCollections[collection.slug] = {\n fieldName: parentFieldName,\n hasMany: fieldHasMany,\n }\n\n // Inject HierarchyButton if field requests it\n if (hierarchyField.custom?.hierarchy?.injectHeaderButton === true) {\n injectHierarchyButton({\n collection,\n fieldName: parentFieldName,\n hierarchyCollectionSlug: hierarchyCollection.slug,\n parentFieldName: hierarchyConfig.parentFieldName,\n })\n }\n }\n\n // If collectionSpecific, add type field to hierarchy collection\n if (hierarchyConfig.collectionSpecific) {\n injectTypeField({\n config,\n hierarchyCollection: hierarchyCollection as SanitizedCollectionConfig,\n parentFieldName: hierarchyConfig.parentFieldName,\n sanitizedRelatedCollections,\n typeFieldName: hierarchyConfig.collectionSpecific.fieldName,\n })\n }\n\n // If joinField is configured, add the join field to query children\n if (hierarchyConfig.joinField) {\n injectJoinField({\n config,\n hierarchyCollection: hierarchyCollection as SanitizedCollectionConfig,\n joinFieldConfig: hierarchyConfig.joinField,\n parentFieldName,\n relatedSlugs: Object.keys(sanitizedRelatedCollections),\n })\n }\n\n // Update hierarchy config with sanitized relatedCollections\n if (hierarchyConfig) {\n hierarchyConfig.relatedCollections = sanitizedRelatedCollections\n }\n\n // Add afterDelete hook to clear folder references from related documents\n if (Object.keys(sanitizedRelatedCollections).length > 0) {\n injectAfterDeleteHook({\n hierarchyCollection: hierarchyCollection as SanitizedCollectionConfig,\n sanitizedRelatedCollections,\n })\n }\n\n // Add sidebar tab for this hierarchy collection (unless explicitly disabled)\n if (hierarchyConfig.admin.injectSidebarTab !== false) {\n injectSidebarTab({\n config,\n hierarchyCollection,\n hierarchyConfig,\n })\n\n // Hide from nav when sidebar tab is injected (unless user explicitly set group)\n if (hierarchyCollection.admin?.group === undefined) {\n hierarchyCollection.admin = {\n ...hierarchyCollection.admin,\n group: false,\n }\n }\n }\n }\n}\n\n/**\n * Injects validation for collectionSpecific hierarchy fields.\n * Ensures the selected hierarchy item allows documents of this collection type.\n */\nfunction injectCollectionSpecificValidation({\n hierarchyField,\n hierarchySlug,\n typeFieldName,\n}: {\n hierarchyField: RelationshipField\n hierarchySlug: string\n typeFieldName: string\n}): void {\n const existingValidate = hierarchyField.validate\n\n const validate: Validate<unknown> = async (value, options) => {\n // Run existing validation first if present\n if (existingValidate) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const existingResult = await existingValidate(value as any, options as any)\n if (existingResult !== true) {\n return existingResult\n }\n }\n\n // No hierarchy selected, no validation needed\n if (!value) {\n return true\n }\n\n const { collectionSlug, overrideAccess, previousValue, req } = options\n const newID = extractID<Document>(value)\n\n // Value didn't change, no validation needed\n if (previousValue && extractID<Document>(previousValue) === newID) {\n return true\n }\n\n // Fetch the hierarchy item to check its type field\n let parentItem: Document | null = null\n if (typeof newID === 'string' || typeof newID === 'number') {\n try {\n parentItem = await req.payload.findByID({\n id: newID,\n collection: hierarchySlug,\n depth: 0,\n overrideAccess: overrideAccess ?? false,\n req,\n select: { [typeFieldName]: true },\n })\n } catch {\n return `Hierarchy item with ID ${newID} not found`\n }\n }\n\n if (!parentItem) {\n return `Hierarchy item with ID ${newID} not found`\n }\n\n const allowedTypes: string[] = (parentItem[typeFieldName] as string[]) || []\n\n // If hierarchy has no types, it accepts all collections\n if (allowedTypes.length === 0) {\n return true\n }\n\n // Check if this collection is allowed\n if (collectionSlug && allowedTypes.includes(collectionSlug)) {\n return true\n }\n\n return `Hierarchy item \"${newID}\" does not allow documents of type \"${collectionSlug}\"`\n }\n\n hierarchyField.validate = validate\n}\n\n/**\n * Injects the hierarchyType select field into a hierarchy collection.\n */\nfunction injectTypeField({\n config,\n hierarchyCollection,\n parentFieldName,\n sanitizedRelatedCollections,\n typeFieldName,\n}: {\n config: Config\n hierarchyCollection: CollectionConfig | SanitizedCollectionConfig\n parentFieldName: string\n sanitizedRelatedCollections: Record<string, SanitizedHierarchyRelatedCollection>\n typeFieldName: string\n}): void {\n const collectionOptions: Option[] = Object.keys(sanitizedRelatedCollections).map((slug) => {\n const relatedCollection = config.collections?.find((c) => c.slug === slug)\n return {\n label: relatedCollection?.labels?.plural || slug,\n value: slug,\n }\n })\n\n const typeField: SelectField = {\n name: typeFieldName,\n type: 'select',\n admin: {\n components: {\n Field: {\n path: '@payloadcms/next/rsc#HierarchyTypeFieldServer',\n serverProps: {\n collectionOptions,\n parentFieldName,\n },\n },\n },\n position: 'sidebar',\n },\n hasMany: true,\n options: collectionOptions,\n }\n\n hierarchyCollection.fields = hierarchyCollection.fields || []\n hierarchyCollection.fields.push(typeField)\n\n // Recompute flattenedFields since we added a field after initial sanitization\n // This is required for the field to be queryable\n if ('flattenedFields' in hierarchyCollection) {\n hierarchyCollection.flattenedFields = flattenAllFields({\n fields: hierarchyCollection.fields,\n })\n }\n}\n\n/**\n * Injects a join field to query all children of a hierarchy item.\n */\nfunction injectJoinField({\n config,\n hierarchyCollection,\n joinFieldConfig,\n parentFieldName,\n relatedSlugs,\n}: {\n config: Config\n hierarchyCollection: SanitizedCollectionConfig\n joinFieldConfig: HierarchyJoinFieldConfig\n parentFieldName: string\n relatedSlugs: string[]\n}): void {\n const { name, admin: userAdmin, ...userConfig } = joinFieldConfig\n\n const hasJoinField = hierarchyCollection.fields?.some(\n (field) => 'name' in field && field.name === name,\n )\n\n if (hasJoinField) {\n return\n }\n\n const joinField: JoinField = {\n // User config (spread first so auto-generated values take precedence for required fields)\n ...userConfig,\n // Auto-generated values (these cannot be overridden)\n name,\n type: 'join',\n collection: [hierarchyCollection.slug, ...relatedSlugs],\n hasMany: true,\n on: parentFieldName,\n // Merge admin config\n admin: {\n ...userAdmin,\n },\n }\n\n hierarchyCollection.fields = hierarchyCollection.fields || []\n hierarchyCollection.fields.push(joinField)\n\n // Sanitize the join field to register it properly\n sanitizeJoinField({\n config,\n field: joinField,\n joins: hierarchyCollection.joins,\n parentIsLocalized: false,\n polymorphicJoins: hierarchyCollection.polymorphicJoins,\n })\n\n // Recompute flattenedFields since we added a field after initial sanitization\n hierarchyCollection.flattenedFields = flattenAllFields({\n fields: hierarchyCollection.fields,\n })\n}\n\n/**\n * Injects afterDelete hook to clear hierarchy references from related documents.\n */\nfunction injectAfterDeleteHook({\n hierarchyCollection,\n sanitizedRelatedCollections,\n}: {\n hierarchyCollection: CollectionConfig | SanitizedCollectionConfig\n sanitizedRelatedCollections: Record<string, SanitizedHierarchyRelatedCollection>\n}): void {\n // Build map of collection slugs to their field names\n const relatedCollectionFieldMap: Record<string, string> = {}\n for (const [slug, relatedConfig] of Object.entries(sanitizedRelatedCollections)) {\n relatedCollectionFieldMap[slug] = relatedConfig.fieldName\n }\n\n hierarchyCollection.hooks = hierarchyCollection.hooks || {}\n hierarchyCollection.hooks.afterDelete = [\n ...(hierarchyCollection.hooks.afterDelete || []),\n hierarchyCollectionAfterDelete({ relatedCollections: relatedCollectionFieldMap }),\n ]\n}\n\n/**\n * Injects a sidebar tab for a hierarchy collection.\n */\nfunction injectSidebarTab({\n config,\n hierarchyCollection,\n hierarchyConfig,\n}: {\n config: Config\n hierarchyCollection: CollectionConfig\n hierarchyConfig: SanitizedHierarchyConfig\n}): void {\n const tabSlug = `hierarchy-${hierarchyCollection.slug}`\n const Icon = hierarchyConfig.admin.components.Icon\n\n // Initialize admin config structure\n config.admin = config.admin || {}\n config.admin.components = config.admin.components || {}\n config.admin.components.sidebar = config.admin.components.sidebar || {}\n config.admin.components.sidebar.tabs = config.admin.components.sidebar.tabs || []\n\n // Check if tab already exists\n const hasTab = config.admin.components.sidebar.tabs.some((tab) => tab.slug === tabSlug)\n\n if (!hasTab) {\n config.admin.components.sidebar.tabs.push({\n slug: tabSlug,\n components: {\n Content: {\n clientProps: {\n hierarchyCollectionSlug: hierarchyCollection.slug,\n },\n path: '@payloadcms/ui/rsc#HierarchySidebarTabServer',\n },\n Icon,\n },\n label: hierarchyCollection.labels?.plural || hierarchyCollection.slug,\n })\n }\n}\n"],"names":["sanitizeJoinField","fieldAffectsData","extractID","flattenAllFields","getHierarchyFieldName","hierarchyCollectionAfterDelete","injectHierarchyButton","resolveHierarchyCollections","config","hierarchyCollections","collections","filter","col","hierarchy","hierarchyCollection","hierarchyConfig","defaultFieldName","slug","parentFieldName","isParentFieldNameOverridden","collectionSpecific","typeFieldName","fieldName","undefined","allowHasMany","sanitizedRelatedCollections","selfParentField","fields","find","field","name","type","relationTo","custom","injectHeaderButton","collection","hierarchyCollectionSlug","hierarchyField","fieldHasMany","hasMany","injectCollectionSpecificValidation","hierarchySlug","injectTypeField","joinField","injectJoinField","joinFieldConfig","relatedSlugs","Object","keys","relatedCollections","length","injectAfterDeleteHook","admin","injectSidebarTab","group","existingValidate","validate","value","options","existingResult","collectionSlug","overrideAccess","previousValue","req","newID","parentItem","payload","findByID","id","depth","select","allowedTypes","includes","collectionOptions","map","relatedCollection","c","label","labels","plural","typeField","components","Field","path","serverProps","position","push","flattenedFields","userAdmin","userConfig","hasJoinField","some","on","joins","parentIsLocalized","polymorphicJoins","relatedCollectionFieldMap","relatedConfig","entries","hooks","afterDelete","tabSlug","Icon","sidebar","tabs","hasTab","tab","Content","clientProps"],"mappings":"AAgBA,SAASA,iBAAiB,QAAQ,wCAAuC;AACzE,SAASC,gBAAgB,QAAQ,4BAA2B;AAC5D,SAASC,SAAS,QAAQ,4BAA2B;AACrD,SAASC,gBAAgB,QAAQ,mCAAkC;AACnE,SAASC,qBAAqB,QAAQ,iBAAgB;AACtD,SAASC,8BAA8B,QAAQ,mCAAkC;AACjF,SAASC,qBAAqB,QAAQ,6BAA4B;AAElE;;;;;;;;;;;;;;;;;;;CAmBC,GACD,OAAO,MAAMC,8BAA8B,CAACC;IAC1C,MAAMC,uBACJD,OAAOE,WAAW,EAAEC,OAAO,CAACC,MAAQA,IAAIC,SAAS,IAAI,OAAOD,IAAIC,SAAS,KAAK,aAAa,EAAE;IAE/F,KAAK,MAAMC,uBAAuBL,qBAAsB;QACtD,MAAMI,YAAYC,oBAAoBD,SAAS;QAE/C,iFAAiF;QACjF,IAAI,CAACA,aAAa,OAAOA,cAAc,UAAU;YAC/C;QACF;QAEA,MAAME,kBAAkBF;QACxB,MAAMG,mBAAmBZ,sBAAsBU,oBAAoBG,IAAI;QACvE,MAAMC,kBAAkBH,gBAAgBG,eAAe,IAAIF;QAC3D,MAAMG,8BAA8BD,oBAAoBF;QACxD,MAAMI,qBAAqBL,gBAAgBK,kBAAkB;QAC7D,MAAMC,gBAAgBD,qBAAqBA,mBAAmBE,SAAS,GAAGC;QAC1E,MAAMC,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AAU,IAAI,CAAC;IACtDzE,OAAO4C,KAAK,CAAC6B,UAAU,CAACsB,OAAO,GAAG/F,OAAO4C,KAAK,CAAC6B,UAAU,CAACsB,OAAO,IAAI,CAAC;IACtE/F,OAAO4C,KAAK,CAAC6B,UAAU,CAACsB,OAAO,CAACC,IAAI,GAAGhG,OAAO4C,KAAK,CAAC6B,UAAU,CAACsB,OAAO,CAACC,IAAI,IAAI,EAAE;IAEjF,8BAA8B;IAC9B,MAAMC,SAASjG,OAAO4C,KAAK,CAAC6B,UAAU,CAACsB,OAAO,CAACC,IAAI,CAACb,IAAI,CAAC,CAACe,MAAQA,IAAIzF,IAAI,KAAKoF;IAE/E,IAAI,CAACI,QAAQ;QACXjG,OAAO4C,KAAK,CAAC6B,UAAU,CAACsB,OAAO,CAACC,IAAI,CAAClB,IAAI,CAAC;YACxCrE,MAAMoF;YACNpB,YAAY;gBACV0B,SAAS;oBACPC,aAAa;wBACXxE,yBAAyBtB,oBAAoBG,IAAI;oBACnD;oBACAkE,MAAM;gBACR;gBACAmB;YACF;YACAzB,OAAO/D,oBAAoBgE,MAAM,EAAEC,UAAUjE,oBAAoBG,IAAI;QACvE;IACF;AACF"}
@@ -0,0 +1,14 @@
1
+ import type { CollectionConfig } from '../collections/config/types.js';
2
+ import type { Config } from '../config/types.js';
3
+ /**
4
+ * Sanitizes hierarchy configuration for a single collection.
5
+ *
6
+ * This is phase 1 of hierarchy setup, called during individual collection sanitization.
7
+ * It normalizes the hierarchy config, creates the parent field if needed, adds hooks,
8
+ * and sets up the sanitized config structure.
9
+ *
10
+ * Phase 2 (`resolveHierarchyCollections`) runs after all collections are sanitized
11
+ * to establish cross-collection relationships.
12
+ */
13
+ export declare const sanitizeHierarchyCollection: (collectionConfig: CollectionConfig, _config: Config) => void;
14
+ //# sourceMappingURL=sanitizeHierarchyCollection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sanitizeHierarchyCollection.d.ts","sourceRoot":"","sources":["../../src/hierarchy/sanitizeHierarchyCollection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAA;AACtE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAgBhD;;;;;;;;;GASG;AACH,eAAO,MAAM,2BAA2B,qBACpB,gBAAgB,WACzB,MAAM,KACd,IAkIF,CAAA"}
@@ -0,0 +1,117 @@
1
+ import { fieldAffectsData } from '../fields/config/types.js';
2
+ import { slugify as defaultSlugify } from '../utilities/slugify.js';
3
+ import { addHierarchyToCollection } from './addHierarchyToCollection.js';
4
+ import { buildParentField } from './buildParentField.js';
5
+ import { DEFAULT_ALLOW_HAS_MANY, DEFAULT_HIERARCHY_TREE_LIMIT, getHierarchyFieldName, HIERARCHY_SLUG_PATH_FIELD, HIERARCHY_TITLE_PATH_FIELD } from './constants.js';
6
+ import { ensureSafeCollectionsChange } from './hooks/ensureSafeCollectionsChange.js';
7
+ /**
8
+ * Sanitizes hierarchy configuration for a single collection.
9
+ *
10
+ * This is phase 1 of hierarchy setup, called during individual collection sanitization.
11
+ * It normalizes the hierarchy config, creates the parent field if needed, adds hooks,
12
+ * and sets up the sanitized config structure.
13
+ *
14
+ * Phase 2 (`resolveHierarchyCollections`) runs after all collections are sanitized
15
+ * to establish cross-collection relationships.
16
+ */ export const sanitizeHierarchyCollection = (collectionConfig, _config)=>{
17
+ if (!collectionConfig.hierarchy) {
18
+ collectionConfig.hierarchy = false;
19
+ return;
20
+ }
21
+ // Normalize boolean to object and apply parentFieldName default
22
+ const defaultParentFieldName = getHierarchyFieldName(collectionConfig.slug);
23
+ if (collectionConfig.hierarchy === true) {
24
+ collectionConfig.hierarchy = {
25
+ parentFieldName: defaultParentFieldName
26
+ };
27
+ }
28
+ const parentFieldName = collectionConfig.hierarchy.parentFieldName ?? defaultParentFieldName;
29
+ // Check if parent field already exists
30
+ const existingParentField = collectionConfig.fields.find((field)=>fieldAffectsData(field) && field.name === parentFieldName);
31
+ if (existingParentField) {
32
+ // Validate existing parent field configuration
33
+ if (existingParentField.type !== 'relationship') {
34
+ throw new Error(`Hierarchy parent field "${parentFieldName}" in collection "${collectionConfig.slug}" must be a relationship field`);
35
+ }
36
+ if (existingParentField.hasMany !== false) {
37
+ throw new Error(`Hierarchy parent field "${parentFieldName}" in collection "${collectionConfig.slug}" must have hasMany set to false`);
38
+ }
39
+ if (existingParentField.localized === true) {
40
+ throw new Error(`Hierarchy parent field "${parentFieldName}" in collection "${collectionConfig.slug}" cannot be localized. The parent relationship must be consistent across all locales.`);
41
+ }
42
+ } else {
43
+ // Auto-create parent field if it doesn't exist
44
+ // useHeaderButton defaults to true - parent selection via header button with miller columns
45
+ const useHeaderButton = collectionConfig.hierarchy.admin?.useHeaderButton ?? true;
46
+ const parentField = buildParentField({
47
+ collectionSlug: collectionConfig.slug,
48
+ injectHeaderButton: useHeaderButton,
49
+ parentFieldName
50
+ });
51
+ collectionConfig.fields.unshift(parentField);
52
+ }
53
+ // Apply defaults for optional fields
54
+ const slugPathFieldName = collectionConfig.hierarchy.slugPathFieldName || HIERARCHY_SLUG_PATH_FIELD;
55
+ const titlePathFieldName = collectionConfig.hierarchy.titlePathFieldName || HIERARCHY_TITLE_PATH_FIELD;
56
+ const allowHasMany = collectionConfig.hierarchy.allowHasMany ?? DEFAULT_ALLOW_HAS_MANY;
57
+ const rawCollectionSpecific = collectionConfig.hierarchy.collectionSpecific;
58
+ const collectionSpecific = rawCollectionSpecific === true ? {
59
+ fieldName: 'hierarchyType'
60
+ } : rawCollectionSpecific ? {
61
+ fieldName: rawCollectionSpecific.fieldName ?? 'hierarchyType'
62
+ } : false;
63
+ const joinField = collectionConfig.hierarchy.joinField ? collectionConfig.hierarchy.joinField : undefined;
64
+ const slugify = collectionConfig.hierarchy.slugify ?? ((text)=>defaultSlugify(text) ?? '');
65
+ const treeLimit = collectionConfig.hierarchy.admin?.treeLimit ?? DEFAULT_HIERARCHY_TREE_LIMIT;
66
+ const iconComponent = collectionConfig.hierarchy.admin?.components?.Icon;
67
+ const slugField = collectionConfig.hierarchy.slugField;
68
+ // Apply hierarchy to collection (adds fields and hooks)
69
+ addHierarchyToCollection({
70
+ collectionConfig,
71
+ parentFieldName: collectionConfig.hierarchy.parentFieldName,
72
+ slugFieldName: slugField,
73
+ slugPathFieldName,
74
+ titlePathFieldName
75
+ });
76
+ // If collectionSpecific, add beforeValidate hook to enforce scope inheritance
77
+ // (hierarchyType field is added in resolveHierarchyCollections after discovery)
78
+ if (collectionSpecific) {
79
+ // Use parentFieldName for both - backward compatible configs use the same field name everywhere
80
+ if (!collectionConfig.hooks) {
81
+ collectionConfig.hooks = {};
82
+ }
83
+ if (!collectionConfig.hooks.beforeValidate) {
84
+ collectionConfig.hooks.beforeValidate = [];
85
+ }
86
+ collectionConfig.hooks.beforeValidate.push(ensureSafeCollectionsChange({
87
+ folderFieldName: parentFieldName,
88
+ foldersSlug: collectionConfig.slug,
89
+ parentFieldName,
90
+ typeFieldName: collectionSpecific.fieldName
91
+ }));
92
+ }
93
+ // Set sanitized hierarchy config (cast needed as we're transitioning from HierarchyConfig to SanitizedHierarchyConfig)
94
+ const useHeaderButton = collectionConfig.hierarchy.admin?.useHeaderButton ?? false;
95
+ const injectSidebarTab = collectionConfig.hierarchy.admin?.injectSidebarTab ?? true;
96
+ collectionConfig.hierarchy = {
97
+ admin: {
98
+ components: {
99
+ Icon: iconComponent || '@payloadcms/ui#TagIcon'
100
+ },
101
+ injectSidebarTab,
102
+ treeLimit,
103
+ useHeaderButton
104
+ },
105
+ allowHasMany,
106
+ collectionSpecific,
107
+ joinField,
108
+ parentFieldName,
109
+ relatedCollections: {},
110
+ slugField,
111
+ slugify,
112
+ slugPathFieldName,
113
+ titlePathFieldName
114
+ };
115
+ };
116
+
117
+ //# sourceMappingURL=sanitizeHierarchyCollection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/hierarchy/sanitizeHierarchyCollection.ts"],"sourcesContent":["import type { CollectionConfig } from '../collections/config/types.js'\nimport type { Config } from '../config/types.js'\nimport type { SanitizedHierarchyConfig } from './types.js'\n\nimport { fieldAffectsData } from '../fields/config/types.js'\nimport { slugify as defaultSlugify } from '../utilities/slugify.js'\nimport { addHierarchyToCollection } from './addHierarchyToCollection.js'\nimport { buildParentField } from './buildParentField.js'\nimport {\n DEFAULT_ALLOW_HAS_MANY,\n DEFAULT_HIERARCHY_TREE_LIMIT,\n getHierarchyFieldName,\n HIERARCHY_SLUG_PATH_FIELD,\n HIERARCHY_TITLE_PATH_FIELD,\n} from './constants.js'\nimport { ensureSafeCollectionsChange } from './hooks/ensureSafeCollectionsChange.js'\n\n/**\n * Sanitizes hierarchy configuration for a single collection.\n *\n * This is phase 1 of hierarchy setup, called during individual collection sanitization.\n * It normalizes the hierarchy config, creates the parent field if needed, adds hooks,\n * and sets up the sanitized config structure.\n *\n * Phase 2 (`resolveHierarchyCollections`) runs after all collections are sanitized\n * to establish cross-collection relationships.\n */\nexport const sanitizeHierarchyCollection = (\n collectionConfig: CollectionConfig,\n _config: Config,\n): void => {\n if (!collectionConfig.hierarchy) {\n collectionConfig.hierarchy = false\n return\n }\n\n // Normalize boolean to object and apply parentFieldName default\n const defaultParentFieldName = getHierarchyFieldName(collectionConfig.slug)\n\n if (collectionConfig.hierarchy === true) {\n collectionConfig.hierarchy = {\n parentFieldName: defaultParentFieldName,\n }\n }\n\n const parentFieldName = collectionConfig.hierarchy.parentFieldName ?? defaultParentFieldName\n\n // Check if parent field already exists\n const existingParentField = collectionConfig.fields.find(\n (field) => fieldAffectsData(field) && field.name === parentFieldName,\n )\n\n if (existingParentField) {\n // Validate existing parent field configuration\n if (existingParentField.type !== 'relationship') {\n throw new Error(\n `Hierarchy parent field \"${parentFieldName}\" in collection \"${collectionConfig.slug}\" must be a relationship field`,\n )\n }\n\n if (existingParentField.hasMany !== false) {\n throw new Error(\n `Hierarchy parent field \"${parentFieldName}\" in collection \"${collectionConfig.slug}\" must have hasMany set to false`,\n )\n }\n\n if (existingParentField.localized === true) {\n throw new Error(\n `Hierarchy parent field \"${parentFieldName}\" in collection \"${collectionConfig.slug}\" cannot be localized. The parent relationship must be consistent across all locales.`,\n )\n }\n } else {\n // Auto-create parent field if it doesn't exist\n // useHeaderButton defaults to true - parent selection via header button with miller columns\n const useHeaderButton = collectionConfig.hierarchy.admin?.useHeaderButton ?? true\n\n const parentField = buildParentField({\n collectionSlug: collectionConfig.slug,\n injectHeaderButton: useHeaderButton,\n parentFieldName,\n })\n\n collectionConfig.fields.unshift(parentField)\n }\n\n // Apply defaults for optional fields\n const slugPathFieldName =\n collectionConfig.hierarchy.slugPathFieldName || HIERARCHY_SLUG_PATH_FIELD\n const titlePathFieldName =\n collectionConfig.hierarchy.titlePathFieldName || HIERARCHY_TITLE_PATH_FIELD\n const allowHasMany = collectionConfig.hierarchy.allowHasMany ?? DEFAULT_ALLOW_HAS_MANY\n const rawCollectionSpecific = collectionConfig.hierarchy.collectionSpecific\n const collectionSpecific: { fieldName: string } | false =\n rawCollectionSpecific === true\n ? { fieldName: 'hierarchyType' }\n : rawCollectionSpecific\n ? { fieldName: rawCollectionSpecific.fieldName ?? 'hierarchyType' }\n : false\n const joinField = collectionConfig.hierarchy.joinField\n ? collectionConfig.hierarchy.joinField\n : undefined\n const slugify =\n collectionConfig.hierarchy.slugify ?? ((text: string) => defaultSlugify(text) ?? '')\n const treeLimit = collectionConfig.hierarchy.admin?.treeLimit ?? DEFAULT_HIERARCHY_TREE_LIMIT\n const iconComponent = collectionConfig.hierarchy.admin?.components?.Icon\n\n const slugField = collectionConfig.hierarchy.slugField\n\n // Apply hierarchy to collection (adds fields and hooks)\n addHierarchyToCollection({\n collectionConfig,\n parentFieldName: collectionConfig.hierarchy.parentFieldName,\n slugFieldName: slugField,\n slugPathFieldName,\n titlePathFieldName,\n })\n\n // If collectionSpecific, add beforeValidate hook to enforce scope inheritance\n // (hierarchyType field is added in resolveHierarchyCollections after discovery)\n if (collectionSpecific) {\n // Use parentFieldName for both - backward compatible configs use the same field name everywhere\n if (!collectionConfig.hooks) {\n collectionConfig.hooks = {}\n }\n if (!collectionConfig.hooks.beforeValidate) {\n collectionConfig.hooks.beforeValidate = []\n }\n collectionConfig.hooks.beforeValidate.push(\n ensureSafeCollectionsChange({\n folderFieldName: parentFieldName,\n foldersSlug: collectionConfig.slug,\n parentFieldName,\n typeFieldName: collectionSpecific.fieldName,\n }),\n )\n }\n\n // Set sanitized hierarchy config (cast needed as we're transitioning from HierarchyConfig to SanitizedHierarchyConfig)\n const useHeaderButton = collectionConfig.hierarchy.admin?.useHeaderButton ?? false\n const injectSidebarTab = collectionConfig.hierarchy.admin?.injectSidebarTab ?? true\n\n ;(collectionConfig as unknown as { hierarchy: SanitizedHierarchyConfig }).hierarchy = {\n admin: {\n components: {\n Icon: iconComponent || '@payloadcms/ui#TagIcon',\n },\n injectSidebarTab,\n treeLimit,\n useHeaderButton,\n },\n allowHasMany,\n collectionSpecific,\n joinField,\n parentFieldName,\n relatedCollections: {},\n slugField,\n slugify,\n slugPathFieldName,\n titlePathFieldName,\n }\n}\n"],"names":["fieldAffectsData","slugify","defaultSlugify","addHierarchyToCollection","buildParentField","DEFAULT_ALLOW_HAS_MANY","DEFAULT_HIERARCHY_TREE_LIMIT","getHierarchyFieldName","HIERARCHY_SLUG_PATH_FIELD","HIERARCHY_TITLE_PATH_FIELD","ensureSafeCollectionsChange","sanitizeHierarchyCollection","collectionConfig","_config","hierarchy","defaultParentFieldName","slug","parentFieldName","existingParentField","fields","find","field","name","type","Error","hasMany","localized","useHeaderButton","admin","parentField","collectionSlug","injectHeaderButton","unshift","slugPathFieldName","titlePathFieldName","allowHasMany","rawCollectionSpecific","collectionSpecific","fieldName","joinField","undefined","text","treeLimit","iconComponent","components","Icon","slugField","slugFieldName","hooks","beforeValidate","push","folderFieldName","foldersSlug","typeFieldName","injectSidebarTab","relatedCollections"],"mappings":"AAIA,SAASA,gBAAgB,QAAQ,4BAA2B;AAC5D,SAASC,WAAWC,cAAc,Q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GAAG,CAAC;QAC5B;QACA,IAAI,CAACpC,iBAAiBoC,KAAK,CAACC,cAAc,EAAE;YAC1CrC,iBAAiBoC,KAAK,CAACC,cAAc,GAAG,EAAE;QAC5C;QACArC,iBAAiBoC,KAAK,CAACC,cAAc,CAACC,IAAI,CACxCxC,4BAA4B;YAC1ByC,iBAAiBlC;YACjBmC,aAAaxC,iBAAiBI,IAAI;YAClCC;YACAoC,eAAehB,mBAAmBC,SAAS;QAC7C;IAEJ;IAEA,uHAAuH;IACvH,MAAMX,kBAAkBf,iBAAiBE,SAAS,CAACc,KAAK,EAAED,mBAAmB;IAC7E,MAAM2B,mBAAmB1C,iBAAiBE,SAAS,CAACc,KAAK,EAAE0B,oBAAoB;IAE7E1C,iBAAwEE,SAAS,GAAG;QACpFc,OAAO;YACLgB,YAAY;gBACVC,MAAMF,iBAAiB;YACzB;YACAW;YACAZ;YACAf;QACF;QACAQ;QACAE;QACAE;QACAtB;QACAsC,oBAAoB,CAAC;QACrBT;QACA7C;QACAgC;QACAC;IACF;AACF,EAAC"}
@@ -0,0 +1,155 @@
1
+ import type { PayloadComponent } from '../config/types.js';
2
+ import type { JoinField } from '../fields/config/types.js';
3
+ /**
4
+ * User-configurable options for the hierarchy join field.
5
+ * Excludes properties that are auto-generated: type, collection, on, hasMany
6
+ */
7
+ export type HierarchyJoinFieldConfig = {
8
+ name: string;
9
+ } & Omit<Partial<JoinField>, 'collection' | 'hasMany' | 'name' | 'on' | 'type'>;
10
+ /**
11
+ * Configuration options for hierarchy feature
12
+ *
13
+ * Hierarchies are always self-referential - documents can only nest under other documents
14
+ * from the same collection.
15
+ */
16
+ export type HierarchyConfig = {
17
+ /**
18
+ * UI configuration for hierarchy
19
+ */
20
+ admin?: {
21
+ /**
22
+ * Custom components for hierarchy UI
23
+ */
24
+ components?: {
25
+ /**
26
+ * Custom icon component for hierarchy items
27
+ */
28
+ Icon?: PayloadComponent;
29
+ };
30
+ /**
31
+ * Whether to inject a sidebar tab for this hierarchy collection
32
+ * @default true
33
+ */
34
+ injectSidebarTab?: boolean;
35
+ /**
36
+ * Maximum number of items to load in tree views
37
+ * @default 100
38
+ */
39
+ treeLimit?: number;
40
+ /**
41
+ * Whether to use a header button for parent selection instead of inline field.
42
+ * When true, the parent field is hidden and a button is injected into the document header.
43
+ * @default true
44
+ */
45
+ useHeaderButton?: boolean;
46
+ };
47
+ /**
48
+ * Whether related documents can have multiple values of this hierarchy
49
+ * Set to false for folder-like behavior (single parent), true for tag-like behavior (multiple)
50
+ * @default true
51
+ */
52
+ allowHasMany?: boolean;
53
+ /**
54
+ * Whether this hierarchy is scoped to specific collections
55
+ * When true or an object, hierarchy items can be restricted to certain collections
56
+ * @default false
57
+ */
58
+ collectionSpecific?: {
59
+ /**
60
+ * Name of the select field for specifying allowed collections
61
+ * @default 'hierarchyType'
62
+ */
63
+ fieldName?: string;
64
+ } | boolean;
65
+ /**
66
+ * Configure a join field to query all children (nested hierarchy items and related documents)
67
+ * If not set, no join field is created.
68
+ * You can pass additional JoinField options (admin, defaultLimit, defaultSort, etc.)
69
+ * that will be merged with the auto-generated config.
70
+ */
71
+ joinField?: HierarchyJoinFieldConfig;
72
+ /**
73
+ * Name of the field that references the parent document
74
+ * Will automatically create this field if it does not exist
75
+ * @default '_h_${collectionSlug}' (e.g., '_h_folders' for a collection with slug 'folders')
76
+ */
77
+ parentFieldName: string;
78
+ /**
79
+ * Name of the field to use for slug path generation.
80
+ * When set, uses this field's value directly instead of slugifying the title.
81
+ * Useful when you have a dedicated slug field (e.g., 'slug') separate from the title.
82
+ * @example 'slug' - uses the 'slug' field value as-is for path segments
83
+ */
84
+ slugField?: string;
85
+ /**
86
+ * Custom function to slugify text for path generation
87
+ * Used by computeSlugPath() utility for generating slug-based breadcrumb paths
88
+ * Only used when slugField is not set.
89
+ * Defaults to internal slugify implementation
90
+ */
91
+ slugify?: (text: string) => string;
92
+ /**
93
+ * Name of the virtual field that will contain the slug-based breadcrumb path
94
+ * @default HIERARCHY_SLUG_PATH_FIELD ('_h_slugPath')
95
+ */
96
+ slugPathFieldName?: string;
97
+ /**
98
+ * Name of the virtual field that will contain the title-based breadcrumb path
99
+ * @default HIERARCHY_TITLE_PATH_FIELD ('_h_titlePath')
100
+ */
101
+ titlePathFieldName?: string;
102
+ };
103
+ /**
104
+ * Sanitized hierarchy configuration with all defaults applied
105
+ */
106
+ export type SanitizedHierarchyConfig = {
107
+ admin: {
108
+ components: {
109
+ Icon: PayloadComponent;
110
+ };
111
+ injectSidebarTab: boolean;
112
+ treeLimit: number;
113
+ useHeaderButton: boolean;
114
+ };
115
+ allowHasMany: boolean;
116
+ collectionSpecific: {
117
+ fieldName: string;
118
+ } | false;
119
+ /**
120
+ * Join field configuration, or undefined if not enabled
121
+ */
122
+ joinField?: HierarchyJoinFieldConfig;
123
+ parentFieldName: string;
124
+ /**
125
+ * Auto-populated during validation - maps collection slug to field info
126
+ */
127
+ relatedCollections: Record<string, SanitizedHierarchyRelatedCollection>;
128
+ /**
129
+ * Field name for slug values, or undefined to use slugified title
130
+ */
131
+ slugField?: string;
132
+ slugify: (text: string) => string;
133
+ slugPathFieldName: string;
134
+ titlePathFieldName: string;
135
+ };
136
+ /**
137
+ * Information about how a collection relates to this hierarchy
138
+ */
139
+ export type SanitizedHierarchyRelatedCollection = {
140
+ fieldName: string;
141
+ hasMany: boolean;
142
+ };
143
+ /**
144
+ * Client-safe hierarchy configuration (excludes functions that can't cross server-client boundary)
145
+ */
146
+ export type ClientHierarchyConfig = Omit<SanitizedHierarchyConfig, 'slugify'>;
147
+ /**
148
+ * Breadcrumb item for folder hierarchies
149
+ * @deprecated Use hierarchy breadcrumbs instead
150
+ */
151
+ export type FolderBreadcrumb = {
152
+ id: number | string;
153
+ name: string;
154
+ };
155
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/hierarchy/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,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AAgB,CAAA;SACvB,CAAA;QACD,gBAAgB,EAAE,OAAO,CAAA;QACzB,SAAS,EAAE,MAAM,CAAA;QACjB,eAAe,EAAE,OAAO,CAAA;KACzB,CAAA;IACD,YAAY,EAAE,OAAO,CAAA;IACrB,kBAAkB,EACd;QACE,SAAS,EAAE,MAAM,CAAA;KAClB,GACD,KAAK,CAAA;IACT;;OAEG;IACH,SAAS,CAAC,EAAE,wBAAwB,CAAA;IACpC,eAAe,EAAE,MAAM,CAAA;IACvB;;OAEG;IACH,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,mCAAmC,CAAC,CAAA;IACvE;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAA;IACjC,iBAAiB,EAAE,MAAM,CAAA;IACzB,kBAAkB,EAAE,MAAM,CAAA;CAC3B,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,mCAAmC,GAAG;IAChD,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,OAAO,CAAA;CACjB,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG,IAAI,CAAC,wBAAwB,EAAE,SAAS,CAAC,CAAA;AAE7E;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;IACnB,IAAI,EAAE,MAAM,CAAA;CACb,CAAA"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Breadcrumb item for folder hierarchies
3
+ * @deprecated Use hierarchy breadcrumbs instead
4
+ */ export { };
5
+
6
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/hierarchy/types.ts"],"sourcesContent":["import type { PayloadComponent } from '../config/types.js'\nimport type { JoinField } from '../fields/config/types.js'\n\n/**\n * User-configurable options for the hierarchy join field.\n * Excludes properties that are auto-generated: type, collection, on, hasMany\n */\nexport type HierarchyJoinFieldConfig = {\n name: string\n} & Omit<Partial<JoinField>, 'collection' | 'hasMany' | 'name' | 'on' | 'type'>\n\n/**\n * Configuration options for hierarchy feature\n *\n * Hierarchies are always self-referential - documents can only nest under other documents\n * from the same collection.\n */\nexport type HierarchyConfig = {\n /**\n * UI configuration for hierarchy\n */\n admin?: {\n /**\n * Custom components for hierarchy UI\n */\n components?: {\n /**\n * Custom icon component for hierarchy items\n */\n Icon?: PayloadComponent\n }\n /**\n * Whether to inject a sidebar tab for this hierarchy collection\n * @default true\n */\n injectSidebarTab?: boolean\n /**\n * Maximum number of items to load in tree views\n * @default 100\n */\n treeLimit?: number\n /**\n * Whether to use a header button for parent selection instead of inline field.\n * When true, the parent field is hidden and a button is injected into the document header.\n * @default true\n */\n useHeaderButton?: boolean\n }\n /**\n * Whether related documents can have multiple values of this hierarchy\n * Set to false for folder-like behavior (single parent), true for tag-like behavior (multiple)\n * @default true\n */\n allowHasMany?: boolean\n /**\n * Whether this hierarchy is scoped to specific collections\n * When true or an object, hierarchy items can be restricted to certain collections\n * @default false\n */\n collectionSpecific?:\n | {\n /**\n * Name of the select field for specifying allowed collections\n * @default 'hierarchyType'\n */\n fieldName?: string\n }\n | boolean\n /**\n * Configure a join field to query all children (nested hierarchy items and related documents)\n * If not set, no join field is created.\n * You can pass additional JoinField options (admin, defaultLimit, defaultSort, etc.)\n * that will be merged with the auto-generated config.\n */\n joinField?: HierarchyJoinFieldConfig\n /**\n * Name of the field that references the parent document\n * Will automatically create this field if it does not exist\n * @default '_h_${collectionSlug}' (e.g., '_h_folders' for a collection with slug 'folders')\n */\n parentFieldName: string\n /**\n * Name of the field to use for slug path generation.\n * When set, uses this field's value directly instead of slugifying the title.\n * Useful when you have a dedicated slug field (e.g., 'slug') separate from the title.\n * @example 'slug' - uses the 'slug' field value as-is for path segments\n */\n slugField?: string\n /**\n * Custom function to slugify text for path generation\n * Used by computeSlugPath() utility for generating slug-based breadcrumb paths\n * Only used when slugField is not set.\n * Defaults to internal slugify implementation\n */\n slugify?: (text: string) => string\n /**\n * Name of the virtual field that will contain the slug-based breadcrumb path\n * @default HIERARCHY_SLUG_PATH_FIELD ('_h_slugPath')\n */\n slugPathFieldName?: string\n /**\n * Name of the virtual field that will contain the title-based breadcrumb path\n * @default HIERARCHY_TITLE_PATH_FIELD ('_h_titlePath')\n */\n titlePathFieldName?: string\n}\n\n/**\n * Sanitized hierarchy configuration with all defaults applied\n */\nexport type SanitizedHierarchyConfig = {\n admin: {\n components: {\n Icon: PayloadComponent\n }\n injectSidebarTab: boolean\n treeLimit: number\n useHeaderButton: boolean\n }\n allowHasMany: boolean\n collectionSpecific:\n | {\n fieldName: string\n }\n | false\n /**\n * Join field configuration, or undefined if not enabled\n */\n joinField?: HierarchyJoinFieldConfig\n parentFieldName: string\n /**\n * Auto-populated during validation - maps collection slug to field info\n */\n relatedCollections: Record<string, SanitizedHierarchyRelatedCollection>\n /**\n * Field name for slug values, or undefined to use slugified title\n */\n slugField?: string\n slugify: (text: string) => string\n slugPathFieldName: string\n titlePathFieldName: string\n}\n\n/**\n * Information about how a collection relates to this hierarchy\n */\nexport type SanitizedHierarchyRelatedCollection = {\n fieldName: string\n hasMany: boolean\n}\n\n/**\n * Client-safe hierarchy configuration (excludes functions that can't cross server-client boundary)\n */\nexport type ClientHierarchyConfig = Omit<SanitizedHierarchyConfig, 'slugify'>\n\n/**\n * Breadcrumb item for folder hierarchies\n * @deprecated Use hierarchy breadcrumbs instead\n */\nexport type FolderBreadcrumb = {\n id: number | string\n name: string\n}\n"],"names":[],"mappings":"AA4JA;;;CAGC,GACD,WAGC"}
@@ -0,0 +1,77 @@
1
+ import type { PayloadRequest } from '../../types/index.js';
2
+ type BuildLocalizedPathsArgs = {
3
+ /**
4
+ * Optional parent's slug paths by locale (e.g., { en: "/blog/tech", es: "/blog/tecnologia" })
5
+ * If provided, these paths will be prepended to the generated slug segments
6
+ */
7
+ parentSlugPath?: Record<string, string>;
8
+ /**
9
+ * Optional parent's title paths by locale (e.g., { en: "Blog / Tech", es: "Blog / Tecnología" })
10
+ * If provided, these paths will be prepended to the generated title segments
11
+ */
12
+ parentTitlePath?: Record<string, string>;
13
+ /**
14
+ * The Payload request object - used to access locale configuration and fallback settings
15
+ */
16
+ req: PayloadRequest;
17
+ /**
18
+ * Function to convert title text into URL-safe slug segments.
19
+ * Only used when slugValue is not provided.
20
+ */
21
+ slugify: (val: string) => string;
22
+ /**
23
+ * Optional pre-computed slug value by locale.
24
+ * When provided, uses these values directly instead of slugifying the title.
25
+ */
26
+ slugValue?: Record<string, string>;
27
+ /**
28
+ * The localized title value object (e.g., { en: "Home", es: "Inicio", de: "Startseite" })
29
+ */
30
+ titleValue: Record<string, string>;
31
+ };
32
+ type BuildLocalizedPathsResult = {
33
+ slugPath: Record<string, string>;
34
+ titlePath: Record<string, string>;
35
+ };
36
+ /**
37
+ * Builds localized slug and title paths for all configured locales.
38
+ * Applies proper fallback locale handling and optionally prepends parent paths.
39
+ *
40
+ * This utility is used when `locale: 'all'` is requested and the title field is localized,
41
+ * generating a path for each locale with proper fallback handling.
42
+ *
43
+ * @example
44
+ * ```ts
45
+ * // Without parent (root document)
46
+ * buildLocalizedPaths({
47
+ * req,
48
+ * slugify: (val) => val.toLowerCase().replace(/\s/g, '-'),
49
+ * titleValue: { en: "Home", es: "Inicio", de: "" }
50
+ * })
51
+ * // Returns:
52
+ * // {
53
+ * // slugPath: { en: "home", es: "inicio", de: "home" }, // 'de' falls back to 'en'
54
+ * // titlePath: { en: "Home", es: "Inicio", de: "Home" }
55
+ * // }
56
+ *
57
+ * // With parent paths
58
+ * buildLocalizedPaths({
59
+ * parentSlugPath: { en: "/blog", es: "/blog" },
60
+ * parentTitlePath: { en: "Blog", es: "Blog" },
61
+ * req,
62
+ * slugify: (val) => val.toLowerCase().replace(/\s/g, '-'),
63
+ * titleValue: { en: "Tech News", es: "Noticias Tecnológicas" }
64
+ * })
65
+ * // Returns:
66
+ * // {
67
+ * // slugPath: { en: "/blog/tech-news", es: "/blog/noticias-tecnologicas" },
68
+ * // titlePath: { en: "Blog / Tech News", es: "Blog / Noticias Tecnológicas" }
69
+ * // }
70
+ * ```
71
+ *
72
+ * @param args - Configuration for building localized paths
73
+ * @returns Object containing slugPath and titlePath, each mapping locale codes to path strings
74
+ */
75
+ export declare function buildLocalizedHierarchyPaths(args: BuildLocalizedPathsArgs): BuildLocalizedPathsResult;
76
+ export {};
77
+ //# sourceMappingURL=buildLocalizedHierarchyPaths.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildLocalizedHierarchyPaths.d.ts","sourceRoot":"","sources":["../../../src/hierarchy/utils/buildLocalizedHierarchyPaths.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAI1D,KAAK,uBAAuB,GAAG;IAC7B;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACvC;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACxC;;OAEG;IACH,GAAG,EAAE,cAAc,CAAA;IACnB;;;OAGG;IACH,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAA;IAChC;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAClC;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CACnC,CAAA;AAED,KAAK,yBAAyB,GAAG;IAC/B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAChC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAClC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAgB,4BAA4B,CAC1C,IAAI,EAAE,uBAAuB,GAC5B,yBAAyB,CA6C3B"}
@@ -0,0 +1,77 @@
1
+ import { getLocalizedValue } from './getLocalizedValue.js';
2
+ /**
3
+ * Builds localized slug and title paths for all configured locales.
4
+ * Applies proper fallback locale handling and optionally prepends parent paths.
5
+ *
6
+ * This utility is used when `locale: 'all'` is requested and the title field is localized,
7
+ * generating a path for each locale with proper fallback handling.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * // Without parent (root document)
12
+ * buildLocalizedPaths({
13
+ * req,
14
+ * slugify: (val) => val.toLowerCase().replace(/\s/g, '-'),
15
+ * titleValue: { en: "Home", es: "Inicio", de: "" }
16
+ * })
17
+ * // Returns:
18
+ * // {
19
+ * // slugPath: { en: "home", es: "inicio", de: "home" }, // 'de' falls back to 'en'
20
+ * // titlePath: { en: "Home", es: "Inicio", de: "Home" }
21
+ * // }
22
+ *
23
+ * // With parent paths
24
+ * buildLocalizedPaths({
25
+ * parentSlugPath: { en: "/blog", es: "/blog" },
26
+ * parentTitlePath: { en: "Blog", es: "Blog" },
27
+ * req,
28
+ * slugify: (val) => val.toLowerCase().replace(/\s/g, '-'),
29
+ * titleValue: { en: "Tech News", es: "Noticias Tecnológicas" }
30
+ * })
31
+ * // Returns:
32
+ * // {
33
+ * // slugPath: { en: "/blog/tech-news", es: "/blog/noticias-tecnologicas" },
34
+ * // titlePath: { en: "Blog / Tech News", es: "Blog / Noticias Tecnológicas" }
35
+ * // }
36
+ * ```
37
+ *
38
+ * @param args - Configuration for building localized paths
39
+ * @returns Object containing slugPath and titlePath, each mapping locale codes to path strings
40
+ */ export function buildLocalizedHierarchyPaths(args) {
41
+ const { parentSlugPath, parentTitlePath, req, slugify, slugValue, titleValue } = args;
42
+ const slugPathsByLocale = {};
43
+ const titlePathsByLocale = {};
44
+ const locales = req.payload.config.localization ? req.payload.config.localization.localeCodes : [];
45
+ for (const loc of locales){
46
+ const localizedTitle = getLocalizedValue({
47
+ fallbackLocale: req.fallbackLocale,
48
+ fieldType: 'text',
49
+ locale: loc,
50
+ value: titleValue
51
+ });
52
+ if (localizedTitle) {
53
+ // Use provided slugValue if available, otherwise slugify the title
54
+ let slugSegment;
55
+ if (slugValue) {
56
+ const localizedSlug = getLocalizedValue({
57
+ fallbackLocale: req.fallbackLocale,
58
+ fieldType: 'text',
59
+ locale: loc,
60
+ value: slugValue
61
+ });
62
+ slugSegment = localizedSlug || slugify(localizedTitle);
63
+ } else {
64
+ slugSegment = slugify(localizedTitle);
65
+ }
66
+ const titleSegment = localizedTitle;
67
+ slugPathsByLocale[loc] = parentSlugPath ? `${parentSlugPath[loc]}/${slugSegment}` : slugSegment;
68
+ titlePathsByLocale[loc] = parentTitlePath ? `${parentTitlePath[loc]}/${titleSegment}` : titleSegment;
69
+ }
70
+ }
71
+ return {
72
+ slugPath: slugPathsByLocale,
73
+ titlePath: titlePathsByLocale
74
+ };
75
+ }
76
+
77
+ //# sourceMappingURL=buildLocalizedHierarchyPaths.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/hierarchy/utils/buildLocalizedHierarchyPaths.ts"],"sourcesContent":["import type { PayloadRequest } from '../../types/index.js'\n\nimport { getLocalizedValue } from './getLocalizedValue.js'\n\ntype BuildLocalizedPathsArgs = {\n /**\n * Optional parent's slug paths by locale (e.g., { en: \"/blog/tech\", es: \"/blog/tecnologia\" })\n * If provided, these paths will be prepended to the generated slug segments\n */\n parentSlugPath?: Record<string, string>\n /**\n * Optional parent's title paths by locale (e.g., { en: \"Blog / Tech\", es: \"Blog / Tecnología\" })\n * If provided, these paths will be prepended to the generated title segments\n */\n parentTitlePath?: Record<string, string>\n /**\n * The Payload request object - used to access locale configuration and fallback settings\n */\n req: PayloadRequest\n /**\n * Function to convert title text into URL-safe slug segments.\n * Only used when slugValue is not provided.\n */\n slugify: (val: string) => string\n /**\n * Optional pre-computed slug value by locale.\n * When provided, uses these values directly instead of slugifying the title.\n */\n slugValue?: Record<string, string>\n /**\n * The localized title value object (e.g., { en: \"Home\", es: \"Inicio\", de: \"Startseite\" })\n */\n titleValue: Record<string, string>\n}\n\ntype BuildLocalizedPathsResult = {\n slugPath: Record<string, string>\n titlePath: Record<string, string>\n}\n\n/**\n * Builds localized slug and title paths for all configured locales.\n * Applies proper fallback locale handling and optionally prepends parent paths.\n *\n * This utility is used when `locale: 'all'` is requested and the title field is localized,\n * generating a path for each locale with proper fallback handling.\n *\n * @example\n * ```ts\n * // Without parent (root document)\n * buildLocalizedPaths({\n * req,\n * slugify: (val) => val.toLowerCase().replace(/\\s/g, '-'),\n * titleValue: { en: \"Home\", es: \"Inicio\", de: \"\" }\n * })\n * // Returns:\n * // {\n * // slugPath: { en: \"home\", es: \"inicio\", de: \"home\" }, // 'de' falls back to 'en'\n * // titlePath: { en: \"Home\", es: \"Inicio\", de: \"Home\" }\n * // }\n *\n * // With parent paths\n * buildLocalizedPaths({\n * parentSlugPath: { en: \"/blog\", es: \"/blog\" },\n * parentTitlePath: { en: \"Blog\", es: \"Blog\" },\n * req,\n * slugify: (val) => val.toLowerCase().replace(/\\s/g, '-'),\n * titleValue: { en: \"Tech News\", es: \"Noticias Tecnológicas\" }\n * })\n * // Returns:\n * // {\n * // slugPath: { en: \"/blog/tech-news\", es: \"/blog/noticias-tecnologicas\" },\n * // titlePath: { en: \"Blog / Tech News\", es: \"Blog / Noticias Tecnológicas\" }\n * // }\n * ```\n *\n * @param args - Configuration for building localized paths\n * @returns Object containing slugPath and titlePath, each mapping locale codes to path strings\n */\nexport function buildLocalizedHierarchyPaths(\n args: BuildLocalizedPathsArgs,\n): BuildLocalizedPathsResult {\n const { parentSlugPath, parentTitlePath, req, slugify, slugValue, titleValue } = args\n\n const slugPathsByLocale: Record<string, string> = {}\n const titlePathsByLocale: Record<string, string> = {}\n\n const locales = req.payload.config.localization ? req.payload.config.localization.localeCodes : []\n\n for (const loc of locales) {\n const localizedTitle = getLocalizedValue({\n fallbackLocale: req.fallbackLocale,\n fieldType: 'text',\n locale: loc,\n value: titleValue,\n })\n\n if (localizedTitle) {\n // Use provided slugValue if available, otherwise slugify the title\n let slugSegment: string\n if (slugValue) {\n const localizedSlug = getLocalizedValue({\n fallbackLocale: req.fallbackLocale,\n fieldType: 'text',\n locale: loc,\n value: slugValue,\n })\n slugSegment = localizedSlug || slugify(localizedTitle)\n } else {\n slugSegment = slugify(localizedTitle)\n }\n const titleSegment = localizedTitle\n\n slugPathsByLocale[loc] = parentSlugPath\n ? `${parentSlugPath[loc]}/${slugSegment}`\n : slugSegment\n titlePathsByLocale[loc] = parentTitlePath\n ? `${parentTitlePath[loc]}/${titleSegment}`\n : titleSegment\n }\n }\n\n return {\n slugPath: slugPathsByLocale,\n titlePath: titlePathsByLocale,\n }\n}\n"],"names":["getLocalizedValue","buildLocalizedHierarchyPaths","args","parentSlugPath","parentTitlePath","req","slugify","slugValue","titleValue","slugPathsByLocale","titlePathsByLocale","locales","payload","config","localization","localeCodes","loc","localizedTitle","fallbackLocale","fieldType","locale","value","slugSegment","localizedSlug","titleSegment","slugPath","titlePath"],"mappings":"AAEA,SAASA,iBAAiB,QAAQ,yBAAwB;AAsC1D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsCC,GACD,OAAO,SAASC,6BACdC,IAA6B;IAE7B,MAAM,EAAEC,cAAc,EAAEC,eAAe,EAAEC,GAAG,EAAEC,OAAO,EAAEC,SAAS,EAAEC,UAAU,EAAE,GAAGN;IAEjF,MAAMO,oBAA4C,CAAC;IACnD,MAAMC,qBAA6C,CAAC;IAEpD,MAAMC,UAAUN,IAAIO,OAAO,CAACC,MAAM,CAACC,YAAY,GAAGT,IAAIO,OAAO,CAACC,MAAM,CAACC,YAAY,CAACC,WAAW,GAAG,EAAE;IAElG,KAAK,MAAMC,OAAOL,QAAS;QACzB,MAAMM,iBAAiBjB,kBAAkB;YACvCkB,gBAAgBb,IAAIa,cAAc;YAClCC,WAAW;YACXC,QAAQJ;YACRK,OAAOb;QACT;QAEA,IAAIS,gBAAgB;YAClB,mEAAmE;YACnE,IAAIK;YACJ,IAAIf,WAAW;gBACb,MAAMgB,gBAAgBvB,kBAAkB;oBACtCkB,gBAAgBb,IAAIa,cAAc;oBAClCC,WAAW;oBACXC,QAAQJ;oBACRK,OAAOd;gBACT;gBACAe,cAAcC,iBAAiBjB,QAAQW;YACzC,OAAO;gBACLK,cAAchB,QAAQW;YACxB;YACA,MAAMO,eAAeP;YAErBR,iBAAiB,CAACO,IAAI,GAAGb,iBACrB,GAAGA,cAAc,CAACa,IAAI,CAAC,CAAC,EAAEM,aAAa,GACvCA;YACJZ,kBAAkB,CAACM,IAAI,GAAGZ,kBACtB,GAAGA,eAAe,CAACY,IAAI,CAAC,CAAC,EAAEQ,cAAc,GACzCA;QACN;IACF;IAEA,OAAO;QACLC,UAAUhB;QACViB,WAAWhB;IACb;AACF"}
@@ -0,0 +1,31 @@
1
+ import type { SanitizedCollectionConfig } from '../../collections/config/types.js';
2
+ import type { Document, PayloadRequest } from '../../types/index.js';
3
+ type ComputePathsArgs = {
4
+ collection: SanitizedCollectionConfig;
5
+ doc: Document;
6
+ draft?: boolean;
7
+ locale?: string;
8
+ parentFieldName: string;
9
+ req: PayloadRequest;
10
+ slugPathFieldName?: string;
11
+ titlePathFieldName?: string;
12
+ };
13
+ type ComputePathsResult = {
14
+ slugPath: Record<string, string> | string;
15
+ titlePath: Record<string, string> | string;
16
+ };
17
+ /**
18
+ * Computes both slug and title breadcrumb paths for a document by walking up the parent chain.
19
+ * More efficient than computing them separately since it only walks the chain once.
20
+ *
21
+ * Note: Ancestor fetches always use `overrideAccess: true` to ensure paths are complete.
22
+ * If a user can read a document, they should see its full breadcrumb path even if they
23
+ * cannot read all ancestor documents. This prevents broken breadcrumbs and provides
24
+ * better UX at the cost of minimal information leakage (ancestor titles in paths).
25
+ *
26
+ * @param args - Configuration for path computation
27
+ * @returns Object with slugPath and titlePath
28
+ */
29
+ export declare function computePaths(args: ComputePathsArgs): Promise<ComputePathsResult>;
30
+ export {};
31
+ //# sourceMappingURL=computePaths.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"computePaths.d.ts","sourceRoot":"","sources":["../../../src/hierarchy/utils/computePaths.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAA;AAClF,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAQpE,KAAK,gBAAgB,GAAG;IACtB,UAAU,EAAE,yBAAyB,CAAA;IACrC,GAAG,EAAE,QAAQ,CAAA;IACb,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,eAAe,EAAE,MAAM,CAAA;IACvB,GAAG,EAAE,cAAc,CAAA;IACnB,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,kBAAkB,CAAC,EAAE,MAAM,CAAA;CAC5B,CAAA;AAED,KAAK,kBAAkB,GAAG;IACxB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAA;IACzC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAA;CAC3C,CAAA;AAgFD;;;;;;;;;;;GAWG;AACH,wBAAsB,YAAY,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CA2dtF"}