payload 3.80.0-internal-debug.4c84b90 → 3.80.0-internal.0311fce

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 (266) hide show
  1. package/dist/admin/elements/Nav.d.ts +10 -0
  2. package/dist/admin/elements/Nav.d.ts.map +1 -1
  3. package/dist/admin/elements/Nav.js.map +1 -1
  4. package/dist/admin/functions/index.d.ts +1 -38
  5. package/dist/admin/functions/index.d.ts.map +1 -1
  6. package/dist/admin/functions/index.js.map +1 -1
  7. package/dist/admin/types.d.ts +5 -4
  8. package/dist/admin/types.d.ts.map +1 -1
  9. package/dist/admin/types.js.map +1 -1
  10. package/dist/admin/views/hierarchyList.d.ts +9 -0
  11. package/dist/admin/views/hierarchyList.d.ts.map +1 -0
  12. package/dist/admin/views/hierarchyList.js +3 -0
  13. package/dist/admin/views/hierarchyList.js.map +1 -0
  14. package/dist/admin/views/index.d.ts +1 -3
  15. package/dist/admin/views/index.d.ts.map +1 -1
  16. package/dist/admin/views/index.js.map +1 -1
  17. package/dist/admin/views/list.d.ts +37 -1
  18. package/dist/admin/views/list.d.ts.map +1 -1
  19. package/dist/admin/views/list.js.map +1 -1
  20. package/dist/bin/generateImportMap/iterateCollections.d.ts.map +1 -1
  21. package/dist/bin/generateImportMap/iterateCollections.js +1 -0
  22. package/dist/bin/generateImportMap/iterateCollections.js.map +1 -1
  23. package/dist/bin/generateImportMap/iterateConfig.d.ts.map +1 -1
  24. package/dist/bin/generateImportMap/iterateConfig.js +7 -0
  25. package/dist/bin/generateImportMap/iterateConfig.js.map +1 -1
  26. package/dist/collections/config/client.d.ts +3 -1
  27. package/dist/collections/config/client.d.ts.map +1 -1
  28. package/dist/collections/config/client.js +11 -0
  29. package/dist/collections/config/client.js.map +1 -1
  30. package/dist/collections/config/defaults.js +1 -1
  31. package/dist/collections/config/defaults.js.map +1 -1
  32. package/dist/collections/config/sanitize.d.ts.map +1 -1
  33. package/dist/collections/config/sanitize.js +3 -7
  34. package/dist/collections/config/sanitize.js.map +1 -1
  35. package/dist/collections/config/types.d.ts +29 -7
  36. package/dist/collections/config/types.d.ts.map +1 -1
  37. package/dist/collections/config/types.js.map +1 -1
  38. package/dist/collections/operations/create.js +17 -17
  39. package/dist/collections/operations/create.js.map +1 -1
  40. package/dist/collections/operations/findByID.js +3 -3
  41. package/dist/collections/operations/findByID.js.map +1 -1
  42. package/dist/collections/operations/utilities/update.d.ts.map +1 -1
  43. package/dist/collections/operations/utilities/update.js +5 -4
  44. package/dist/collections/operations/utilities/update.js.map +1 -1
  45. package/dist/config/client.d.ts.map +1 -1
  46. package/dist/config/client.js +0 -10
  47. package/dist/config/client.js.map +1 -1
  48. package/dist/config/defaults.d.ts.map +1 -1
  49. package/dist/config/defaults.js +0 -15
  50. package/dist/config/defaults.js.map +1 -1
  51. package/dist/config/sanitize.d.ts.map +1 -1
  52. package/dist/config/sanitize.js +3 -26
  53. package/dist/config/sanitize.js.map +1 -1
  54. package/dist/config/types.d.ts +27 -13
  55. package/dist/config/types.d.ts.map +1 -1
  56. package/dist/config/types.js.map +1 -1
  57. package/dist/database/sanitizeJoinQuery.d.ts.map +1 -1
  58. package/dist/database/sanitizeJoinQuery.js +6 -0
  59. package/dist/database/sanitizeJoinQuery.js.map +1 -1
  60. package/dist/exports/shared.d.ts +2 -3
  61. package/dist/exports/shared.d.ts.map +1 -1
  62. package/dist/exports/shared.js +1 -2
  63. package/dist/exports/shared.js.map +1 -1
  64. package/dist/fields/config/sanitize.d.ts.map +1 -1
  65. package/dist/fields/config/sanitize.js +4 -0
  66. package/dist/fields/config/sanitize.js.map +1 -1
  67. package/dist/fields/config/sanitizeJoinField.d.ts.map +1 -1
  68. package/dist/fields/config/sanitizeJoinField.js +3 -0
  69. package/dist/fields/config/sanitizeJoinField.js.map +1 -1
  70. package/dist/globals/config/types.d.ts +4 -0
  71. package/dist/globals/config/types.d.ts.map +1 -1
  72. package/dist/globals/config/types.js.map +1 -1
  73. package/dist/hierarchy/addHierarchyToCollection.d.ts +8 -0
  74. package/dist/hierarchy/addHierarchyToCollection.d.ts.map +1 -0
  75. package/dist/hierarchy/addHierarchyToCollection.js +62 -0
  76. package/dist/hierarchy/addHierarchyToCollection.js.map +1 -0
  77. package/dist/hierarchy/buildParentField.d.ts +11 -0
  78. package/dist/hierarchy/buildParentField.d.ts.map +1 -0
  79. package/dist/hierarchy/buildParentField.js +42 -0
  80. package/dist/hierarchy/buildParentField.js.map +1 -0
  81. package/dist/hierarchy/constants.d.ts +15 -0
  82. package/dist/hierarchy/constants.d.ts.map +1 -0
  83. package/dist/hierarchy/constants.js +11 -0
  84. package/dist/hierarchy/constants.js.map +1 -0
  85. package/dist/hierarchy/createFolderField.d.ts +39 -0
  86. package/dist/hierarchy/createFolderField.d.ts.map +1 -0
  87. package/dist/hierarchy/createFolderField.js +54 -0
  88. package/dist/hierarchy/createFolderField.js.map +1 -0
  89. package/dist/hierarchy/createFoldersCollection.d.ts +57 -0
  90. package/dist/hierarchy/createFoldersCollection.d.ts.map +1 -0
  91. package/dist/hierarchy/createFoldersCollection.js +63 -0
  92. package/dist/hierarchy/createFoldersCollection.js.map +1 -0
  93. package/dist/hierarchy/createTagField.d.ts +44 -0
  94. package/dist/hierarchy/createTagField.d.ts.map +1 -0
  95. package/dist/hierarchy/createTagField.js +48 -0
  96. package/dist/hierarchy/createTagField.js.map +1 -0
  97. package/dist/hierarchy/createTagsCollection.d.ts +54 -0
  98. package/dist/hierarchy/createTagsCollection.d.ts.map +1 -0
  99. package/dist/hierarchy/createTagsCollection.js +56 -0
  100. package/dist/hierarchy/createTagsCollection.js.map +1 -0
  101. package/dist/hierarchy/endpoints/findRelated.d.ts +7 -0
  102. package/dist/hierarchy/endpoints/findRelated.d.ts.map +1 -0
  103. package/dist/hierarchy/endpoints/findRelated.js +36 -0
  104. package/dist/hierarchy/endpoints/findRelated.js.map +1 -0
  105. package/dist/hierarchy/getInitialTreeData.d.ts +24 -0
  106. package/dist/hierarchy/getInitialTreeData.d.ts.map +1 -0
  107. package/dist/hierarchy/getInitialTreeData.js +120 -0
  108. package/dist/hierarchy/getInitialTreeData.js.map +1 -0
  109. package/dist/hierarchy/hooks/collectionAfterDelete.d.ts +14 -0
  110. package/dist/hierarchy/hooks/collectionAfterDelete.d.ts.map +1 -0
  111. package/dist/hierarchy/hooks/collectionAfterDelete.js +21 -0
  112. package/dist/hierarchy/hooks/collectionAfterDelete.js.map +1 -0
  113. package/dist/hierarchy/hooks/collectionAfterRead.d.ts +27 -0
  114. package/dist/hierarchy/hooks/collectionAfterRead.d.ts.map +1 -0
  115. package/dist/hierarchy/hooks/collectionAfterRead.js +64 -0
  116. package/dist/hierarchy/hooks/collectionAfterRead.js.map +1 -0
  117. package/dist/hierarchy/hooks/collectionBeforeChange.d.ts +19 -0
  118. package/dist/hierarchy/hooks/collectionBeforeChange.d.ts.map +1 -0
  119. package/dist/hierarchy/hooks/collectionBeforeChange.js +90 -0
  120. package/dist/hierarchy/hooks/collectionBeforeChange.js.map +1 -0
  121. package/dist/hierarchy/hooks/collectionBeforeDelete.d.ts +15 -0
  122. package/dist/hierarchy/hooks/collectionBeforeDelete.d.ts.map +1 -0
  123. package/dist/hierarchy/hooks/collectionBeforeDelete.js +20 -0
  124. package/dist/hierarchy/hooks/collectionBeforeDelete.js.map +1 -0
  125. package/dist/hierarchy/hooks/ensureSafeCollectionsChange.d.ts +8 -0
  126. package/dist/hierarchy/hooks/ensureSafeCollectionsChange.d.ts.map +1 -0
  127. package/dist/hierarchy/hooks/ensureSafeCollectionsChange.js +108 -0
  128. package/dist/hierarchy/hooks/ensureSafeCollectionsChange.js.map +1 -0
  129. package/dist/hierarchy/injectHierarchyButton.d.ts +14 -0
  130. package/dist/hierarchy/injectHierarchyButton.d.ts.map +1 -0
  131. package/dist/hierarchy/injectHierarchyButton.js +37 -0
  132. package/dist/hierarchy/injectHierarchyButton.js.map +1 -0
  133. package/dist/hierarchy/operations/findRelatedDocuments.d.ts +24 -0
  134. package/dist/hierarchy/operations/findRelatedDocuments.d.ts.map +1 -0
  135. package/dist/hierarchy/operations/findRelatedDocuments.js +73 -0
  136. package/dist/hierarchy/operations/findRelatedDocuments.js.map +1 -0
  137. package/dist/hierarchy/operations/index.d.ts +2 -0
  138. package/dist/hierarchy/operations/index.d.ts.map +1 -0
  139. package/dist/hierarchy/operations/index.js +3 -0
  140. package/dist/hierarchy/operations/index.js.map +1 -0
  141. package/dist/hierarchy/resolveHierarchyCollections.d.ts +23 -0
  142. package/dist/hierarchy/resolveHierarchyCollections.d.ts.map +1 -0
  143. package/dist/hierarchy/resolveHierarchyCollections.js +312 -0
  144. package/dist/hierarchy/resolveHierarchyCollections.js.map +1 -0
  145. package/dist/hierarchy/sanitizeHierarchyCollection.d.ts +14 -0
  146. package/dist/hierarchy/sanitizeHierarchyCollection.d.ts.map +1 -0
  147. package/dist/hierarchy/sanitizeHierarchyCollection.js +125 -0
  148. package/dist/hierarchy/sanitizeHierarchyCollection.js.map +1 -0
  149. package/dist/hierarchy/types.d.ts +137 -0
  150. package/dist/hierarchy/types.d.ts.map +1 -0
  151. package/dist/hierarchy/types.js +6 -0
  152. package/dist/hierarchy/types.js.map +1 -0
  153. package/dist/hierarchy/utils/buildLocalizedHierarchyPaths.d.ts +71 -0
  154. package/dist/hierarchy/utils/buildLocalizedHierarchyPaths.d.ts.map +1 -0
  155. package/dist/hierarchy/utils/buildLocalizedHierarchyPaths.js +65 -0
  156. package/dist/hierarchy/utils/buildLocalizedHierarchyPaths.js.map +1 -0
  157. package/dist/hierarchy/utils/computePaths.d.ts +31 -0
  158. package/dist/hierarchy/utils/computePaths.d.ts.map +1 -0
  159. package/dist/hierarchy/utils/computePaths.js +371 -0
  160. package/dist/hierarchy/utils/computePaths.js.map +1 -0
  161. package/dist/hierarchy/utils/findUseAsTitle.d.ts +6 -0
  162. package/dist/hierarchy/utils/findUseAsTitle.d.ts.map +1 -0
  163. package/dist/hierarchy/utils/findUseAsTitle.js +72 -0
  164. package/dist/hierarchy/utils/findUseAsTitle.js.map +1 -0
  165. package/dist/hierarchy/utils/getAncestors.d.ts +34 -0
  166. package/dist/hierarchy/utils/getAncestors.d.ts.map +1 -0
  167. package/dist/hierarchy/utils/getAncestors.js +94 -0
  168. package/dist/hierarchy/utils/getAncestors.js.map +1 -0
  169. package/dist/hierarchy/utils/getLocalizedValue.d.ts +30 -0
  170. package/dist/hierarchy/utils/getLocalizedValue.d.ts.map +1 -0
  171. package/dist/hierarchy/utils/getLocalizedValue.js +46 -0
  172. package/dist/hierarchy/utils/getLocalizedValue.js.map +1 -0
  173. package/dist/hierarchy/utils/getLocalizedValue.spec.js +250 -0
  174. package/dist/hierarchy/utils/getLocalizedValue.spec.js.map +1 -0
  175. package/dist/index.bundled.d.ts +574 -284
  176. package/dist/index.d.ts +23 -9
  177. package/dist/index.d.ts.map +1 -1
  178. package/dist/index.js +13 -5
  179. package/dist/index.js.map +1 -1
  180. package/dist/preferences/keys.d.ts +8 -4
  181. package/dist/preferences/keys.d.ts.map +1 -1
  182. package/dist/preferences/keys.js +7 -4
  183. package/dist/preferences/keys.js.map +1 -1
  184. package/dist/types/index.d.ts +1 -0
  185. package/dist/types/index.d.ts.map +1 -1
  186. package/dist/types/index.js.map +1 -1
  187. package/dist/utilities/configToJSONSchema.d.ts +7 -3
  188. package/dist/utilities/configToJSONSchema.d.ts.map +1 -1
  189. package/dist/utilities/configToJSONSchema.js +23 -33
  190. package/dist/utilities/configToJSONSchema.js.map +1 -1
  191. package/dist/utilities/configToJSONSchema.spec.js +75 -1
  192. package/dist/utilities/configToJSONSchema.spec.js.map +1 -1
  193. package/dist/utilities/extractID.js +1 -1
  194. package/dist/utilities/extractID.js.map +1 -1
  195. package/dist/utilities/formatAdminURL.d.ts +13 -2
  196. package/dist/utilities/formatAdminURL.d.ts.map +1 -1
  197. package/dist/utilities/formatAdminURL.js.map +1 -1
  198. package/package.json +2 -2
  199. package/dist/admin/views/folderList.d.ts +0 -56
  200. package/dist/admin/views/folderList.d.ts.map +0 -1
  201. package/dist/admin/views/folderList.js +0 -3
  202. package/dist/admin/views/folderList.js.map +0 -1
  203. package/dist/folders/addFolderCollection.d.ts +0 -10
  204. package/dist/folders/addFolderCollection.d.ts.map +0 -1
  205. package/dist/folders/addFolderCollection.js +0 -26
  206. package/dist/folders/addFolderCollection.js.map +0 -1
  207. package/dist/folders/addFolderFieldToCollection.d.ts +0 -8
  208. package/dist/folders/addFolderFieldToCollection.d.ts.map +0 -1
  209. package/dist/folders/addFolderFieldToCollection.js +0 -20
  210. package/dist/folders/addFolderFieldToCollection.js.map +0 -1
  211. package/dist/folders/buildFolderField.d.ts +0 -8
  212. package/dist/folders/buildFolderField.d.ts.map +0 -1
  213. package/dist/folders/buildFolderField.js +0 -87
  214. package/dist/folders/buildFolderField.js.map +0 -1
  215. package/dist/folders/constants.d.ts +0 -3
  216. package/dist/folders/constants.d.ts.map +0 -1
  217. package/dist/folders/constants.js +0 -4
  218. package/dist/folders/constants.js.map +0 -1
  219. package/dist/folders/createFolderCollection.d.ts +0 -11
  220. package/dist/folders/createFolderCollection.d.ts.map +0 -1
  221. package/dist/folders/createFolderCollection.js +0 -115
  222. package/dist/folders/createFolderCollection.js.map +0 -1
  223. package/dist/folders/hooks/deleteSubfoldersAfterDelete.d.ts +0 -8
  224. package/dist/folders/hooks/deleteSubfoldersAfterDelete.d.ts.map +0 -1
  225. package/dist/folders/hooks/deleteSubfoldersAfterDelete.js +0 -15
  226. package/dist/folders/hooks/deleteSubfoldersAfterDelete.js.map +0 -1
  227. package/dist/folders/hooks/dissasociateAfterDelete.d.ts +0 -8
  228. package/dist/folders/hooks/dissasociateAfterDelete.d.ts.map +0 -1
  229. package/dist/folders/hooks/dissasociateAfterDelete.js +0 -20
  230. package/dist/folders/hooks/dissasociateAfterDelete.js.map +0 -1
  231. package/dist/folders/hooks/ensureSafeCollectionsChange.d.ts +0 -5
  232. package/dist/folders/hooks/ensureSafeCollectionsChange.d.ts.map +0 -1
  233. package/dist/folders/hooks/ensureSafeCollectionsChange.js +0 -107
  234. package/dist/folders/hooks/ensureSafeCollectionsChange.js.map +0 -1
  235. package/dist/folders/hooks/reparentChildFolder.d.ts +0 -24
  236. package/dist/folders/hooks/reparentChildFolder.d.ts.map +0 -1
  237. package/dist/folders/hooks/reparentChildFolder.js +0 -72
  238. package/dist/folders/hooks/reparentChildFolder.js.map +0 -1
  239. package/dist/folders/types.d.ts +0 -118
  240. package/dist/folders/types.d.ts.map +0 -1
  241. package/dist/folders/types.js +0 -3
  242. package/dist/folders/types.js.map +0 -1
  243. package/dist/folders/utils/buildFolderWhereConstraints.d.ts +0 -13
  244. package/dist/folders/utils/buildFolderWhereConstraints.d.ts.map +0 -1
  245. package/dist/folders/utils/buildFolderWhereConstraints.js +0 -45
  246. package/dist/folders/utils/buildFolderWhereConstraints.js.map +0 -1
  247. package/dist/folders/utils/formatFolderOrDocumentItem.d.ts +0 -12
  248. package/dist/folders/utils/formatFolderOrDocumentItem.d.ts.map +0 -1
  249. package/dist/folders/utils/formatFolderOrDocumentItem.js +0 -30
  250. package/dist/folders/utils/formatFolderOrDocumentItem.js.map +0 -1
  251. package/dist/folders/utils/getFolderBreadcrumbs.d.ts +0 -14
  252. package/dist/folders/utils/getFolderBreadcrumbs.d.ts.map +0 -1
  253. package/dist/folders/utils/getFolderBreadcrumbs.js +0 -45
  254. package/dist/folders/utils/getFolderBreadcrumbs.js.map +0 -1
  255. package/dist/folders/utils/getFolderData.d.ts +0 -33
  256. package/dist/folders/utils/getFolderData.d.ts.map +0 -1
  257. package/dist/folders/utils/getFolderData.js +0 -88
  258. package/dist/folders/utils/getFolderData.js.map +0 -1
  259. package/dist/folders/utils/getFoldersAndDocumentsFromJoin.d.ts +0 -24
  260. package/dist/folders/utils/getFoldersAndDocumentsFromJoin.d.ts.map +0 -1
  261. package/dist/folders/utils/getFoldersAndDocumentsFromJoin.js +0 -66
  262. package/dist/folders/utils/getFoldersAndDocumentsFromJoin.js.map +0 -1
  263. package/dist/folders/utils/getOrphanedDocs.d.ts +0 -15
  264. package/dist/folders/utils/getOrphanedDocs.d.ts.map +0 -1
  265. package/dist/folders/utils/getOrphanedDocs.js +0 -40
  266. package/dist/folders/utils/getOrphanedDocs.js.map +0 -1
@@ -0,0 +1,125 @@
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 { findRelatedHandler } from './endpoints/findRelated.js';
7
+ import { ensureSafeCollectionsChange } from './hooks/ensureSafeCollectionsChange.js';
8
+ /**
9
+ * Sanitizes hierarchy configuration for a single collection.
10
+ *
11
+ * This is phase 1 of hierarchy setup, called during individual collection sanitization.
12
+ * It normalizes the hierarchy config, creates the parent field if needed, adds hooks,
13
+ * and sets up the sanitized config structure.
14
+ *
15
+ * Phase 2 (`resolveHierarchyCollections`) runs after all collections are sanitized
16
+ * to establish cross-collection relationships.
17
+ */ export const sanitizeHierarchyCollection = (collectionConfig, _config)=>{
18
+ if (!collectionConfig.hierarchy) {
19
+ collectionConfig.hierarchy = false;
20
+ return;
21
+ }
22
+ // Normalize boolean to object and apply parentFieldName default
23
+ const defaultParentFieldName = getHierarchyFieldName(collectionConfig.slug);
24
+ if (collectionConfig.hierarchy === true) {
25
+ collectionConfig.hierarchy = {
26
+ parentFieldName: defaultParentFieldName
27
+ };
28
+ }
29
+ const parentFieldName = collectionConfig.hierarchy.parentFieldName ?? defaultParentFieldName;
30
+ // Check if parent field already exists
31
+ const existingParentField = collectionConfig.fields.find((field)=>fieldAffectsData(field) && field.name === parentFieldName);
32
+ if (existingParentField) {
33
+ // Validate existing parent field configuration
34
+ if (existingParentField.type !== 'relationship') {
35
+ throw new Error(`Hierarchy parent field "${parentFieldName}" in collection "${collectionConfig.slug}" must be a relationship field`);
36
+ }
37
+ if (existingParentField.hasMany !== false) {
38
+ throw new Error(`Hierarchy parent field "${parentFieldName}" in collection "${collectionConfig.slug}" must have hasMany set to false`);
39
+ }
40
+ if (existingParentField.localized === true) {
41
+ throw new Error(`Hierarchy parent field "${parentFieldName}" in collection "${collectionConfig.slug}" cannot be localized. The parent relationship must be consistent across all locales.`);
42
+ }
43
+ } else {
44
+ // Auto-create parent field if it doesn't exist
45
+ // useHeaderButton defaults to true - parent selection via header button with miller columns
46
+ const useHeaderButton = collectionConfig.hierarchy.admin?.useHeaderButton ?? true;
47
+ const parentField = buildParentField({
48
+ collectionSlug: collectionConfig.slug,
49
+ injectHeaderButton: useHeaderButton,
50
+ parentFieldName
51
+ });
52
+ collectionConfig.fields.unshift(parentField);
53
+ }
54
+ // Apply defaults for optional fields
55
+ const slugPathFieldName = collectionConfig.hierarchy.slugPathFieldName || HIERARCHY_SLUG_PATH_FIELD;
56
+ const titlePathFieldName = collectionConfig.hierarchy.titlePathFieldName || HIERARCHY_TITLE_PATH_FIELD;
57
+ const allowHasMany = collectionConfig.hierarchy.allowHasMany ?? DEFAULT_ALLOW_HAS_MANY;
58
+ const rawCollectionSpecific = collectionConfig.hierarchy.collectionSpecific;
59
+ const collectionSpecific = rawCollectionSpecific === true ? {
60
+ fieldName: 'hierarchyType'
61
+ } : rawCollectionSpecific ? {
62
+ fieldName: rawCollectionSpecific.fieldName ?? 'hierarchyType'
63
+ } : false;
64
+ const joinField = collectionConfig.hierarchy.joinField ? collectionConfig.hierarchy.joinField : undefined;
65
+ const slugify = collectionConfig.hierarchy.slugify ?? ((text)=>defaultSlugify(text) ?? '');
66
+ const treeLimit = collectionConfig.hierarchy.admin?.treeLimit ?? DEFAULT_HIERARCHY_TREE_LIMIT;
67
+ const iconComponent = collectionConfig.hierarchy.admin?.components?.Icon;
68
+ // Apply hierarchy to collection (adds fields and hooks)
69
+ addHierarchyToCollection({
70
+ collectionConfig,
71
+ parentFieldName: collectionConfig.hierarchy.parentFieldName,
72
+ slugPathFieldName,
73
+ titlePathFieldName
74
+ });
75
+ // Add /related endpoint for finding related documents
76
+ if (!collectionConfig.endpoints) {
77
+ collectionConfig.endpoints = [];
78
+ }
79
+ const hasRelatedEndpoint = Array.isArray(collectionConfig.endpoints) && collectionConfig.endpoints.some((endpoint)=>endpoint.path === '/:id/related');
80
+ if (!hasRelatedEndpoint && Array.isArray(collectionConfig.endpoints)) {
81
+ collectionConfig.endpoints.push({
82
+ handler: findRelatedHandler,
83
+ method: 'get',
84
+ path: '/:id/related'
85
+ });
86
+ }
87
+ // If collectionSpecific, add beforeValidate hook to enforce scope inheritance
88
+ // (hierarchyType field is added in resolveHierarchyCollections after discovery)
89
+ if (collectionSpecific) {
90
+ // Use parentFieldName for both - backward compatible configs use the same field name everywhere
91
+ if (!collectionConfig.hooks) {
92
+ collectionConfig.hooks = {};
93
+ }
94
+ if (!collectionConfig.hooks.beforeValidate) {
95
+ collectionConfig.hooks.beforeValidate = [];
96
+ }
97
+ collectionConfig.hooks.beforeValidate.push(ensureSafeCollectionsChange({
98
+ folderFieldName: parentFieldName,
99
+ foldersSlug: collectionConfig.slug,
100
+ parentFieldName,
101
+ typeFieldName: collectionSpecific.fieldName
102
+ }));
103
+ }
104
+ // Set sanitized hierarchy config (cast needed as we're transitioning from HierarchyConfig to SanitizedHierarchyConfig)
105
+ const useHeaderButton = collectionConfig.hierarchy.admin?.useHeaderButton ?? false;
106
+ collectionConfig.hierarchy = {
107
+ admin: {
108
+ components: {
109
+ Icon: iconComponent || '@payloadcms/ui#TagIcon'
110
+ },
111
+ treeLimit,
112
+ useHeaderButton
113
+ },
114
+ allowHasMany,
115
+ collectionSpecific,
116
+ joinField,
117
+ parentFieldName,
118
+ relatedCollections: {},
119
+ slugify,
120
+ slugPathFieldName,
121
+ titlePathFieldName
122
+ };
123
+ };
124
+
125
+ //# 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 { findRelatedHandler } from './endpoints/findRelated.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 // Apply hierarchy to collection (adds fields and hooks)\n addHierarchyToCollection({\n collectionConfig,\n parentFieldName: collectionConfig.hierarchy.parentFieldName,\n slugPathFieldName,\n titlePathFieldName,\n })\n\n // Add /related endpoint for finding related documents\n if (!collectionConfig.endpoints) {\n collectionConfig.endpoints = []\n }\n\n const hasRelatedEndpoint =\n Array.isArray(collectionConfig.endpoints) &&\n collectionConfig.endpoints.some((endpoint) => endpoint.path === '/:id/related')\n\n if (!hasRelatedEndpoint && Array.isArray(collectionConfig.endpoints)) {\n collectionConfig.endpoints.push({\n handler: findRelatedHandler,\n method: 'get',\n path: '/:id/related',\n })\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\n ;(collectionConfig as unknown as { hierarchy: SanitizedHierarchyConfig }).hierarchy = {\n admin: {\n components: {\n Icon: iconComponent || '@payloadcms/ui#TagIcon',\n },\n treeLimit,\n useHeaderButton,\n },\n allowHasMany,\n collectionSpecific,\n joinField,\n parentFieldName,\n relatedCollections: {},\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","findRelatedHandler","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","endpoints","hasRelatedEndpoint","Array","isArray","some","endpoint","path","push","handler","method","hooks","beforeValidate","folderFieldName","foldersSlug","typeFieldName","relatedCollections"],"mappings":"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"}
@@ -0,0 +1,137 @@
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
+ * Maximum number of items to load in tree views
32
+ * @default 100
33
+ */
34
+ treeLimit?: number;
35
+ /**
36
+ * Whether to use a header button for parent selection instead of inline field.
37
+ * When true, the parent field is hidden and a button is injected into the document header.
38
+ * @default true
39
+ */
40
+ useHeaderButton?: boolean;
41
+ };
42
+ /**
43
+ * Whether related documents can have multiple values of this hierarchy
44
+ * Set to false for folder-like behavior (single parent), true for tag-like behavior (multiple)
45
+ * @default true
46
+ */
47
+ allowHasMany?: boolean;
48
+ /**
49
+ * Whether this hierarchy is scoped to specific collections
50
+ * When true or an object, hierarchy items can be restricted to certain collections
51
+ * @default false
52
+ */
53
+ collectionSpecific?: {
54
+ /**
55
+ * Name of the select field for specifying allowed collections
56
+ * @default 'hierarchyType'
57
+ */
58
+ fieldName?: string;
59
+ } | boolean;
60
+ /**
61
+ * Configure a join field to query all children (nested hierarchy items and related documents)
62
+ * If not set, no join field is created.
63
+ * You can pass additional JoinField options (admin, defaultLimit, defaultSort, etc.)
64
+ * that will be merged with the auto-generated config.
65
+ */
66
+ joinField?: HierarchyJoinFieldConfig;
67
+ /**
68
+ * Name of the field that references the parent document
69
+ * Will automatically create this field if it does not exist
70
+ * @default '_h_${collectionSlug}' (e.g., '_h_folders' for a collection with slug 'folders')
71
+ */
72
+ parentFieldName: string;
73
+ /**
74
+ * Custom function to slugify text for path generation
75
+ * Used by computeSlugPath() utility for generating slug-based breadcrumb paths
76
+ * Defaults to internal slugify implementation
77
+ */
78
+ slugify?: (text: string) => string;
79
+ /**
80
+ * Name of the virtual field that will contain the slug-based breadcrumb path
81
+ * @default HIERARCHY_SLUG_PATH_FIELD ('_h_slugPath')
82
+ */
83
+ slugPathFieldName?: string;
84
+ /**
85
+ * Name of the virtual field that will contain the title-based breadcrumb path
86
+ * @default HIERARCHY_TITLE_PATH_FIELD ('_h_titlePath')
87
+ */
88
+ titlePathFieldName?: string;
89
+ };
90
+ /**
91
+ * Sanitized hierarchy configuration with all defaults applied
92
+ */
93
+ export type SanitizedHierarchyConfig = {
94
+ admin: {
95
+ components: {
96
+ Icon: PayloadComponent;
97
+ };
98
+ treeLimit: number;
99
+ useHeaderButton: boolean;
100
+ };
101
+ allowHasMany: boolean;
102
+ collectionSpecific: {
103
+ fieldName: string;
104
+ } | false;
105
+ /**
106
+ * Join field configuration, or undefined if not enabled
107
+ */
108
+ joinField?: HierarchyJoinFieldConfig;
109
+ parentFieldName: string;
110
+ /**
111
+ * Auto-populated during validation - maps collection slug to field info
112
+ */
113
+ relatedCollections: Record<string, SanitizedHierarchyRelatedCollection>;
114
+ slugify: (text: string) => string;
115
+ slugPathFieldName: string;
116
+ titlePathFieldName: string;
117
+ };
118
+ /**
119
+ * Information about how a collection relates to this hierarchy
120
+ */
121
+ export type SanitizedHierarchyRelatedCollection = {
122
+ fieldName: string;
123
+ hasMany: boolean;
124
+ };
125
+ /**
126
+ * Client-safe hierarchy configuration (excludes functions that can't cross server-client boundary)
127
+ */
128
+ export type ClientHierarchyConfig = Omit<SanitizedHierarchyConfig, 'slugify'>;
129
+ /**
130
+ * Breadcrumb item for folder hierarchies
131
+ * @deprecated Use hierarchy breadcrumbs instead
132
+ */
133
+ export type FolderBreadcrumb = {
134
+ id: number | string;
135
+ name: string;
136
+ };
137
+ //# 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,EAAE,MAAM,oBAAoB,CAAA;AAC1D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AAE1D;;;GAGG;AACH,MAAM,MAAM,wBAAwB,GAAG;IACrC,IAAI,EAAE,MAAM,CAAA;CACb,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,YAAY,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,GAAG,MAAM,CAAC,CAAA;AAE/E;;;;;GAKG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B;;OAEG;IACH,KAAK,CAAC,EAAE;QACN;;WAEG;QACH,UAAU,CAAC,EAAE;YACX;;eAEG;YACH,IAAI,CAAC,EAAE,gBAAgB,CAAA;SACxB,CAAA;QACD;;;WAGG;QACH,SAAS,CAAC,EAAE,MAAM,CAAA;QAClB;;;;WAIG;QACH,eAAe,CAAC,EAAE,OAAO,CAAA;KAC1B,CAAA;IACD;;;;OAIG;IACH,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB;;;;OAIG;IACH,kBAAkB,CAAC,EACf;QACE;;;WAGG;QACH,SAAS,CAAC,EAAE,MAAM,CAAA;KACnB,GACD,OAAO,CAAA;IACX;;;;;OAKG;IACH,SAAS,CAAC,EAAE,wBAAwB,CAAA;IACpC;;;;OAIG;IACH,eAAe,EAAE,MAAM,CAAA;IACvB;;;;OAIG;IACH,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAA;IAClC;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B;;;OAGG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAA;CAC5B,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAAG;IACrC,KAAK,EAAE;QACL,UAAU,EAAE;YACV,IAAI,EAAE,gBAAgB,CAAA;SACvB,CAAA;QACD,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,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 * 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 * Custom function to slugify text for path generation\n * Used by computeSlugPath() utility for generating slug-based breadcrumb paths\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 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 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":"AA0IA;;;CAGC,GACD,WAGC"}
@@ -0,0 +1,71 @@
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
+ */
20
+ slugify: (val: string) => string;
21
+ /**
22
+ * The localized title value object (e.g., { en: "Home", es: "Inicio", de: "Startseite" })
23
+ */
24
+ titleValue: Record<string, string>;
25
+ };
26
+ type BuildLocalizedPathsResult = {
27
+ slugPath: Record<string, string>;
28
+ titlePath: Record<string, string>;
29
+ };
30
+ /**
31
+ * Builds localized slug and title paths for all configured locales.
32
+ * Applies proper fallback locale handling and optionally prepends parent paths.
33
+ *
34
+ * This utility is used when `locale: 'all'` is requested and the title field is localized,
35
+ * generating a path for each locale with proper fallback handling.
36
+ *
37
+ * @example
38
+ * ```ts
39
+ * // Without parent (root document)
40
+ * buildLocalizedPaths({
41
+ * req,
42
+ * slugify: (val) => val.toLowerCase().replace(/\s/g, '-'),
43
+ * titleValue: { en: "Home", es: "Inicio", de: "" }
44
+ * })
45
+ * // Returns:
46
+ * // {
47
+ * // slugPath: { en: "home", es: "inicio", de: "home" }, // 'de' falls back to 'en'
48
+ * // titlePath: { en: "Home", es: "Inicio", de: "Home" }
49
+ * // }
50
+ *
51
+ * // With parent paths
52
+ * buildLocalizedPaths({
53
+ * parentSlugPath: { en: "/blog", es: "/blog" },
54
+ * parentTitlePath: { en: "Blog", es: "Blog" },
55
+ * req,
56
+ * slugify: (val) => val.toLowerCase().replace(/\s/g, '-'),
57
+ * titleValue: { en: "Tech News", es: "Noticias Tecnológicas" }
58
+ * })
59
+ * // Returns:
60
+ * // {
61
+ * // slugPath: { en: "/blog/tech-news", es: "/blog/noticias-tecnologicas" },
62
+ * // titlePath: { en: "Blog / Tech News", es: "Blog / Noticias Tecnológicas" }
63
+ * // }
64
+ * ```
65
+ *
66
+ * @param args - Configuration for building localized paths
67
+ * @returns Object containing slugPath and titlePath, each mapping locale codes to path strings
68
+ */
69
+ export declare function buildLocalizedHierarchyPaths(args: BuildLocalizedPathsArgs): BuildLocalizedPathsResult;
70
+ export {};
71
+ //# 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;;OAEG;IACH,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAA;IAChC;;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,CAiC3B"}
@@ -0,0 +1,65 @@
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, 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
+ const slugSegment = slugify(localizedTitle);
54
+ const titleSegment = localizedTitle;
55
+ slugPathsByLocale[loc] = parentSlugPath ? `${parentSlugPath[loc]}/${slugSegment}` : slugSegment;
56
+ titlePathsByLocale[loc] = parentTitlePath ? `${parentTitlePath[loc]}/${titleSegment}` : titleSegment;
57
+ }
58
+ }
59
+ return {
60
+ slugPath: slugPathsByLocale,
61
+ titlePath: titlePathsByLocale
62
+ };
63
+ }
64
+
65
+ //# 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 */\n slugify: (val: 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, 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 const slugSegment = slugify(localizedTitle)\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","titleValue","slugPathsByLocale","titlePathsByLocale","locales","payload","config","localization","localeCodes","loc","localizedTitle","fallbackLocale","fieldType","locale","value","slugSegment","titleSegment","slugPath","titlePath"],"mappings":"AAEA,SAASA,iBAAiB,QAAQ,yBAAwB;AAgC1D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsCC,GACD,OAAO,SAASC,6BACdC,IAA6B;IAE7B,MAAM,EAAEC,cAAc,EAAEC,eAAe,EAAEC,GAAG,EAAEC,OAAO,EAAEC,UAAU,EAAE,GAAGL;IAEtE,MAAMM,oBAA4C,CAAC;IACnD,MAAMC,qBAA6C,CAAC;IAEpD,MAAMC,UAAUL,IAAIM,OAAO,CAACC,MAAM,CAACC,YAAY,GAAGR,IAAIM,OAAO,CAACC,MAAM,CAACC,YAAY,CAACC,WAAW,GAAG,EAAE;IAElG,KAAK,MAAMC,OAAOL,QAAS;QACzB,MAAMM,iBAAiBhB,kBAAkB;YACvCiB,gBAAgBZ,IAAIY,cAAc;YAClCC,WAAW;YACXC,QAAQJ;YACRK,OAAOb;QACT;QAEA,IAAIS,gBAAgB;YAClB,MAAMK,cAAcf,QAAQU;YAC5B,MAAMM,eAAeN;YAErBR,iBAAiB,CAACO,IAAI,GAAGZ,iBACrB,GAAGA,cAAc,CAACY,IAAI,CAAC,CAAC,EAAEM,aAAa,GACvCA;YACJZ,kBAAkB,CAACM,IAAI,GAAGX,kBACtB,GAAGA,eAAe,CAACW,IAAI,CAAC,CAAC,EAAEO,cAAc,GACzCA;QACN;IACF;IAEA,OAAO;QACLC,UAAUf;QACVgB,WAAWf;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;AAYpE,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;AAyCD;;;;;;;;;;;GAWG;AACH,wBAAsB,YAAY,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAsZtF"}