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.
- package/README.md +5 -5
- package/dist/admin/elements/Nav.d.ts +13 -0
- package/dist/admin/elements/Nav.d.ts.map +1 -1
- package/dist/admin/elements/Nav.js.map +1 -1
- package/dist/admin/functions/index.d.ts +1 -38
- package/dist/admin/functions/index.d.ts.map +1 -1
- package/dist/admin/functions/index.js.map +1 -1
- package/dist/admin/types.d.ts +5 -4
- package/dist/admin/types.d.ts.map +1 -1
- package/dist/admin/types.js.map +1 -1
- package/dist/admin/views/hierarchyList.d.ts +9 -0
- package/dist/admin/views/hierarchyList.d.ts.map +1 -0
- package/dist/admin/views/hierarchyList.js +3 -0
- package/dist/admin/views/hierarchyList.js.map +1 -0
- package/dist/admin/views/index.d.ts +1 -3
- package/dist/admin/views/index.d.ts.map +1 -1
- package/dist/admin/views/index.js.map +1 -1
- package/dist/admin/views/list.d.ts +43 -2
- package/dist/admin/views/list.d.ts.map +1 -1
- package/dist/admin/views/list.js.map +1 -1
- package/dist/bin/generateImportMap/iterateCollections.d.ts.map +1 -1
- package/dist/bin/generateImportMap/iterateCollections.js +1 -0
- package/dist/bin/generateImportMap/iterateCollections.js.map +1 -1
- package/dist/bin/generateImportMap/iterateConfig.d.ts.map +1 -1
- package/dist/bin/generateImportMap/iterateConfig.js +7 -0
- package/dist/bin/generateImportMap/iterateConfig.js.map +1 -1
- package/dist/bin/generateImportMap/iterateGlobals.d.ts.map +1 -1
- package/dist/bin/generateImportMap/iterateGlobals.js +20 -8
- package/dist/bin/generateImportMap/iterateGlobals.js.map +1 -1
- package/dist/bin/index.d.ts.map +1 -1
- package/dist/bin/index.js +1 -3
- package/dist/bin/index.js.map +1 -1
- package/dist/collections/config/client.d.ts +4 -2
- package/dist/collections/config/client.d.ts.map +1 -1
- package/dist/collections/config/client.js +13 -1
- package/dist/collections/config/client.js.map +1 -1
- package/dist/collections/config/defaults.js +1 -1
- package/dist/collections/config/defaults.js.map +1 -1
- package/dist/collections/config/sanitize.d.ts.map +1 -1
- package/dist/collections/config/sanitize.js +231 -184
- package/dist/collections/config/sanitize.js.map +1 -1
- package/dist/collections/config/types.d.ts +76 -91
- package/dist/collections/config/types.d.ts.map +1 -1
- package/dist/collections/config/types.js.map +1 -1
- package/dist/collections/operations/create.d.ts.map +1 -1
- package/dist/collections/operations/create.js +24 -19
- package/dist/collections/operations/create.js.map +1 -1
- package/dist/collections/operations/delete.d.ts.map +1 -1
- package/dist/collections/operations/delete.js +7 -2
- package/dist/collections/operations/delete.js.map +1 -1
- package/dist/collections/operations/deleteByID.d.ts.map +1 -1
- package/dist/collections/operations/deleteByID.js +7 -2
- package/dist/collections/operations/deleteByID.js.map +1 -1
- package/dist/collections/operations/find.d.ts.map +1 -1
- package/dist/collections/operations/find.js +7 -2
- package/dist/collections/operations/find.js.map +1 -1
- package/dist/collections/operations/findByID.d.ts.map +1 -1
- package/dist/collections/operations/findByID.js +10 -5
- package/dist/collections/operations/findByID.js.map +1 -1
- package/dist/collections/operations/findVersionByID.d.ts.map +1 -1
- package/dist/collections/operations/findVersionByID.js +6 -4
- package/dist/collections/operations/findVersionByID.js.map +1 -1
- package/dist/collections/operations/findVersions.d.ts.map +1 -1
- package/dist/collections/operations/findVersions.js +6 -4
- package/dist/collections/operations/findVersions.js.map +1 -1
- package/dist/collections/operations/restoreVersion.d.ts.map +1 -1
- package/dist/collections/operations/restoreVersion.js +7 -2
- package/dist/collections/operations/restoreVersion.js.map +1 -1
- package/dist/collections/operations/update.d.ts.map +1 -1
- package/dist/collections/operations/update.js +7 -2
- package/dist/collections/operations/update.js.map +1 -1
- package/dist/collections/operations/updateByID.d.ts.map +1 -1
- package/dist/collections/operations/updateByID.js +7 -2
- package/dist/collections/operations/updateByID.js.map +1 -1
- package/dist/collections/operations/utilities/update.d.ts.map +1 -1
- package/dist/collections/operations/utilities/update.js +5 -4
- package/dist/collections/operations/utilities/update.js.map +1 -1
- package/dist/config/client.d.ts.map +1 -1
- package/dist/config/client.js +0 -10
- package/dist/config/client.js.map +1 -1
- package/dist/config/defaults.d.ts.map +1 -1
- package/dist/config/defaults.js +0 -15
- package/dist/config/defaults.js.map +1 -1
- package/dist/config/orderable/index.d.ts.map +1 -1
- package/dist/config/orderable/index.js +0 -4
- package/dist/config/orderable/index.js.map +1 -1
- package/dist/config/sanitize.d.ts.map +1 -1
- package/dist/config/sanitize.js +252 -266
- package/dist/config/sanitize.js.map +1 -1
- package/dist/config/types.d.ts +120 -13
- package/dist/config/types.d.ts.map +1 -1
- package/dist/config/types.js.map +1 -1
- package/dist/exports/internal.d.ts +1 -0
- package/dist/exports/internal.d.ts.map +1 -1
- package/dist/exports/internal.js +1 -0
- package/dist/exports/internal.js.map +1 -1
- package/dist/exports/shared.d.ts +5 -3
- package/dist/exports/shared.d.ts.map +1 -1
- package/dist/exports/shared.js +3 -2
- package/dist/exports/shared.js.map +1 -1
- package/dist/fields/baseFields/slug/index.d.ts.map +1 -1
- package/dist/fields/baseFields/slug/index.js +6 -4
- package/dist/fields/baseFields/slug/index.js.map +1 -1
- package/dist/fields/config/client.d.ts.map +1 -1
- package/dist/fields/config/client.js +3 -2
- package/dist/fields/config/client.js.map +1 -1
- package/dist/fields/config/sanitize.d.ts.map +1 -1
- package/dist/fields/config/sanitize.js +335 -322
- package/dist/fields/config/sanitize.js.map +1 -1
- package/dist/fields/config/sanitizeJoinField.d.ts.map +1 -1
- package/dist/fields/config/sanitizeJoinField.js +3 -0
- package/dist/fields/config/sanitizeJoinField.js.map +1 -1
- package/dist/fields/config/types.d.ts +17 -73
- package/dist/fields/config/types.d.ts.map +1 -1
- package/dist/fields/config/types.js +11 -1
- package/dist/fields/config/types.js.map +1 -1
- package/dist/fields/isFieldDisabled.d.ts +12 -0
- package/dist/fields/isFieldDisabled.d.ts.map +1 -0
- package/dist/fields/isFieldDisabled.js +15 -0
- package/dist/fields/isFieldDisabled.js.map +1 -0
- package/dist/fields/isFieldDisabled.spec.js +134 -0
- package/dist/fields/isFieldDisabled.spec.js.map +1 -0
- package/dist/fields/validations.js +1 -1
- package/dist/fields/validations.js.map +1 -1
- package/dist/globals/config/client.d.ts +1 -1
- package/dist/globals/config/client.d.ts.map +1 -1
- package/dist/globals/config/client.js +2 -1
- package/dist/globals/config/client.js.map +1 -1
- package/dist/globals/config/sanitize.d.ts.map +1 -1
- package/dist/globals/config/sanitize.js +132 -122
- package/dist/globals/config/sanitize.js.map +1 -1
- package/dist/globals/config/types.d.ts +4 -57
- package/dist/globals/config/types.d.ts.map +1 -1
- package/dist/globals/config/types.js.map +1 -1
- package/dist/globals/operations/findOne.d.ts.map +1 -1
- package/dist/globals/operations/findOne.js +7 -2
- package/dist/globals/operations/findOne.js.map +1 -1
- package/dist/globals/operations/findVersionByID.d.ts.map +1 -1
- package/dist/globals/operations/findVersionByID.js +6 -4
- package/dist/globals/operations/findVersionByID.js.map +1 -1
- package/dist/globals/operations/findVersions.d.ts.map +1 -1
- package/dist/globals/operations/findVersions.js +6 -4
- package/dist/globals/operations/findVersions.js.map +1 -1
- package/dist/globals/operations/update.d.ts.map +1 -1
- package/dist/globals/operations/update.js +7 -2
- package/dist/globals/operations/update.js.map +1 -1
- package/dist/hierarchy/addHierarchyToCollection.d.ts +9 -0
- package/dist/hierarchy/addHierarchyToCollection.d.ts.map +1 -0
- package/dist/hierarchy/addHierarchyToCollection.js +76 -0
- package/dist/hierarchy/addHierarchyToCollection.js.map +1 -0
- package/dist/hierarchy/buildParentField.d.ts +11 -0
- package/dist/hierarchy/buildParentField.d.ts.map +1 -0
- package/dist/hierarchy/buildParentField.js +42 -0
- package/dist/hierarchy/buildParentField.js.map +1 -0
- package/dist/hierarchy/constants.d.ts +15 -0
- package/dist/hierarchy/constants.d.ts.map +1 -0
- package/dist/hierarchy/constants.js +11 -0
- package/dist/hierarchy/constants.js.map +1 -0
- package/dist/hierarchy/createFolderField.d.ts +39 -0
- package/dist/hierarchy/createFolderField.d.ts.map +1 -0
- package/dist/hierarchy/createFolderField.js +54 -0
- package/dist/hierarchy/createFolderField.js.map +1 -0
- package/dist/hierarchy/createTagField.d.ts +44 -0
- package/dist/hierarchy/createTagField.d.ts.map +1 -0
- package/dist/hierarchy/createTagField.js +48 -0
- package/dist/hierarchy/createTagField.js.map +1 -0
- package/dist/hierarchy/getInitialTreeData.d.ts +27 -0
- package/dist/hierarchy/getInitialTreeData.d.ts.map +1 -0
- package/dist/hierarchy/getInitialTreeData.js +125 -0
- package/dist/hierarchy/getInitialTreeData.js.map +1 -0
- package/dist/hierarchy/hooks/collectionAfterDelete.d.ts +14 -0
- package/dist/hierarchy/hooks/collectionAfterDelete.d.ts.map +1 -0
- package/dist/hierarchy/hooks/collectionAfterDelete.js +21 -0
- package/dist/hierarchy/hooks/collectionAfterDelete.js.map +1 -0
- package/dist/hierarchy/hooks/collectionAfterRead.d.ts +27 -0
- package/dist/hierarchy/hooks/collectionAfterRead.d.ts.map +1 -0
- package/dist/hierarchy/hooks/collectionAfterRead.js +72 -0
- package/dist/hierarchy/hooks/collectionAfterRead.js.map +1 -0
- package/dist/hierarchy/hooks/collectionBeforeChange.d.ts +19 -0
- package/dist/hierarchy/hooks/collectionBeforeChange.d.ts.map +1 -0
- package/dist/hierarchy/hooks/collectionBeforeChange.js +90 -0
- package/dist/hierarchy/hooks/collectionBeforeChange.js.map +1 -0
- package/dist/hierarchy/hooks/collectionBeforeDelete.d.ts +15 -0
- package/dist/hierarchy/hooks/collectionBeforeDelete.d.ts.map +1 -0
- package/dist/hierarchy/hooks/collectionBeforeDelete.js +20 -0
- package/dist/hierarchy/hooks/collectionBeforeDelete.js.map +1 -0
- package/dist/hierarchy/hooks/collectionBeforeOperation.d.ts +33 -0
- package/dist/hierarchy/hooks/collectionBeforeOperation.d.ts.map +1 -0
- package/dist/hierarchy/hooks/collectionBeforeOperation.js +66 -0
- package/dist/hierarchy/hooks/collectionBeforeOperation.js.map +1 -0
- package/dist/hierarchy/hooks/ensureSafeCollectionsChange.d.ts +8 -0
- package/dist/hierarchy/hooks/ensureSafeCollectionsChange.d.ts.map +1 -0
- package/dist/hierarchy/hooks/ensureSafeCollectionsChange.js +108 -0
- package/dist/hierarchy/hooks/ensureSafeCollectionsChange.js.map +1 -0
- package/dist/hierarchy/injectHierarchyButton.d.ts +14 -0
- package/dist/hierarchy/injectHierarchyButton.d.ts.map +1 -0
- package/dist/hierarchy/injectHierarchyButton.js +37 -0
- package/dist/hierarchy/injectHierarchyButton.js.map +1 -0
- package/dist/hierarchy/presets.d.ts +13 -0
- package/dist/hierarchy/presets.d.ts.map +1 -0
- package/dist/hierarchy/presets.js +52 -0
- package/dist/hierarchy/presets.js.map +1 -0
- package/dist/hierarchy/resolveHierarchyCollections.d.ts +23 -0
- package/dist/hierarchy/resolveHierarchyCollections.d.ts.map +1 -0
- package/dist/hierarchy/resolveHierarchyCollections.js +321 -0
- package/dist/hierarchy/resolveHierarchyCollections.js.map +1 -0
- package/dist/hierarchy/sanitizeHierarchyCollection.d.ts +14 -0
- package/dist/hierarchy/sanitizeHierarchyCollection.d.ts.map +1 -0
- package/dist/hierarchy/sanitizeHierarchyCollection.js +117 -0
- package/dist/hierarchy/sanitizeHierarchyCollection.js.map +1 -0
- package/dist/hierarchy/types.d.ts +155 -0
- package/dist/hierarchy/types.d.ts.map +1 -0
- package/dist/hierarchy/types.js +6 -0
- package/dist/hierarchy/types.js.map +1 -0
- package/dist/hierarchy/utils/buildLocalizedHierarchyPaths.d.ts +77 -0
- package/dist/hierarchy/utils/buildLocalizedHierarchyPaths.d.ts.map +1 -0
- package/dist/hierarchy/utils/buildLocalizedHierarchyPaths.js +77 -0
- package/dist/hierarchy/utils/buildLocalizedHierarchyPaths.js.map +1 -0
- package/dist/hierarchy/utils/computePaths.d.ts +31 -0
- package/dist/hierarchy/utils/computePaths.d.ts.map +1 -0
- package/dist/hierarchy/utils/computePaths.js +445 -0
- package/dist/hierarchy/utils/computePaths.js.map +1 -0
- package/dist/hierarchy/utils/findUseAsTitle.d.ts +14 -0
- package/dist/hierarchy/utils/findUseAsTitle.d.ts.map +1 -0
- package/dist/hierarchy/utils/findUseAsTitle.js +89 -0
- package/dist/hierarchy/utils/findUseAsTitle.js.map +1 -0
- package/dist/hierarchy/utils/getAncestors.d.ts +34 -0
- package/dist/hierarchy/utils/getAncestors.d.ts.map +1 -0
- package/dist/hierarchy/utils/getAncestors.js +94 -0
- package/dist/hierarchy/utils/getAncestors.js.map +1 -0
- package/dist/hierarchy/utils/getLocalizedValue.d.ts +30 -0
- package/dist/hierarchy/utils/getLocalizedValue.d.ts.map +1 -0
- package/dist/hierarchy/utils/getLocalizedValue.js +46 -0
- package/dist/hierarchy/utils/getLocalizedValue.js.map +1 -0
- package/dist/hierarchy/utils/getLocalizedValue.spec.js +250 -0
- package/dist/hierarchy/utils/getLocalizedValue.spec.js.map +1 -0
- package/dist/index.bundled.d.ts +709 -530
- package/dist/index.d.ts +28 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +31 -8
- package/dist/index.js.map +1 -1
- package/dist/preferences/keys.d.ts +8 -4
- package/dist/preferences/keys.d.ts.map +1 -1
- package/dist/preferences/keys.js +7 -4
- package/dist/preferences/keys.js.map +1 -1
- package/dist/preferences/types.d.ts +1 -1
- package/dist/preferences/types.d.ts.map +1 -1
- package/dist/preferences/types.js.map +1 -1
- package/dist/query-presets/config.d.ts.map +1 -1
- package/dist/query-presets/config.js +5 -1
- package/dist/query-presets/config.js.map +1 -1
- package/dist/queues/config/types/index.d.ts +0 -21
- package/dist/queues/config/types/index.d.ts.map +1 -1
- package/dist/queues/config/types/index.js.map +1 -1
- package/dist/queues/config/types/taskTypes.d.ts +0 -20
- package/dist/queues/config/types/taskTypes.d.ts.map +1 -1
- package/dist/queues/config/types/taskTypes.js.map +1 -1
- package/dist/queues/errors/handleWorkflowError.d.ts.map +1 -1
- package/dist/queues/errors/handleWorkflowError.js +9 -1
- package/dist/queues/errors/handleWorkflowError.js.map +1 -1
- package/dist/queues/localAPI.d.ts.map +1 -1
- package/dist/queues/localAPI.js +26 -67
- package/dist/queues/localAPI.js.map +1 -1
- package/dist/queues/operations/handleSchedules/index.d.ts.map +1 -1
- package/dist/queues/operations/handleSchedules/index.js +1 -4
- package/dist/queues/operations/handleSchedules/index.js.map +1 -1
- package/dist/queues/operations/runJobs/index.d.ts.map +1 -1
- package/dist/queues/operations/runJobs/index.js +40 -37
- package/dist/queues/operations/runJobs/index.js.map +1 -1
- package/dist/queues/operations/runJobs/runJob/getRunTaskFunction.d.ts.map +1 -1
- package/dist/queues/operations/runJobs/runJob/getRunTaskFunction.js +3 -22
- package/dist/queues/operations/runJobs/runJob/getRunTaskFunction.js.map +1 -1
- package/dist/queues/operations/runJobs/runJob/getUpdateJobFunction.d.ts.map +1 -1
- package/dist/queues/operations/runJobs/runJob/getUpdateJobFunction.js +0 -2
- package/dist/queues/operations/runJobs/runJob/getUpdateJobFunction.js.map +1 -1
- package/dist/queues/utilities/updateJob.d.ts +1 -3
- package/dist/queues/utilities/updateJob.d.ts.map +1 -1
- package/dist/queues/utilities/updateJob.js +2 -18
- package/dist/queues/utilities/updateJob.js.map +1 -1
- package/dist/types/index.d.ts +44 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/uploads/getBaseFields.d.ts.map +1 -1
- package/dist/uploads/getBaseFields.js +35 -69
- package/dist/uploads/getBaseFields.js.map +1 -1
- package/dist/uploads/getSafeFilename.d.ts +9 -4
- package/dist/uploads/getSafeFilename.d.ts.map +1 -1
- package/dist/uploads/getSafeFilename.js +5 -5
- package/dist/uploads/getSafeFilename.js.map +1 -1
- package/dist/utilities/appendDateTimezoneSelectFields.d.ts +13 -0
- package/dist/utilities/appendDateTimezoneSelectFields.d.ts.map +1 -0
- package/dist/utilities/appendDateTimezoneSelectFields.js +47 -0
- package/dist/utilities/appendDateTimezoneSelectFields.js.map +1 -0
- package/dist/utilities/appendUploadSelectFields.d.ts.map +1 -1
- package/dist/utilities/appendUploadSelectFields.js +3 -0
- package/dist/utilities/appendUploadSelectFields.js.map +1 -1
- package/dist/utilities/extractID.js +1 -1
- package/dist/utilities/extractID.js.map +1 -1
- package/dist/utilities/flattenAllFields.d.ts.map +1 -1
- package/dist/utilities/flattenAllFields.js +102 -93
- package/dist/utilities/flattenAllFields.js.map +1 -1
- package/dist/utilities/formatAdminURL.d.ts +13 -2
- package/dist/utilities/formatAdminURL.d.ts.map +1 -1
- package/dist/utilities/formatAdminURL.js.map +1 -1
- package/dist/utilities/handleEndpoints.d.ts.map +1 -1
- package/dist/utilities/handleEndpoints.js +0 -1
- package/dist/utilities/handleEndpoints.js.map +1 -1
- package/dist/utilities/resolveSelect.d.ts +16 -0
- package/dist/utilities/resolveSelect.d.ts.map +1 -0
- package/dist/utilities/resolveSelect.js +19 -0
- package/dist/utilities/resolveSelect.js.map +1 -0
- package/dist/utilities/sanitizeProfiler.d.ts +38 -0
- package/dist/utilities/sanitizeProfiler.d.ts.map +1 -0
- package/dist/utilities/sanitizeProfiler.js +101 -0
- package/dist/utilities/sanitizeProfiler.js.map +1 -0
- package/dist/utilities/sanitizeSelect.d.ts +1 -2
- package/dist/utilities/sanitizeSelect.d.ts.map +1 -1
- package/dist/utilities/sanitizeSelect.js +19 -25
- package/dist/utilities/sanitizeSelect.js.map +1 -1
- package/dist/versions/baseFields.d.ts.map +1 -1
- package/dist/versions/baseFields.js +3 -2
- package/dist/versions/baseFields.js.map +1 -1
- package/dist/versions/buildCollectionFields.d.ts.map +1 -1
- package/dist/versions/buildCollectionFields.js +0 -1
- package/dist/versions/buildCollectionFields.js.map +1 -1
- package/dist/versions/buildGlobalFields.d.ts.map +1 -1
- package/dist/versions/buildGlobalFields.js +0 -1
- package/dist/versions/buildGlobalFields.js.map +1 -1
- package/dist/versions/payloadPackageList.d.ts.map +1 -1
- package/dist/versions/payloadPackageList.js +0 -1
- package/dist/versions/payloadPackageList.js.map +1 -1
- package/package.json +4 -4
- package/dist/admin/views/folderList.d.ts +0 -56
- package/dist/admin/views/folderList.d.ts.map +0 -1
- package/dist/admin/views/folderList.js +0 -3
- package/dist/admin/views/folderList.js.map +0 -1
- package/dist/folders/addFolderCollection.d.ts +0 -10
- package/dist/folders/addFolderCollection.d.ts.map +0 -1
- package/dist/folders/addFolderCollection.js +0 -26
- package/dist/folders/addFolderCollection.js.map +0 -1
- package/dist/folders/addFolderFieldToCollection.d.ts +0 -8
- package/dist/folders/addFolderFieldToCollection.d.ts.map +0 -1
- package/dist/folders/addFolderFieldToCollection.js +0 -20
- package/dist/folders/addFolderFieldToCollection.js.map +0 -1
- package/dist/folders/buildFolderField.d.ts +0 -8
- package/dist/folders/buildFolderField.d.ts.map +0 -1
- package/dist/folders/buildFolderField.js +0 -87
- package/dist/folders/buildFolderField.js.map +0 -1
- package/dist/folders/constants.d.ts +0 -3
- package/dist/folders/constants.d.ts.map +0 -1
- package/dist/folders/constants.js +0 -4
- package/dist/folders/constants.js.map +0 -1
- package/dist/folders/createFolderCollection.d.ts +0 -11
- package/dist/folders/createFolderCollection.d.ts.map +0 -1
- package/dist/folders/createFolderCollection.js +0 -115
- package/dist/folders/createFolderCollection.js.map +0 -1
- package/dist/folders/hooks/deleteSubfoldersAfterDelete.d.ts +0 -8
- package/dist/folders/hooks/deleteSubfoldersAfterDelete.d.ts.map +0 -1
- package/dist/folders/hooks/deleteSubfoldersAfterDelete.js +0 -15
- package/dist/folders/hooks/deleteSubfoldersAfterDelete.js.map +0 -1
- package/dist/folders/hooks/dissasociateAfterDelete.d.ts +0 -8
- package/dist/folders/hooks/dissasociateAfterDelete.d.ts.map +0 -1
- package/dist/folders/hooks/dissasociateAfterDelete.js +0 -20
- package/dist/folders/hooks/dissasociateAfterDelete.js.map +0 -1
- package/dist/folders/hooks/ensureSafeCollectionsChange.d.ts +0 -5
- package/dist/folders/hooks/ensureSafeCollectionsChange.d.ts.map +0 -1
- package/dist/folders/hooks/ensureSafeCollectionsChange.js +0 -107
- package/dist/folders/hooks/ensureSafeCollectionsChange.js.map +0 -1
- package/dist/folders/hooks/reparentChildFolder.d.ts +0 -24
- package/dist/folders/hooks/reparentChildFolder.d.ts.map +0 -1
- package/dist/folders/hooks/reparentChildFolder.js +0 -72
- package/dist/folders/hooks/reparentChildFolder.js.map +0 -1
- package/dist/folders/types.d.ts +0 -118
- package/dist/folders/types.d.ts.map +0 -1
- package/dist/folders/types.js +0 -3
- package/dist/folders/types.js.map +0 -1
- package/dist/folders/utils/buildFolderWhereConstraints.d.ts +0 -13
- package/dist/folders/utils/buildFolderWhereConstraints.d.ts.map +0 -1
- package/dist/folders/utils/buildFolderWhereConstraints.js +0 -45
- package/dist/folders/utils/buildFolderWhereConstraints.js.map +0 -1
- package/dist/folders/utils/formatFolderOrDocumentItem.d.ts +0 -12
- package/dist/folders/utils/formatFolderOrDocumentItem.d.ts.map +0 -1
- package/dist/folders/utils/formatFolderOrDocumentItem.js +0 -30
- package/dist/folders/utils/formatFolderOrDocumentItem.js.map +0 -1
- package/dist/folders/utils/getFolderBreadcrumbs.d.ts +0 -14
- package/dist/folders/utils/getFolderBreadcrumbs.d.ts.map +0 -1
- package/dist/folders/utils/getFolderBreadcrumbs.js +0 -45
- package/dist/folders/utils/getFolderBreadcrumbs.js.map +0 -1
- package/dist/folders/utils/getFolderData.d.ts +0 -33
- package/dist/folders/utils/getFolderData.d.ts.map +0 -1
- package/dist/folders/utils/getFolderData.js +0 -88
- package/dist/folders/utils/getFolderData.js.map +0 -1
- package/dist/folders/utils/getFoldersAndDocumentsFromJoin.d.ts +0 -24
- package/dist/folders/utils/getFoldersAndDocumentsFromJoin.d.ts.map +0 -1
- package/dist/folders/utils/getFoldersAndDocumentsFromJoin.js +0 -66
- package/dist/folders/utils/getFoldersAndDocumentsFromJoin.js.map +0 -1
- package/dist/folders/utils/getOrphanedDocs.d.ts +0 -15
- package/dist/folders/utils/getOrphanedDocs.d.ts.map +0 -1
- package/dist/folders/utils/getOrphanedDocs.js +0 -40
- package/dist/folders/utils/getOrphanedDocs.js.map +0 -1
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
import { slugify as payloadSlugify } from '../../utilities/slugify.js';
|
|
2
|
+
import { HIERARCHY_SLUG_PATH_FIELD, HIERARCHY_TITLE_PATH_FIELD } from '../constants.js';
|
|
3
|
+
import { buildLocalizedHierarchyPaths } from './buildLocalizedHierarchyPaths.js';
|
|
4
|
+
import { findFieldByName, findUseAsTitleField } from './findUseAsTitle.js';
|
|
5
|
+
import { getLocalizedValue } from './getLocalizedValue.js';
|
|
6
|
+
// Helper to get title value - returns string for single locale, object for 'all' locales
|
|
7
|
+
const getTitleValue = ({ document, isTitleLocalized = false, locale, req, titleFieldName })=>{
|
|
8
|
+
const titleValue = document[titleFieldName];
|
|
9
|
+
if (!titleValue) {
|
|
10
|
+
return document.id?.toString() || 'untitled';
|
|
11
|
+
}
|
|
12
|
+
// If field is localized and we want all locales, return the full object
|
|
13
|
+
if (isTitleLocalized && locale === 'all' && typeof titleValue === 'object') {
|
|
14
|
+
return titleValue;
|
|
15
|
+
}
|
|
16
|
+
// Single locale - use getLocalizedValue to handle fallback
|
|
17
|
+
if (isTitleLocalized && typeof titleValue === 'object') {
|
|
18
|
+
const localizedValue = getLocalizedValue({
|
|
19
|
+
fallbackLocale: req.fallbackLocale,
|
|
20
|
+
fieldType: 'text',
|
|
21
|
+
locale: locale || req.locale || 'en',
|
|
22
|
+
value: titleValue
|
|
23
|
+
});
|
|
24
|
+
return localizedValue || document.id?.toString() || 'untitled';
|
|
25
|
+
}
|
|
26
|
+
return titleValue;
|
|
27
|
+
};
|
|
28
|
+
// Helper to get slug value from a dedicated slug field
|
|
29
|
+
const getSlugFieldValue = ({ document, isSlugLocalized = false, locale, req, slugFieldName })=>{
|
|
30
|
+
const slugValue = document[slugFieldName];
|
|
31
|
+
if (!slugValue) {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
// If field is localized and we want all locales, return the full object
|
|
35
|
+
if (isSlugLocalized && locale === 'all' && typeof slugValue === 'object') {
|
|
36
|
+
return slugValue;
|
|
37
|
+
}
|
|
38
|
+
// Single locale - use getLocalizedValue to handle fallback
|
|
39
|
+
if (isSlugLocalized && typeof slugValue === 'object') {
|
|
40
|
+
const localizedValue = getLocalizedValue({
|
|
41
|
+
fallbackLocale: req.fallbackLocale,
|
|
42
|
+
fieldType: 'text',
|
|
43
|
+
locale: locale || req.locale || 'en',
|
|
44
|
+
value: slugValue
|
|
45
|
+
});
|
|
46
|
+
return localizedValue || undefined;
|
|
47
|
+
}
|
|
48
|
+
return slugValue;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Computes both slug and title breadcrumb paths for a document by walking up the parent chain.
|
|
52
|
+
* More efficient than computing them separately since it only walks the chain once.
|
|
53
|
+
*
|
|
54
|
+
* Note: Ancestor fetches always use `overrideAccess: true` to ensure paths are complete.
|
|
55
|
+
* If a user can read a document, they should see its full breadcrumb path even if they
|
|
56
|
+
* cannot read all ancestor documents. This prevents broken breadcrumbs and provides
|
|
57
|
+
* better UX at the cost of minimal information leakage (ancestor titles in paths).
|
|
58
|
+
*
|
|
59
|
+
* @param args - Configuration for path computation
|
|
60
|
+
* @returns Object with slugPath and titlePath
|
|
61
|
+
*/ export async function computePaths(args) {
|
|
62
|
+
const { collection, doc, draft = false, locale, parentFieldName, req, slugPathFieldName = HIERARCHY_SLUG_PATH_FIELD, titlePathFieldName = HIERARCHY_TITLE_PATH_FIELD } = args;
|
|
63
|
+
const slugify = collection.hierarchy !== false && collection.hierarchy.slugify || ((text)=>payloadSlugify(text) || '');
|
|
64
|
+
const { localized: isTitleLocalized, titleFieldName } = findUseAsTitleField(collection);
|
|
65
|
+
// Check for dedicated slug field
|
|
66
|
+
const slugFieldName = collection.hierarchy !== false ? collection.hierarchy.slugField : undefined;
|
|
67
|
+
const slugFieldInfo = slugFieldName ? findFieldByName(collection, slugFieldName) : undefined;
|
|
68
|
+
const isSlugFieldLocalized = slugFieldInfo?.localized ?? false;
|
|
69
|
+
// Initialize cache if it doesn't exist
|
|
70
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
71
|
+
const context = req.context;
|
|
72
|
+
if (!context.hierarchyAncestorCache) {
|
|
73
|
+
context.hierarchyAncestorCache = {};
|
|
74
|
+
}
|
|
75
|
+
if (!context.hierarchyAncestorCache[collection.slug]) {
|
|
76
|
+
context.hierarchyAncestorCache[collection.slug] = {};
|
|
77
|
+
}
|
|
78
|
+
// Initialize cache stats if debug is enabled
|
|
79
|
+
if (req.payload.config.debug && !context.hierarchyCacheStats) {
|
|
80
|
+
context.hierarchyCacheStats = {
|
|
81
|
+
hits: 0,
|
|
82
|
+
misses: 0,
|
|
83
|
+
queries: 0
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
const parentValue = doc[parentFieldName];
|
|
87
|
+
let parentID;
|
|
88
|
+
if (!parentValue) {
|
|
89
|
+
// No parent - root document
|
|
90
|
+
parentID = undefined;
|
|
91
|
+
} else {
|
|
92
|
+
// Extract ID from parent value
|
|
93
|
+
// Parent can be:
|
|
94
|
+
// - Plain ID (string/number)
|
|
95
|
+
// - Populated object with { id: ... }
|
|
96
|
+
if (typeof parentValue === 'object' && 'id' in parentValue) {
|
|
97
|
+
parentID = parentValue.id;
|
|
98
|
+
} else {
|
|
99
|
+
parentID = parentValue;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (parentID) {
|
|
103
|
+
// Parent is always from the same collection (self-referential)
|
|
104
|
+
const parentCollectionConfig = collection;
|
|
105
|
+
const parentHierarchyConfig = parentCollectionConfig.hierarchy;
|
|
106
|
+
// If parent collection doesn't have hierarchy, we can't compute paths through it
|
|
107
|
+
if (!parentHierarchyConfig || !parentCollectionConfig) {
|
|
108
|
+
const titleValue = getTitleValue({
|
|
109
|
+
document: doc,
|
|
110
|
+
isTitleLocalized,
|
|
111
|
+
locale,
|
|
112
|
+
req,
|
|
113
|
+
titleFieldName
|
|
114
|
+
});
|
|
115
|
+
const slugValue = slugFieldName ? getSlugFieldValue({
|
|
116
|
+
document: doc,
|
|
117
|
+
isSlugLocalized: isSlugFieldLocalized,
|
|
118
|
+
locale,
|
|
119
|
+
req,
|
|
120
|
+
slugFieldName
|
|
121
|
+
}) : undefined;
|
|
122
|
+
if (isTitleLocalized && locale === 'all') {
|
|
123
|
+
return buildLocalizedHierarchyPaths({
|
|
124
|
+
req,
|
|
125
|
+
slugify,
|
|
126
|
+
slugValue: slugValue,
|
|
127
|
+
titleValue: titleValue
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
return {
|
|
131
|
+
slugPath: slugValue !== undefined ? slugValue : slugify(titleValue),
|
|
132
|
+
titlePath: titleValue
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
// Initialize cache for parent collection if needed
|
|
136
|
+
if (!context.hierarchyAncestorCache[collection.slug]) {
|
|
137
|
+
context.hierarchyAncestorCache[collection.slug] = {};
|
|
138
|
+
}
|
|
139
|
+
const cache = context.hierarchyAncestorCache[collection.slug];
|
|
140
|
+
const cacheKey = `${parentID}_${locale || 'default'}`;
|
|
141
|
+
// Check cache first
|
|
142
|
+
let parent = cache[cacheKey];
|
|
143
|
+
if (parent) {
|
|
144
|
+
// Cache hit
|
|
145
|
+
if (context.hierarchyCacheStats) {
|
|
146
|
+
context.hierarchyCacheStats.hits += 1;
|
|
147
|
+
}
|
|
148
|
+
} else {
|
|
149
|
+
// Cache miss - fetch parent
|
|
150
|
+
if (context.hierarchyCacheStats) {
|
|
151
|
+
context.hierarchyCacheStats.misses += 1;
|
|
152
|
+
context.hierarchyCacheStats.queries += 1;
|
|
153
|
+
}
|
|
154
|
+
const parentTitleField = findUseAsTitleField(parentCollectionConfig).titleFieldName;
|
|
155
|
+
// parentID is guaranteed to be defined here (we're inside if (parentID))
|
|
156
|
+
const validParentID = parentID;
|
|
157
|
+
// Create new context with computeHierarchyPaths enabled to trigger recursive path computation
|
|
158
|
+
const parentReq = {
|
|
159
|
+
...req,
|
|
160
|
+
context: {
|
|
161
|
+
...req.context,
|
|
162
|
+
computeHierarchyPaths: true
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
// Fetch parent
|
|
166
|
+
// When locale === 'all', we need special handling because Payload doesn't support
|
|
167
|
+
// fetching all locales of a draft document (drafts are stored per-locale).
|
|
168
|
+
// Strategy: Try published first, fallback to fetching each locale separately for drafts.
|
|
169
|
+
const fetchParent = async ()=>{
|
|
170
|
+
if (locale === 'all') {
|
|
171
|
+
try {
|
|
172
|
+
// First try to fetch published version with all locales
|
|
173
|
+
return await req.payload.findByID({
|
|
174
|
+
id: validParentID,
|
|
175
|
+
collection: collection.slug,
|
|
176
|
+
depth: 0,
|
|
177
|
+
locale,
|
|
178
|
+
overrideAccess: true,
|
|
179
|
+
req: parentReq,
|
|
180
|
+
select: {
|
|
181
|
+
[parentHierarchyConfig.parentFieldName]: true,
|
|
182
|
+
[parentHierarchyConfig.slugPathFieldName]: true,
|
|
183
|
+
[parentHierarchyConfig.titlePathFieldName]: true,
|
|
184
|
+
[parentTitleField]: true,
|
|
185
|
+
...slugFieldName ? {
|
|
186
|
+
[slugFieldName]: true
|
|
187
|
+
} : {}
|
|
188
|
+
},
|
|
189
|
+
user: req.user
|
|
190
|
+
});
|
|
191
|
+
} catch (_error) {
|
|
192
|
+
// Published version not found, must be a draft
|
|
193
|
+
// Payload doesn't support fetching all locales of a draft with a single query
|
|
194
|
+
// So we need to fetch each locale separately and combine the path data
|
|
195
|
+
const locales = req.payload.config.localization ? req.payload.config.localization.localeCodes : [];
|
|
196
|
+
const parentPathsByLocale = {};
|
|
197
|
+
// Get parent collection's slugify function (may differ from child's)
|
|
198
|
+
const parentSlugify = parentCollectionConfig.hierarchy !== false && parentCollectionConfig.hierarchy.slugify || ((text)=>payloadSlugify(text) || '');
|
|
199
|
+
// Fetch parent for each locale to get paths
|
|
200
|
+
for (const loc of locales){
|
|
201
|
+
// Create a new request with this specific locale but keep computeHierarchyPaths flag
|
|
202
|
+
const localeReq = {
|
|
203
|
+
...req,
|
|
204
|
+
context: {
|
|
205
|
+
...req.context,
|
|
206
|
+
computeHierarchyPaths: true
|
|
207
|
+
},
|
|
208
|
+
locale: loc
|
|
209
|
+
};
|
|
210
|
+
try {
|
|
211
|
+
const parentForLocale = await req.payload.findByID({
|
|
212
|
+
id: validParentID,
|
|
213
|
+
collection: collection.slug,
|
|
214
|
+
depth: 0,
|
|
215
|
+
draft: true,
|
|
216
|
+
locale: loc,
|
|
217
|
+
overrideAccess: true,
|
|
218
|
+
req: localeReq,
|
|
219
|
+
user: req.user
|
|
220
|
+
});
|
|
221
|
+
// Extract the path fields and title from the parent
|
|
222
|
+
// If paths weren't computed (undefined), compute them manually for root documents
|
|
223
|
+
let parentSlugPath = parentForLocale[parentHierarchyConfig.slugPathFieldName];
|
|
224
|
+
let parentTitlePath = parentForLocale[parentHierarchyConfig.titlePathFieldName];
|
|
225
|
+
const parentTitle = parentForLocale[parentTitleField];
|
|
226
|
+
// If paths are undefined, this might be a root document - compute paths from title
|
|
227
|
+
if (!parentSlugPath && parentTitle) {
|
|
228
|
+
parentSlugPath = parentSlugify(parentTitle);
|
|
229
|
+
}
|
|
230
|
+
if (!parentTitlePath && parentTitle) {
|
|
231
|
+
parentTitlePath = parentTitle;
|
|
232
|
+
}
|
|
233
|
+
parentPathsByLocale[loc] = {
|
|
234
|
+
slugPath: parentSlugPath,
|
|
235
|
+
title: parentTitle,
|
|
236
|
+
titlePath: parentTitlePath
|
|
237
|
+
};
|
|
238
|
+
} catch (_localeError) {
|
|
239
|
+
// This locale doesn't exist, skip it
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
// Combine the path data from all locales into a single parent object
|
|
243
|
+
const combinedSlugPaths = {};
|
|
244
|
+
const combinedTitlePaths = {};
|
|
245
|
+
const combinedTitles = {};
|
|
246
|
+
for (const loc of locales){
|
|
247
|
+
if (parentPathsByLocale[loc]) {
|
|
248
|
+
combinedSlugPaths[loc] = parentPathsByLocale[loc].slugPath;
|
|
249
|
+
combinedTitlePaths[loc] = parentPathsByLocale[loc].titlePath;
|
|
250
|
+
combinedTitles[loc] = parentPathsByLocale[loc].title;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
// Return a parent object with only the hierarchy fields we need
|
|
254
|
+
// (all properly formatted as multi-locale objects)
|
|
255
|
+
return {
|
|
256
|
+
id: validParentID,
|
|
257
|
+
[parentHierarchyConfig.slugPathFieldName]: combinedSlugPaths,
|
|
258
|
+
[parentHierarchyConfig.titlePathFieldName]: combinedTitlePaths,
|
|
259
|
+
[parentTitleField]: combinedTitles
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
} else {
|
|
263
|
+
// Normal case: single locale, can pass draft parameter
|
|
264
|
+
return await req.payload.findByID({
|
|
265
|
+
id: validParentID,
|
|
266
|
+
collection: collection.slug,
|
|
267
|
+
depth: 0,
|
|
268
|
+
draft,
|
|
269
|
+
locale,
|
|
270
|
+
overrideAccess: true,
|
|
271
|
+
req: parentReq,
|
|
272
|
+
select: {
|
|
273
|
+
[parentHierarchyConfig.parentFieldName]: true,
|
|
274
|
+
[parentHierarchyConfig.slugPathFieldName]: true,
|
|
275
|
+
[parentHierarchyConfig.titlePathFieldName]: true,
|
|
276
|
+
[parentTitleField]: true,
|
|
277
|
+
...slugFieldName ? {
|
|
278
|
+
[slugFieldName]: true
|
|
279
|
+
} : {}
|
|
280
|
+
},
|
|
281
|
+
user: req.user
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
try {
|
|
286
|
+
parent = await fetchParent();
|
|
287
|
+
// Store in cache
|
|
288
|
+
cache[cacheKey] = parent;
|
|
289
|
+
} catch {
|
|
290
|
+
// If we can't fetch the parent at all (even with fallbacks), treat this as a root document
|
|
291
|
+
// This can happen with complex draft/locale combinations
|
|
292
|
+
parentID = undefined;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
// If parent fetch failed, treat as root document
|
|
296
|
+
if (!parentID || !parent) {
|
|
297
|
+
const titleValue = getTitleValue({
|
|
298
|
+
document: doc,
|
|
299
|
+
isTitleLocalized,
|
|
300
|
+
locale,
|
|
301
|
+
req,
|
|
302
|
+
titleFieldName
|
|
303
|
+
});
|
|
304
|
+
const slugValue = slugFieldName ? getSlugFieldValue({
|
|
305
|
+
document: doc,
|
|
306
|
+
isSlugLocalized: isSlugFieldLocalized,
|
|
307
|
+
locale,
|
|
308
|
+
req,
|
|
309
|
+
slugFieldName
|
|
310
|
+
}) : undefined;
|
|
311
|
+
if (isTitleLocalized && locale === 'all') {
|
|
312
|
+
return buildLocalizedHierarchyPaths({
|
|
313
|
+
req,
|
|
314
|
+
slugify,
|
|
315
|
+
slugValue: slugValue,
|
|
316
|
+
titleValue: titleValue
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
return {
|
|
320
|
+
slugPath: slugValue !== undefined ? slugValue : slugify(titleValue),
|
|
321
|
+
titlePath: titleValue
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
const docTitle = getTitleValue({
|
|
325
|
+
document: doc,
|
|
326
|
+
isTitleLocalized,
|
|
327
|
+
locale,
|
|
328
|
+
req,
|
|
329
|
+
titleFieldName
|
|
330
|
+
});
|
|
331
|
+
// Cache the current document (in its own collection's cache)
|
|
332
|
+
const currentDocCacheKey = `${doc.id}_${locale || 'default'}`;
|
|
333
|
+
if (!context.hierarchyAncestorCache[collection.slug]) {
|
|
334
|
+
context.hierarchyAncestorCache[collection.slug] = {};
|
|
335
|
+
}
|
|
336
|
+
context.hierarchyAncestorCache[collection.slug][currentDocCacheKey] = {
|
|
337
|
+
[parentFieldName]: parentID,
|
|
338
|
+
[slugPathFieldName]: undefined,
|
|
339
|
+
[titleFieldName]: docTitle,
|
|
340
|
+
[titlePathFieldName]: undefined
|
|
341
|
+
};
|
|
342
|
+
// Get parent's path field names from hierarchy config
|
|
343
|
+
const parentSlugPathFieldName = parentCollectionConfig.hierarchy !== false ? parentCollectionConfig.hierarchy.slugPathFieldName : HIERARCHY_SLUG_PATH_FIELD;
|
|
344
|
+
const parentTitlePathFieldName = parentCollectionConfig.hierarchy !== false ? parentCollectionConfig.hierarchy.titlePathFieldName : HIERARCHY_TITLE_PATH_FIELD;
|
|
345
|
+
// Handle localized case (locale === 'all' with localized title field)
|
|
346
|
+
if (isTitleLocalized && locale === 'all') {
|
|
347
|
+
// Parent might have non-localized title field, resulting in string paths instead of objects
|
|
348
|
+
// Convert parent paths to objects if they're strings (use same value for all locales)
|
|
349
|
+
let parentSlugPathObj = parent[parentSlugPathFieldName];
|
|
350
|
+
let parentTitlePathObj = parent[parentTitlePathFieldName];
|
|
351
|
+
// If parent paths are strings (non-localized parent), convert to objects for all locales
|
|
352
|
+
if (typeof parentSlugPathObj === 'string') {
|
|
353
|
+
const locales = req.payload.config.localization ? req.payload.config.localization.localeCodes : [];
|
|
354
|
+
const slugValue = parentSlugPathObj;
|
|
355
|
+
parentSlugPathObj = {};
|
|
356
|
+
for (const loc of locales){
|
|
357
|
+
parentSlugPathObj[loc] = slugValue;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
if (typeof parentTitlePathObj === 'string') {
|
|
361
|
+
const locales = req.payload.config.localization ? req.payload.config.localization.localeCodes : [];
|
|
362
|
+
const titleValue = parentTitlePathObj;
|
|
363
|
+
parentTitlePathObj = {};
|
|
364
|
+
for (const loc of locales){
|
|
365
|
+
parentTitlePathObj[loc] = titleValue;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
// Get slug value if slugField is configured
|
|
369
|
+
const docSlugValue = slugFieldName ? getSlugFieldValue({
|
|
370
|
+
document: doc,
|
|
371
|
+
isSlugLocalized: isSlugFieldLocalized,
|
|
372
|
+
locale,
|
|
373
|
+
req,
|
|
374
|
+
slugFieldName
|
|
375
|
+
}) : undefined;
|
|
376
|
+
// If parent paths are undefined (parent fetch failed or paths not computed),
|
|
377
|
+
// buildLocalizedHierarchyPaths will handle it by using just the child's title
|
|
378
|
+
const result = buildLocalizedHierarchyPaths({
|
|
379
|
+
parentSlugPath: parentSlugPathObj,
|
|
380
|
+
parentTitlePath: parentTitlePathObj,
|
|
381
|
+
req,
|
|
382
|
+
slugify,
|
|
383
|
+
slugValue: docSlugValue,
|
|
384
|
+
titleValue: docTitle
|
|
385
|
+
});
|
|
386
|
+
// Update cache with computed paths
|
|
387
|
+
context.hierarchyAncestorCache[collection.slug][currentDocCacheKey][slugPathFieldName] = result.slugPath;
|
|
388
|
+
context.hierarchyAncestorCache[collection.slug][currentDocCacheKey][titlePathFieldName] = result.titlePath;
|
|
389
|
+
return result;
|
|
390
|
+
}
|
|
391
|
+
// Single locale case - get slug value if slugField is configured
|
|
392
|
+
const singleLocaleSlugValue = slugFieldName ? getSlugFieldValue({
|
|
393
|
+
document: doc,
|
|
394
|
+
isSlugLocalized: isSlugFieldLocalized,
|
|
395
|
+
locale,
|
|
396
|
+
req,
|
|
397
|
+
slugFieldName
|
|
398
|
+
}) : undefined;
|
|
399
|
+
const slugSegment = singleLocaleSlugValue !== undefined ? singleLocaleSlugValue : slugify(docTitle);
|
|
400
|
+
const result = {
|
|
401
|
+
slugPath: parent[parentSlugPathFieldName] + '/' + slugSegment,
|
|
402
|
+
titlePath: parent[parentTitlePathFieldName] + '/' + docTitle
|
|
403
|
+
};
|
|
404
|
+
// Update cache with computed paths
|
|
405
|
+
context.hierarchyAncestorCache[collection.slug][currentDocCacheKey][slugPathFieldName] = result.slugPath;
|
|
406
|
+
context.hierarchyAncestorCache[collection.slug][currentDocCacheKey][titlePathFieldName] = result.titlePath;
|
|
407
|
+
return result;
|
|
408
|
+
} else {
|
|
409
|
+
// Root document (no parent)
|
|
410
|
+
const titleValue = getTitleValue({
|
|
411
|
+
document: doc,
|
|
412
|
+
isTitleLocalized,
|
|
413
|
+
locale,
|
|
414
|
+
req,
|
|
415
|
+
titleFieldName
|
|
416
|
+
});
|
|
417
|
+
context.hierarchyAncestorCache[collection.slug][doc.id] = {
|
|
418
|
+
[parentFieldName]: null,
|
|
419
|
+
[titleFieldName]: titleValue
|
|
420
|
+
};
|
|
421
|
+
const rootSlugValue = slugFieldName ? getSlugFieldValue({
|
|
422
|
+
document: doc,
|
|
423
|
+
isSlugLocalized: isSlugFieldLocalized,
|
|
424
|
+
locale,
|
|
425
|
+
req,
|
|
426
|
+
slugFieldName
|
|
427
|
+
}) : undefined;
|
|
428
|
+
// Handle localized case (locale === 'all' with localized title field)
|
|
429
|
+
if (isTitleLocalized && locale === 'all') {
|
|
430
|
+
return buildLocalizedHierarchyPaths({
|
|
431
|
+
req,
|
|
432
|
+
slugify,
|
|
433
|
+
slugValue: rootSlugValue,
|
|
434
|
+
titleValue: titleValue
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
// Single locale case
|
|
438
|
+
return {
|
|
439
|
+
slugPath: rootSlugValue !== undefined ? rootSlugValue : slugify(titleValue),
|
|
440
|
+
titlePath: titleValue
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
//# sourceMappingURL=computePaths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/hierarchy/utils/computePaths.ts"],"sourcesContent":["import type { SanitizedCollectionConfig } from '../../collections/config/types.js'\nimport type { Document, PayloadRequest } from '../../types/index.js'\n\nimport { slugify as payloadSlugify } from '../../utilities/slugify.js'\nimport { HIERARCHY_SLUG_PATH_FIELD, HIERARCHY_TITLE_PATH_FIELD } from '../constants.js'\nimport { buildLocalizedHierarchyPaths } from './buildLocalizedHierarchyPaths.js'\nimport { findFieldByName, findUseAsTitleField } from './findUseAsTitle.js'\nimport { getLocalizedValue } from './getLocalizedValue.js'\n\ntype ComputePathsArgs = {\n collection: SanitizedCollectionConfig\n doc: Document\n draft?: boolean\n locale?: string\n parentFieldName: string\n req: PayloadRequest\n slugPathFieldName?: string\n titlePathFieldName?: string\n}\n\ntype ComputePathsResult = {\n slugPath: Record<string, string> | string\n titlePath: Record<string, string> | string\n}\n\n// Helper to get title value - returns string for single locale, object for 'all' locales\nconst getTitleValue = ({\n document,\n isTitleLocalized = false,\n locale,\n req,\n titleFieldName,\n}: {\n document: Document\n isTitleLocalized?: boolean\n locale?: string\n req: PayloadRequest\n titleFieldName: string\n}): Record<string, string> | string => {\n const titleValue = document[titleFieldName]\n\n if (!titleValue) {\n return document.id?.toString() || 'untitled'\n }\n\n // If field is localized and we want all locales, return the full object\n if (isTitleLocalized && locale === 'all' && typeof titleValue === 'object') {\n return titleValue\n }\n\n // Single locale - use getLocalizedValue to handle fallback\n if (isTitleLocalized && typeof titleValue === 'object') {\n const localizedValue = getLocalizedValue({\n fallbackLocale: req.fallbackLocale,\n fieldType: 'text',\n locale: locale || req.locale || 'en',\n value: titleValue,\n })\n return localizedValue || document.id?.toString() || 'untitled'\n }\n\n return titleValue\n}\n\n// Helper to get slug value from a dedicated slug field\nconst getSlugFieldValue = ({\n document,\n isSlugLocalized = false,\n locale,\n req,\n slugFieldName,\n}: {\n document: Document\n isSlugLocalized?: boolean\n locale?: string\n req: PayloadRequest\n slugFieldName: string\n}): Record<string, string> | string | undefined => {\n const slugValue = document[slugFieldName]\n\n if (!slugValue) {\n return undefined\n }\n\n // If field is localized and we want all locales, return the full object\n if (isSlugLocalized && locale === 'all' && typeof slugValue === 'object') {\n return slugValue\n }\n\n // Single locale - use getLocalizedValue to handle fallback\n if (isSlugLocalized && typeof slugValue === 'object') {\n const localizedValue = getLocalizedValue({\n fallbackLocale: req.fallbackLocale,\n fieldType: 'text',\n locale: locale || req.locale || 'en',\n value: slugValue,\n })\n return localizedValue || undefined\n }\n\n return slugValue\n}\n\n/**\n * Computes both slug and title breadcrumb paths for a document by walking up the parent chain.\n * More efficient than computing them separately since it only walks the chain once.\n *\n * Note: Ancestor fetches always use `overrideAccess: true` to ensure paths are complete.\n * If a user can read a document, they should see its full breadcrumb path even if they\n * cannot read all ancestor documents. This prevents broken breadcrumbs and provides\n * better UX at the cost of minimal information leakage (ancestor titles in paths).\n *\n * @param args - Configuration for path computation\n * @returns Object with slugPath and titlePath\n */\nexport async function computePaths(args: ComputePathsArgs): Promise<ComputePathsResult> {\n const {\n collection,\n doc,\n draft = false,\n locale,\n parentFieldName,\n req,\n slugPathFieldName = HIERARCHY_SLUG_PATH_FIELD,\n titlePathFieldName = HIERARCHY_TITLE_PATH_FIELD,\n } = args\n\n const slugify =\n (collection.hierarchy !== false && collection.hierarchy.slugify) ||\n ((text: string) => payloadSlugify(text) || '')\n const { localized: isTitleLocalized, titleFieldName } = findUseAsTitleField(collection)\n\n // Check for dedicated slug field\n const slugFieldName = collection.hierarchy !== false ? collection.hierarchy.slugField : undefined\n const slugFieldInfo = slugFieldName ? findFieldByName(collection, slugFieldName) : undefined\n const isSlugFieldLocalized = slugFieldInfo?.localized ?? false\n\n // Initialize cache if it doesn't exist\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const context = req.context as any\n if (!context.hierarchyAncestorCache) {\n context.hierarchyAncestorCache = {}\n }\n if (!context.hierarchyAncestorCache[collection.slug]) {\n context.hierarchyAncestorCache[collection.slug] = {}\n }\n\n // Initialize cache stats if debug is enabled\n if (req.payload.config.debug && !context.hierarchyCacheStats) {\n context.hierarchyCacheStats = {\n hits: 0,\n misses: 0,\n queries: 0,\n }\n }\n\n const parentValue = doc[parentFieldName]\n let parentID: number | string | undefined\n\n if (!parentValue) {\n // No parent - root document\n parentID = undefined\n } else {\n // Extract ID from parent value\n // Parent can be:\n // - Plain ID (string/number)\n // - Populated object with { id: ... }\n if (typeof parentValue === 'object' && 'id' in parentValue) {\n parentID = parentValue.id\n } else {\n parentID = parentValue as number | string\n }\n }\n\n if (parentID) {\n // Parent is always from the same collection (self-referential)\n const parentCollectionConfig = collection\n const parentHierarchyConfig = parentCollectionConfig.hierarchy\n\n // If parent collection doesn't have hierarchy, we can't compute paths through it\n if (!parentHierarchyConfig || !parentCollectionConfig) {\n const titleValue = getTitleValue({\n document: doc,\n isTitleLocalized,\n locale,\n req,\n titleFieldName,\n })\n\n const slugValue = slugFieldName\n ? getSlugFieldValue({\n document: doc,\n isSlugLocalized: isSlugFieldLocalized,\n locale,\n req,\n slugFieldName,\n })\n : undefined\n\n if (isTitleLocalized && locale === 'all') {\n return buildLocalizedHierarchyPaths({\n req,\n slugify,\n slugValue: slugValue as Record<string, string> | undefined,\n titleValue: titleValue as Record<string, string>,\n })\n }\n\n return {\n slugPath: slugValue !== undefined ? (slugValue as string) : slugify(titleValue as string),\n titlePath: titleValue as string,\n }\n }\n\n // Initialize cache for parent collection if needed\n if (!context.hierarchyAncestorCache[collection.slug]) {\n context.hierarchyAncestorCache[collection.slug] = {}\n }\n\n const cache = context.hierarchyAncestorCache[collection.slug]\n const cacheKey = `${parentID}_${locale || 'default'}`\n\n // Check cache first\n let parent = cache[cacheKey]\n\n if (parent) {\n // Cache hit\n if (context.hierarchyCacheStats) {\n context.hierarchyCacheStats.hits += 1\n }\n } else {\n // Cache miss - fetch parent\n if (context.hierarchyCacheStats) {\n context.hierarchyCacheStats.misses += 1\n context.hierarchyCacheStats.queries += 1\n }\n\n const parentTitleField = findUseAsTitleField(parentCollectionConfig).titleFieldName\n\n // parentID is guaranteed to be defined here (we're inside if (parentID))\n const validParentID = parentID\n\n // Create new context with computeHierarchyPaths enabled to trigger recursive path computation\n const parentReq = {\n ...req,\n context: {\n ...req.context,\n computeHierarchyPaths: true,\n },\n }\n\n // Fetch parent\n // When locale === 'all', we need special handling because Payload doesn't support\n // fetching all locales of a draft document (drafts are stored per-locale).\n // Strategy: Try published first, fallback to fetching each locale separately for drafts.\n const fetchParent = async () => {\n if (locale === 'all') {\n try {\n // First try to fetch published version with all locales\n return await req.payload.findByID({\n id: validParentID,\n collection: collection.slug,\n depth: 0,\n locale,\n overrideAccess: true,\n req: parentReq,\n select: {\n [parentHierarchyConfig.parentFieldName]: true,\n [parentHierarchyConfig.slugPathFieldName]: true,\n [parentHierarchyConfig.titlePathFieldName]: true,\n [parentTitleField]: true,\n ...(slugFieldName ? { [slugFieldName]: true } : {}),\n },\n user: req.user,\n })\n } catch (_error) {\n // Published version not found, must be a draft\n // Payload doesn't support fetching all locales of a draft with a single query\n // So we need to fetch each locale separately and combine the path data\n const locales = req.payload.config.localization\n ? req.payload.config.localization.localeCodes\n : []\n const parentPathsByLocale: Record<\n string,\n { slugPath?: string; title?: string; titlePath?: string }\n > = {}\n\n // Get parent collection's slugify function (may differ from child's)\n const parentSlugify =\n (parentCollectionConfig.hierarchy !== false &&\n parentCollectionConfig.hierarchy.slugify) ||\n ((text: string) => payloadSlugify(text) || '')\n\n // Fetch parent for each locale to get paths\n for (const loc of locales) {\n // Create a new request with this specific locale but keep computeHierarchyPaths flag\n const localeReq = {\n ...req,\n context: {\n ...req.context,\n computeHierarchyPaths: true,\n },\n locale: loc,\n }\n\n try {\n const parentForLocale = await req.payload.findByID({\n id: validParentID,\n collection: collection.slug,\n depth: 0,\n draft: true,\n locale: loc,\n overrideAccess: true,\n req: localeReq,\n user: req.user,\n })\n\n // Extract the path fields and title from the parent\n // If paths weren't computed (undefined), compute them manually for root documents\n let parentSlugPath = parentForLocale[parentHierarchyConfig.slugPathFieldName]\n let parentTitlePath = parentForLocale[parentHierarchyConfig.titlePathFieldName]\n const parentTitle = parentForLocale[parentTitleField]\n\n // If paths are undefined, this might be a root document - compute paths from title\n if (!parentSlugPath && parentTitle) {\n parentSlugPath = parentSlugify(parentTitle)\n }\n if (!parentTitlePath && parentTitle) {\n parentTitlePath = parentTitle\n }\n\n parentPathsByLocale[loc] = {\n slugPath: parentSlugPath,\n title: parentTitle,\n titlePath: parentTitlePath,\n }\n } catch (_localeError) {\n // This locale doesn't exist, skip it\n }\n }\n\n // Combine the path data from all locales into a single parent object\n const combinedSlugPaths: Record<string, string | undefined> = {}\n const combinedTitlePaths: Record<string, string | undefined> = {}\n const combinedTitles: Record<string, string | undefined> = {}\n\n for (const loc of locales) {\n if (parentPathsByLocale[loc]) {\n combinedSlugPaths[loc] = parentPathsByLocale[loc].slugPath\n combinedTitlePaths[loc] = parentPathsByLocale[loc].titlePath\n combinedTitles[loc] = parentPathsByLocale[loc].title\n }\n }\n\n // Return a parent object with only the hierarchy fields we need\n // (all properly formatted as multi-locale objects)\n return {\n id: validParentID,\n [parentHierarchyConfig.slugPathFieldName]: combinedSlugPaths,\n [parentHierarchyConfig.titlePathFieldName]: combinedTitlePaths,\n [parentTitleField]: combinedTitles,\n }\n }\n } else {\n // Normal case: single locale, can pass draft parameter\n return await req.payload.findByID({\n id: validParentID,\n collection: collection.slug,\n depth: 0,\n draft,\n locale,\n overrideAccess: true,\n req: parentReq,\n select: {\n [parentHierarchyConfig.parentFieldName]: true,\n [parentHierarchyConfig.slugPathFieldName]: true,\n [parentHierarchyConfig.titlePathFieldName]: true,\n [parentTitleField]: true,\n ...(slugFieldName ? { [slugFieldName]: true } : {}),\n },\n user: req.user,\n })\n }\n }\n\n try {\n parent = await fetchParent()\n\n // Store in cache\n cache[cacheKey] = parent\n } catch {\n // If we can't fetch the parent at all (even with fallbacks), treat this as a root document\n // This can happen with complex draft/locale combinations\n parentID = undefined\n }\n }\n\n // If parent fetch failed, treat as root document\n if (!parentID || !parent) {\n const titleValue = getTitleValue({\n document: doc,\n isTitleLocalized,\n locale,\n req,\n titleFieldName,\n })\n\n const slugValue = slugFieldName\n ? getSlugFieldValue({\n document: doc,\n isSlugLocalized: isSlugFieldLocalized,\n locale,\n req,\n slugFieldName,\n })\n : undefined\n\n if (isTitleLocalized && locale === 'all') {\n return buildLocalizedHierarchyPaths({\n req,\n slugify,\n slugValue: slugValue as Record<string, string> | undefined,\n titleValue: titleValue as Record<string, string>,\n })\n }\n\n return {\n slugPath: slugValue !== undefined ? (slugValue as string) : slugify(titleValue as string),\n titlePath: titleValue as string,\n }\n }\n\n const docTitle = getTitleValue({ document: doc, isTitleLocalized, locale, req, titleFieldName })\n\n // Cache the current document (in its own collection's cache)\n const currentDocCacheKey = `${doc.id}_${locale || 'default'}`\n if (!context.hierarchyAncestorCache[collection.slug]) {\n context.hierarchyAncestorCache[collection.slug] = {}\n }\n context.hierarchyAncestorCache[collection.slug][currentDocCacheKey] = {\n [parentFieldName]: parentID,\n [slugPathFieldName]: undefined, // Will be set below\n [titleFieldName]: docTitle,\n [titlePathFieldName]: undefined, // Will be set below\n }\n\n // Get parent's path field names from hierarchy config\n const parentSlugPathFieldName =\n parentCollectionConfig.hierarchy !== false\n ? parentCollectionConfig.hierarchy.slugPathFieldName\n : HIERARCHY_SLUG_PATH_FIELD\n const parentTitlePathFieldName =\n parentCollectionConfig.hierarchy !== false\n ? parentCollectionConfig.hierarchy.titlePathFieldName\n : HIERARCHY_TITLE_PATH_FIELD\n\n // Handle localized case (locale === 'all' with localized title field)\n if (isTitleLocalized && locale === 'all') {\n // Parent might have non-localized title field, resulting in string paths instead of objects\n // Convert parent paths to objects if they're strings (use same value for all locales)\n let parentSlugPathObj: Record<string, string> | undefined = parent[\n parentSlugPathFieldName\n ] as Record<string, string> | undefined\n let parentTitlePathObj: Record<string, string> | undefined = parent[\n parentTitlePathFieldName\n ] as Record<string, string> | undefined\n\n // If parent paths are strings (non-localized parent), convert to objects for all locales\n if (typeof parentSlugPathObj === 'string') {\n const locales = req.payload.config.localization\n ? req.payload.config.localization.localeCodes\n : []\n const slugValue = parentSlugPathObj\n parentSlugPathObj = {}\n for (const loc of locales) {\n parentSlugPathObj[loc] = slugValue\n }\n }\n\n if (typeof parentTitlePathObj === 'string') {\n const locales = req.payload.config.localization\n ? req.payload.config.localization.localeCodes\n : []\n const titleValue = parentTitlePathObj\n parentTitlePathObj = {}\n for (const loc of locales) {\n parentTitlePathObj[loc] = titleValue\n }\n }\n\n // Get slug value if slugField is configured\n const docSlugValue = slugFieldName\n ? getSlugFieldValue({\n document: doc,\n isSlugLocalized: isSlugFieldLocalized,\n locale,\n req,\n slugFieldName,\n })\n : undefined\n\n // If parent paths are undefined (parent fetch failed or paths not computed),\n // buildLocalizedHierarchyPaths will handle it by using just the child's title\n const result = buildLocalizedHierarchyPaths({\n parentSlugPath: parentSlugPathObj,\n parentTitlePath: parentTitlePathObj,\n req,\n slugify,\n slugValue: docSlugValue as Record<string, string> | undefined,\n titleValue: docTitle as Record<string, string>,\n })\n\n // Update cache with computed paths\n context.hierarchyAncestorCache[collection.slug][currentDocCacheKey][slugPathFieldName] =\n result.slugPath\n context.hierarchyAncestorCache[collection.slug][currentDocCacheKey][titlePathFieldName] =\n result.titlePath\n\n return result\n }\n\n // Single locale case - get slug value if slugField is configured\n const singleLocaleSlugValue = slugFieldName\n ? getSlugFieldValue({\n document: doc,\n isSlugLocalized: isSlugFieldLocalized,\n locale,\n req,\n slugFieldName,\n })\n : undefined\n\n const slugSegment =\n singleLocaleSlugValue !== undefined\n ? (singleLocaleSlugValue as string)\n : slugify(docTitle as string)\n\n const result = {\n slugPath: (parent[parentSlugPathFieldName] as string) + '/' + slugSegment,\n titlePath: (parent[parentTitlePathFieldName] as string) + '/' + (docTitle as string),\n }\n\n // Update cache with computed paths\n context.hierarchyAncestorCache[collection.slug][currentDocCacheKey][slugPathFieldName] =\n result.slugPath\n context.hierarchyAncestorCache[collection.slug][currentDocCacheKey][titlePathFieldName] =\n result.titlePath\n\n return result\n } else {\n // Root document (no parent)\n const titleValue = getTitleValue({\n document: doc,\n isTitleLocalized,\n locale,\n req,\n titleFieldName,\n })\n context.hierarchyAncestorCache[collection.slug][doc.id] = {\n [parentFieldName]: null,\n [titleFieldName]: titleValue,\n }\n\n const rootSlugValue = slugFieldName\n ? getSlugFieldValue({\n document: doc,\n isSlugLocalized: isSlugFieldLocalized,\n locale,\n req,\n slugFieldName,\n })\n : undefined\n\n // Handle localized case (locale === 'all' with localized title field)\n if (isTitleLocalized && locale === 'all') {\n return buildLocalizedHierarchyPaths({\n req,\n slugify,\n slugValue: rootSlugValue as Record<string, string> | undefined,\n titleValue: titleValue as Record<string, string>,\n })\n }\n\n // Single locale case\n return {\n slugPath:\n rootSlugValue !== undefined ? (rootSlugValue as string) : slugify(titleValue as string),\n titlePath: titleValue as string,\n }\n }\n}\n"],"names":["slugify","payloadSlugify","HIERARCHY_SLUG_PATH_FIELD","HIERARCHY_TITLE_PATH_FIELD","buildLocalizedHierarchyPaths","findFieldByName","findUseAsTitleField","getLocalizedValue","getTitleValue","document","isTitleLocalized","locale","req","titleFieldName","titleValue","id","toString","localizedValue","fallbackLocale","fieldType","value","getSlugFieldValue","isSlugLocalized","slugFieldName","slugValue","undefined","computePaths","args","collection","doc","draft","parentFieldName","slugPathFieldName","titlePathFieldName","hierarchy","text","localized","slugField","slugFieldInfo","isSlugFieldLocalized","context","hierarchyAncestorCache","slug","payload","config","debug","hierarchyCacheStats","hits","misses","queries","parentValue","parentID","parentCollectionConfig","parentHierarchyConfig","slugPath","titlePath","cache","cacheKey","parent","parentTitleField","validParentID","parentReq","computeHierarchyPaths","fetchParent","findByID","depth","overrideAccess","select","user","_error","locales","localization","localeCodes","parentPathsByLocale","parentSlugify","loc","localeReq","parentForLocale","parentSlugPath","parentTitlePath","parentTitle","title","_localeError","combinedSlugPaths","combinedTitlePaths","combinedTitles","docTitle","currentDocCacheKey","parentSlugPathFieldName","parentTitlePathFieldName","parentSlugPathObj","parentTitlePathObj","docSlugValue","result","singleLocaleSlugValue","slugSegment","rootSlugValue"],"mappings":"AAGA,SAASA,WAAWC,cAAc,QAAQ,6BAA4B;AACtE,SAASC,yBAAyB,EAAEC,0BAA0B,QAAQ,kBAAiB;AACvF,SAASC,4BAA4B,QAAQ,oCAAmC;AAChF,SAASC,eAAe,EAAEC,mBAAmB,QAAQ,sBAAqB;AAC1E,SAASC,iBAAiB,QAAQ,yBAAwB;AAkB1D,yFAAyF;AACzF,MAAMC,gBAAgB,CAAC,EACrBC,QAAQ,EACRC,mBAAmB,KAAK,EACxBC,MAAM,EACNC,GAAG,EACHC,cAAc,EAOf;IACC,MAAMC,aAAaL,QAAQ,CAACI,eAAe;IAE3C,IAAI,CAACC,YAAY;QACf,OAAOL,SAASM,EAAE,EAAEC,cAAc;IACpC;IAEA,wEAAwE;IACxE,I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B,MAAM/E,aAAaN,cAAc;YAC/BC,UAAUoB;YACVnB;YACAC;YACAC;YACAC;QACF;QACA2B,QAAQC,sBAAsB,CAACb,WAAWc,IAAI,CAAC,CAACb,IAAId,EAAE,CAAC,GAAG;YACxD,CAACgB,gBAAgB,EAAE;YACnB,CAAClB,eAAe,EAAEC;QACpB;QAEA,MAAMkF,gBAAgBzE,gBAClBF,kBAAkB;YAChBZ,UAAUoB;YACVP,iBAAiBiB;YACjB5B;YACAC;YACAW;QACF,KACAE;QAEJ,sEAAsE;QACtE,IAAIf,oBAAoBC,WAAW,OAAO;YACxC,OAAOP,6BAA6B;gBAClCQ;gBACAZ;gBACAwB,WAAWwE;gBACXlF,YAAYA;YACd;QACF;QAEA,qBAAqB;QACrB,OAAO;YACLwC,UACE0C,kBAAkBvE,YAAauE,gBAA2BhG,QAAQc;YACpEyC,WAAWzC;QACb;IACF;AACF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { CollectionConfig } from '../../collections/config/types.js';
|
|
2
|
+
export declare function findUseAsTitleField(collectionConfig: CollectionConfig): {
|
|
3
|
+
localized: boolean;
|
|
4
|
+
titleFieldName: string;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Find a field by name and return its localization status.
|
|
8
|
+
* Returns undefined if field is not found.
|
|
9
|
+
*/
|
|
10
|
+
export declare function findFieldByName(collectionConfig: CollectionConfig, fieldName: string): {
|
|
11
|
+
fieldName: string;
|
|
12
|
+
localized: boolean;
|
|
13
|
+
} | undefined;
|
|
14
|
+
//# sourceMappingURL=findUseAsTitle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"findUseAsTitle.d.ts","sourceRoot":"","sources":["../../../src/hierarchy/utils/findUseAsTitle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAA;AAGzE,wBAAgB,mBAAmB,CAAC,gBAAgB,EAAE,gBAAgB,GAAG;IACvE,SAAS,EAAE,OAAO,CAAA;IAClB,cAAc,EAAE,MAAM,CAAA;CACvB,CAGA;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,gBAAgB,EAAE,gBAAgB,EAClC,SAAS,EAAE,MAAM,GAChB;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,OAAO,CAAA;CAAE,GAAG,SAAS,CAOvD"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
export function findUseAsTitleField(collectionConfig) {
|
|
2
|
+
const titleFieldName = collectionConfig.admin?.useAsTitle || 'id';
|
|
3
|
+
return iterateFields({
|
|
4
|
+
fields: collectionConfig.fields,
|
|
5
|
+
titleFieldName
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Find a field by name and return its localization status.
|
|
10
|
+
* Returns undefined if field is not found.
|
|
11
|
+
*/ export function findFieldByName(collectionConfig, fieldName) {
|
|
12
|
+
try {
|
|
13
|
+
const result = iterateFields({
|
|
14
|
+
fields: collectionConfig.fields,
|
|
15
|
+
titleFieldName: fieldName
|
|
16
|
+
});
|
|
17
|
+
return {
|
|
18
|
+
fieldName: result.titleFieldName,
|
|
19
|
+
localized: result.localized
|
|
20
|
+
};
|
|
21
|
+
} catch {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function iterateFields({ fields, titleFieldName }) {
|
|
26
|
+
let titleField;
|
|
27
|
+
if (titleFieldName === 'id') {
|
|
28
|
+
return {
|
|
29
|
+
localized: false,
|
|
30
|
+
titleFieldName
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
for (const field of fields){
|
|
34
|
+
switch(field.type){
|
|
35
|
+
case 'text':
|
|
36
|
+
case 'number':
|
|
37
|
+
case 'textarea':
|
|
38
|
+
if (field.name === titleFieldName) {
|
|
39
|
+
return {
|
|
40
|
+
localized: Boolean(field.localized),
|
|
41
|
+
titleFieldName: field.name
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
break;
|
|
45
|
+
case 'row':
|
|
46
|
+
case 'collapsible':
|
|
47
|
+
{
|
|
48
|
+
const result = iterateFields({
|
|
49
|
+
fields: field.fields,
|
|
50
|
+
titleFieldName
|
|
51
|
+
});
|
|
52
|
+
if (result) {
|
|
53
|
+
titleField = result;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
break;
|
|
57
|
+
case 'group':
|
|
58
|
+
if (!('name' in field)) {
|
|
59
|
+
const result = iterateFields({
|
|
60
|
+
fields: field.fields,
|
|
61
|
+
titleFieldName
|
|
62
|
+
});
|
|
63
|
+
if (result) {
|
|
64
|
+
titleField = result;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
break;
|
|
68
|
+
case 'tabs':
|
|
69
|
+
for (const tab of field.tabs){
|
|
70
|
+
if (!('name' in tab)) {
|
|
71
|
+
const result = iterateFields({
|
|
72
|
+
fields: tab.fields,
|
|
73
|
+
titleFieldName
|
|
74
|
+
});
|
|
75
|
+
if (result) {
|
|
76
|
+
titleField = result;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
// If we found the field in recursion, return it
|
|
82
|
+
if (titleField) {
|
|
83
|
+
return titleField;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
throw new Error(`The hierarchy title field "${titleFieldName}" was not found. It cannot be nested within named fields i.e. named groups, named tabs, etc.`);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
//# sourceMappingURL=findUseAsTitle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/hierarchy/utils/findUseAsTitle.ts"],"sourcesContent":["import type { CollectionConfig } from '../../collections/config/types.js'\nimport type { Field } from '../../fields/config/types.js'\n\nexport function findUseAsTitleField(collectionConfig: CollectionConfig): {\n localized: boolean\n titleFieldName: string\n} {\n const titleFieldName = collectionConfig.admin?.useAsTitle || 'id'\n return iterateFields({ fields: collectionConfig.fields, titleFieldName })\n}\n\n/**\n * Find a field by name and return its localization status.\n * Returns undefined if field is not found.\n */\nexport function findFieldByName(\n collectionConfig: CollectionConfig,\n fieldName: string,\n): { fieldName: string; localized: boolean } | undefined {\n try {\n const result = iterateFields({ fields: collectionConfig.fields, titleFieldName: fieldName })\n return { fieldName: result.titleFieldName, localized: result.localized }\n } catch {\n return undefined\n }\n}\n\nfunction iterateFields({ fields, titleFieldName }: { fields: Field[]; titleFieldName: string }): {\n localized: boolean\n titleFieldName: string\n} {\n let titleField: { localized: boolean; titleFieldName: string } | undefined\n\n if (titleFieldName === 'id') {\n return {\n localized: false,\n titleFieldName,\n }\n }\n\n for (const field of fields) {\n switch (field.type) {\n case 'text':\n case 'number':\n case 'textarea':\n if (field.name === titleFieldName) {\n return {\n localized: Boolean(field.localized),\n titleFieldName: field.name,\n }\n }\n break\n case 'row':\n case 'collapsible':\n {\n const result = iterateFields({ fields: field.fields, titleFieldName })\n if (result) {\n titleField = result\n }\n }\n break\n case 'group':\n if (!('name' in field)) {\n const result = iterateFields({ fields: field.fields, titleFieldName })\n if (result) {\n titleField = result\n }\n }\n break\n case 'tabs':\n for (const tab of field.tabs) {\n if (!('name' in tab)) {\n const result = iterateFields({ fields: tab.fields, titleFieldName })\n if (result) {\n titleField = result\n }\n }\n }\n }\n\n // If we found the field in recursion, return it\n if (titleField) {\n return titleField\n }\n }\n\n throw new Error(\n `The hierarchy title field \"${titleFieldName}\" was not found. It cannot be nested within named fields i.e. named groups, named tabs, etc.`,\n )\n}\n"],"names":["findUseAsTitleField","collectionConfig","titleFieldName","admin","useAsTitle","iterateFields","fields","findFieldByName","fieldName","result","localized","undefined","titleField","field","type","name","Boolean","tab","tabs","Error"],"mappings":"AAGA,OAAO,SAASA,oBAAoBC,gBAAkC;IAIpE,MAAMC,iBAAiBD,iBAAiBE,KAAK,EAAEC,cAAc;IAC7D,OAAOC,cAAc;QAAEC,QAAQL,iBAAiBK,MAAM;QAAEJ;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