@strapi/content-manager 5.48.1 → 5.50.0
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/dist/admin/components/ActionsDrawer.js +3 -2
- package/dist/admin/components/ActionsDrawer.js.map +1 -1
- package/dist/admin/components/ComponentIcon.js +4 -3
- package/dist/admin/components/ComponentIcon.js.map +1 -1
- package/dist/admin/components/ConfigurationForm/EditFieldForm.js +3 -2
- package/dist/admin/components/ConfigurationForm/EditFieldForm.js.map +1 -1
- package/dist/admin/components/ConfigurationForm/Fields.js +3 -2
- package/dist/admin/components/ConfigurationForm/Fields.js.map +1 -1
- package/dist/admin/components/ConfigurationForm/Form.js +7 -3
- package/dist/admin/components/ConfigurationForm/Form.js.map +1 -1
- package/dist/admin/components/LeftMenu.js +3 -2
- package/dist/admin/components/LeftMenu.js.map +1 -1
- package/dist/admin/components/RelativeTime.js +3 -2
- package/dist/admin/components/RelativeTime.js.map +1 -1
- package/dist/admin/components/Widgets.js +3 -2
- package/dist/admin/components/Widgets.js.map +1 -1
- package/dist/admin/features/DocumentRBAC.js +3 -2
- package/dist/admin/features/DocumentRBAC.js.map +1 -1
- package/dist/admin/history/components/VersionContent.js +7 -3
- package/dist/admin/history/components/VersionContent.js.map +1 -1
- package/dist/admin/history/components/VersionHeader.js +3 -2
- package/dist/admin/history/components/VersionHeader.js.map +1 -1
- package/dist/admin/history/components/VersionInputRenderer.js +3 -2
- package/dist/admin/history/components/VersionInputRenderer.js.map +1 -1
- package/dist/admin/history/pages/History.js +3 -2
- package/dist/admin/history/pages/History.js.map +1 -1
- package/dist/admin/history/routes.js +3 -2
- package/dist/admin/history/routes.js.map +1 -1
- package/dist/admin/hooks/useContentTypeSchema.js +3 -2
- package/dist/admin/hooks/useContentTypeSchema.js.map +1 -1
- package/dist/admin/hooks/useDocument.js +3 -2
- package/dist/admin/hooks/useDocument.js.map +1 -1
- package/dist/admin/hooks/useDocumentActions.js +3 -2
- package/dist/admin/hooks/useDocumentActions.js.map +1 -1
- package/dist/admin/hooks/useDocumentContext.js +3 -2
- package/dist/admin/hooks/useDocumentContext.js.map +1 -1
- package/dist/admin/hooks/useDocumentLayout.js +3 -2
- package/dist/admin/hooks/useDocumentLayout.js.map +1 -1
- package/dist/admin/hooks/useDragAndDrop.js +3 -2
- package/dist/admin/hooks/useDragAndDrop.js.map +1 -1
- package/dist/admin/hooks/useKeyboardDragAndDrop.js +3 -2
- package/dist/admin/hooks/useKeyboardDragAndDrop.js.map +1 -1
- package/dist/admin/hooks/useOnce.js +3 -2
- package/dist/admin/hooks/useOnce.js.map +1 -1
- package/dist/admin/hooks/usePersistentQueryParams.js +7 -2
- package/dist/admin/hooks/usePersistentQueryParams.js.map +1 -1
- package/dist/admin/layout.js +3 -1
- package/dist/admin/layout.js.map +1 -1
- package/dist/admin/layout.mjs +5 -3
- package/dist/admin/layout.mjs.map +1 -1
- package/dist/admin/pages/ComponentConfigurationPage.js +3 -2
- package/dist/admin/pages/ComponentConfigurationPage.js.map +1 -1
- package/dist/admin/pages/EditConfigurationPage.js +3 -2
- package/dist/admin/pages/EditConfigurationPage.js.map +1 -1
- package/dist/admin/pages/EditView/EditViewPage.js +3 -2
- package/dist/admin/pages/EditView/EditViewPage.js.map +1 -1
- package/dist/admin/pages/EditView/components/DocumentActions.js +238 -108
- package/dist/admin/pages/EditView/components/DocumentActions.js.map +1 -1
- package/dist/admin/pages/EditView/components/DocumentActions.mjs +225 -103
- package/dist/admin/pages/EditView/components/DocumentActions.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/EditorToolbarObserver.js +3 -2
- package/dist/admin/pages/EditView/components/EditorToolbarObserver.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/Blocks/Code.js +4 -3
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/Blocks/Code.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/Blocks/Image.js +3 -2
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/Blocks/Image.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/Blocks/Link.js +3 -2
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/Blocks/Link.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksContent.js +3 -2
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksContent.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksEditor.js +3 -2
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksEditor.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksInput.js +3 -2
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksInput.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksToolbar.js +4 -3
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksToolbar.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Component/Input.js +3 -2
- package/dist/admin/pages/EditView/components/FormInputs/Component/Input.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Component/NonRepeatable.js +3 -2
- package/dist/admin/pages/EditView/components/FormInputs/Component/NonRepeatable.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Component/Repeatable.js +3 -2
- package/dist/admin/pages/EditView/components/FormInputs/Component/Repeatable.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/ComponentCategory.js +6 -1
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/ComponentCategory.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/ComponentCategory.mjs +2 -1
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/ComponentCategory.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/DynamicComponent.js +9 -4
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/DynamicComponent.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/DynamicComponent.mjs +3 -2
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/DynamicComponent.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/Field.js +13 -4
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/Field.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/Field.mjs +6 -1
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/Field.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Relations/RelationModal.js +3 -2
- package/dist/admin/pages/EditView/components/FormInputs/Relations/RelationModal.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Relations/Relations.js +7 -3
- package/dist/admin/pages/EditView/components/FormInputs/Relations/Relations.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/UID.js +3 -2
- package/dist/admin/pages/EditView/components/FormInputs/UID.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Wysiwyg/Editor.js +8 -4
- package/dist/admin/pages/EditView/components/FormInputs/Wysiwyg/Editor.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Wysiwyg/Field.js +3 -2
- package/dist/admin/pages/EditView/components/FormInputs/Wysiwyg/Field.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Wysiwyg/PreviewWysiwyg.js +3 -2
- package/dist/admin/pages/EditView/components/FormInputs/Wysiwyg/PreviewWysiwyg.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Wysiwyg/utils/continueList.js +5 -1
- package/dist/admin/pages/EditView/components/FormInputs/Wysiwyg/utils/continueList.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Wysiwyg/utils/mdRenderer.js +15 -2
- package/dist/admin/pages/EditView/components/FormInputs/Wysiwyg/utils/mdRenderer.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Wysiwyg/utils/sanitizer.js +5 -1
- package/dist/admin/pages/EditView/components/FormInputs/Wysiwyg/utils/sanitizer.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormLayout.js +3 -2
- package/dist/admin/pages/EditView/components/FormLayout.js.map +1 -1
- package/dist/admin/pages/EditView/components/Header.js +3 -2
- package/dist/admin/pages/EditView/components/Header.js.map +1 -1
- package/dist/admin/pages/EditView/components/InputRenderer.js +3 -2
- package/dist/admin/pages/EditView/components/InputRenderer.js.map +1 -1
- package/dist/admin/pages/EditView/components/Panels.js +3 -2
- package/dist/admin/pages/EditView/components/Panels.js.map +1 -1
- package/dist/admin/pages/EditView/utils/data.js +5 -1
- package/dist/admin/pages/EditView/utils/data.js.map +1 -1
- package/dist/admin/pages/EditView/utils/draftRelationCounts.js +117 -0
- package/dist/admin/pages/EditView/utils/draftRelationCounts.js.map +1 -0
- package/dist/admin/pages/EditView/utils/draftRelationCounts.mjs +109 -0
- package/dist/admin/pages/EditView/utils/draftRelationCounts.mjs.map +1 -0
- package/dist/admin/pages/EditView/utils/keyboardShortcuts.js +35 -0
- package/dist/admin/pages/EditView/utils/keyboardShortcuts.js.map +1 -0
- package/dist/admin/pages/EditView/utils/keyboardShortcuts.mjs +33 -0
- package/dist/admin/pages/EditView/utils/keyboardShortcuts.mjs.map +1 -0
- package/dist/admin/pages/ListConfiguration/ListConfigurationPage.js +3 -2
- package/dist/admin/pages/ListConfiguration/ListConfigurationPage.js.map +1 -1
- package/dist/admin/pages/ListConfiguration/components/DraggableCard.js +3 -2
- package/dist/admin/pages/ListConfiguration/components/DraggableCard.js.map +1 -1
- package/dist/admin/pages/ListConfiguration/components/EditFieldForm.js +3 -2
- package/dist/admin/pages/ListConfiguration/components/EditFieldForm.js.map +1 -1
- package/dist/admin/pages/ListConfiguration/components/Settings.js +3 -2
- package/dist/admin/pages/ListConfiguration/components/Settings.js.map +1 -1
- package/dist/admin/pages/ListConfiguration/components/SortDisplayedFields.js +3 -2
- package/dist/admin/pages/ListConfiguration/components/SortDisplayedFields.js.map +1 -1
- package/dist/admin/pages/ListView/ListViewPage.js +3 -2
- package/dist/admin/pages/ListView/ListViewPage.js.map +1 -1
- package/dist/admin/pages/ListView/components/BulkActions/Actions.js +3 -2
- package/dist/admin/pages/ListView/components/BulkActions/Actions.js.map +1 -1
- package/dist/admin/pages/ListView/components/BulkActions/ConfirmBulkActionDialog.js +4 -3
- package/dist/admin/pages/ListView/components/BulkActions/ConfirmBulkActionDialog.js.map +1 -1
- package/dist/admin/pages/ListView/components/BulkActions/ConfirmBulkActionDialog.mjs +1 -1
- package/dist/admin/pages/ListView/components/BulkActions/ConfirmBulkActionDialog.mjs.map +1 -1
- package/dist/admin/pages/ListView/components/BulkActions/PublishAction.js +3 -2
- package/dist/admin/pages/ListView/components/BulkActions/PublishAction.js.map +1 -1
- package/dist/admin/pages/ListView/components/BulkActions/PublishAction.mjs.map +1 -1
- package/dist/admin/pages/ListView/components/Filters.js +3 -2
- package/dist/admin/pages/ListView/components/Filters.js.map +1 -1
- package/dist/admin/pages/ListView/components/TableActions.js +3 -2
- package/dist/admin/pages/ListView/components/TableActions.js.map +1 -1
- package/dist/admin/pages/ListView/components/TableCells/CellContent.js +9 -5
- package/dist/admin/pages/ListView/components/TableCells/CellContent.js.map +1 -1
- package/dist/admin/pages/ListView/components/TableCells/CellContent.mjs +2 -2
- package/dist/admin/pages/ListView/components/TableCells/CellContent.mjs.map +1 -1
- package/dist/admin/pages/ListView/components/TableCells/CellValue.js +7 -2
- package/dist/admin/pages/ListView/components/TableCells/CellValue.js.map +1 -1
- package/dist/admin/pages/ListView/components/TableCells/Relations.js +4 -3
- package/dist/admin/pages/ListView/components/TableCells/Relations.js.map +1 -1
- package/dist/admin/pages/ListView/components/TableCells/Relations.mjs +1 -1
- package/dist/admin/pages/ListView/components/TableCells/Relations.mjs.map +1 -1
- package/dist/admin/preview/components/InputPopover.js +3 -2
- package/dist/admin/preview/components/InputPopover.js.map +1 -1
- package/dist/admin/preview/hooks/usePreviewInputManager.js +3 -2
- package/dist/admin/preview/hooks/usePreviewInputManager.js.map +1 -1
- package/dist/admin/preview/pages/Preview.js +41 -13
- package/dist/admin/preview/pages/Preview.js.map +1 -1
- package/dist/admin/preview/pages/Preview.mjs +39 -12
- package/dist/admin/preview/pages/Preview.mjs.map +1 -1
- package/dist/admin/preview/routes.js +3 -2
- package/dist/admin/preview/routes.js.map +1 -1
- package/dist/admin/preview/utils/constants.js +9 -15
- package/dist/admin/preview/utils/constants.js.map +1 -1
- package/dist/admin/preview/utils/constants.mjs +10 -15
- package/dist/admin/preview/utils/constants.mjs.map +1 -1
- package/dist/admin/src/components/InjectionZone.d.ts +1 -2
- package/dist/admin/src/content-manager.d.ts +15 -15
- package/dist/admin/src/history/services/historyVersion.d.ts +2 -2
- package/dist/admin/src/hooks/useContentTypeSchema.d.ts +1 -1
- package/dist/admin/src/hooks/useDocument.d.ts +8 -9
- package/dist/admin/src/hooks/useDocumentLayout.d.ts +3 -3
- package/dist/admin/src/hooks/useDragAndDrop.d.ts +4 -4
- package/dist/admin/src/hooks/useKeyboardDragAndDrop.d.ts +1 -1
- package/dist/admin/src/hooks/usePersistentQueryParams.d.ts +0 -1
- package/dist/admin/src/modules/app.d.ts +5 -5
- package/dist/admin/src/pages/EditView/EditViewPage.d.ts +1 -1
- package/dist/admin/src/pages/EditView/components/DocumentActions.d.ts +12 -1
- package/dist/admin/src/pages/EditView/components/EditorToolbarObserver.d.ts +1 -1
- package/dist/admin/src/pages/EditView/components/FormInputs/BlocksInput/BlocksEditor.d.ts +1 -1
- package/dist/admin/src/pages/EditView/components/FormInputs/BlocksInput/utils/conversions.d.ts +2 -2
- package/dist/admin/src/pages/EditView/components/FormInputs/ComponentContext.d.ts +1 -2
- package/dist/admin/src/pages/EditView/components/FormInputs/Relations/Relations.d.ts +4 -4
- package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/EditorLayout.d.ts +2 -2
- package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygStyles.d.ts +19 -20
- package/dist/admin/src/pages/EditView/components/FormLayout.d.ts +12 -12
- package/dist/admin/src/pages/EditView/utils/draftRelationCounts.d.ts +26 -0
- package/dist/admin/src/pages/EditView/utils/keyboardShortcuts.d.ts +18 -0
- package/dist/admin/src/pages/ListView/components/BulkActions/PublishAction.d.ts +1 -1
- package/dist/admin/src/pages/ListView/components/Filters.d.ts +1 -1
- package/dist/admin/src/pages/formatComponentConfigurationEditLayout.d.ts +1 -1
- package/dist/admin/src/preview/utils/constants.d.ts +1 -7
- package/dist/admin/src/preview/utils/getSendMessage.d.ts +0 -1
- package/dist/admin/src/services/documents.d.ts +30 -70
- package/dist/admin/src/services/relations.d.ts +6 -20
- package/dist/admin/src/services/uid.d.ts +5 -5
- package/dist/admin/src/utils/layouts/normalizeContentManagerLayout.d.ts +4 -4
- package/dist/admin/src/utils/users.d.ts +1 -1
- package/dist/admin/src/utils/validation.d.ts +1 -1
- package/dist/admin/translations/cs.json.js +2 -1
- package/dist/admin/translations/cs.json.js.map +1 -1
- package/dist/admin/translations/cs.json.mjs +2 -1
- package/dist/admin/translations/cs.json.mjs.map +1 -1
- package/dist/admin/translations/de.json.js +2 -1
- package/dist/admin/translations/de.json.js.map +1 -1
- package/dist/admin/translations/de.json.mjs +2 -1
- package/dist/admin/translations/de.json.mjs.map +1 -1
- package/dist/admin/translations/en.json.js +7 -3
- package/dist/admin/translations/en.json.js.map +1 -1
- package/dist/admin/translations/en.json.mjs +7 -3
- package/dist/admin/translations/en.json.mjs.map +1 -1
- package/dist/admin/translations/es.json.js +2 -1
- package/dist/admin/translations/es.json.js.map +1 -1
- package/dist/admin/translations/es.json.mjs +2 -1
- package/dist/admin/translations/es.json.mjs.map +1 -1
- package/dist/admin/translations/fr.json.js +2 -1
- package/dist/admin/translations/fr.json.js.map +1 -1
- package/dist/admin/translations/fr.json.mjs +2 -1
- package/dist/admin/translations/fr.json.mjs.map +1 -1
- package/dist/admin/translations/ja.json.js +262 -87
- package/dist/admin/translations/ja.json.js.map +1 -1
- package/dist/admin/translations/ja.json.mjs +262 -87
- package/dist/admin/translations/ja.json.mjs.map +1 -1
- package/dist/admin/translations/nl.json.js +2 -1
- package/dist/admin/translations/nl.json.js.map +1 -1
- package/dist/admin/translations/nl.json.mjs +2 -1
- package/dist/admin/translations/nl.json.mjs.map +1 -1
- package/dist/admin/translations/pl.json.js +2 -1
- package/dist/admin/translations/pl.json.js.map +1 -1
- package/dist/admin/translations/pl.json.mjs +2 -1
- package/dist/admin/translations/pl.json.mjs.map +1 -1
- package/dist/admin/translations/sk.json.js +2 -1
- package/dist/admin/translations/sk.json.js.map +1 -1
- package/dist/admin/translations/sk.json.mjs +2 -1
- package/dist/admin/translations/sk.json.mjs.map +1 -1
- package/dist/admin/utils/objects.js +9 -4
- package/dist/admin/utils/objects.js.map +1 -1
- package/dist/admin/utils/validation.js +7 -3
- package/dist/admin/utils/validation.js.map +1 -1
- package/dist/server/controllers/collection-types.js +2 -2
- package/dist/server/controllers/collection-types.js.map +1 -1
- package/dist/server/controllers/collection-types.mjs +2 -2
- package/dist/server/controllers/collection-types.mjs.map +1 -1
- package/dist/server/controllers/single-types.js +2 -2
- package/dist/server/controllers/single-types.js.map +1 -1
- package/dist/server/controllers/single-types.mjs +2 -2
- package/dist/server/controllers/single-types.mjs.map +1 -1
- package/dist/server/controllers/utils/clone.js +5 -1
- package/dist/server/controllers/utils/clone.js.map +1 -1
- package/dist/server/controllers/utils/clone.mjs.map +1 -1
- package/dist/server/controllers/validation/index.js +6 -2
- package/dist/server/controllers/validation/index.js.map +1 -1
- package/dist/server/homepage/services/homepage.js +6 -1
- package/dist/server/homepage/services/homepage.js.map +1 -1
- package/dist/server/homepage/services/homepage.mjs +6 -1
- package/dist/server/homepage/services/homepage.mjs.map +1 -1
- package/dist/server/mcp/handlers/collection-handlers.js +15 -18
- package/dist/server/mcp/handlers/collection-handlers.js.map +1 -1
- package/dist/server/mcp/handlers/collection-handlers.mjs +16 -19
- package/dist/server/mcp/handlers/collection-handlers.mjs.map +1 -1
- package/dist/server/mcp/handlers/single-type-handlers.js +12 -12
- package/dist/server/mcp/handlers/single-type-handlers.js.map +1 -1
- package/dist/server/mcp/handlers/single-type-handlers.mjs +13 -13
- package/dist/server/mcp/handlers/single-type-handlers.mjs.map +1 -1
- package/dist/server/mcp/register-content-manager-mcp-tools.js +4 -1
- package/dist/server/mcp/register-content-manager-mcp-tools.js.map +1 -1
- package/dist/server/mcp/register-content-manager-mcp-tools.mjs +4 -1
- package/dist/server/mcp/register-content-manager-mcp-tools.mjs.map +1 -1
- package/dist/server/mcp/sanitizers/shape-relations.js +108 -0
- package/dist/server/mcp/sanitizers/shape-relations.js.map +1 -0
- package/dist/server/mcp/sanitizers/shape-relations.mjs +103 -0
- package/dist/server/mcp/sanitizers/shape-relations.mjs.map +1 -0
- package/dist/server/mcp/schemas/data-schema.js +0 -3
- package/dist/server/mcp/schemas/data-schema.js.map +1 -1
- package/dist/server/mcp/schemas/data-schema.mjs +0 -3
- package/dist/server/mcp/schemas/data-schema.mjs.map +1 -1
- package/dist/server/mcp/schemas/output-schemas.js +30 -4
- package/dist/server/mcp/schemas/output-schemas.js.map +1 -1
- package/dist/server/mcp/schemas/output-schemas.mjs +30 -4
- package/dist/server/mcp/schemas/output-schemas.mjs.map +1 -1
- package/dist/server/mcp/utils.js +30 -3
- package/dist/server/mcp/utils.js.map +1 -1
- package/dist/server/mcp/utils.mjs +30 -4
- package/dist/server/mcp/utils.mjs.map +1 -1
- package/dist/server/middlewares/routing.js +5 -1
- package/dist/server/middlewares/routing.js.map +1 -1
- package/dist/server/preview/controllers/preview.js +9 -0
- package/dist/server/preview/controllers/preview.js.map +1 -1
- package/dist/server/preview/controllers/preview.mjs +9 -0
- package/dist/server/preview/controllers/preview.mjs.map +1 -1
- package/dist/server/preview/controllers/previewScript.js +1450 -0
- package/dist/server/preview/routes/preview.js +11 -0
- package/dist/server/preview/routes/preview.js.map +1 -1
- package/dist/server/preview/routes/preview.mjs +11 -0
- package/dist/server/preview/routes/preview.mjs.map +1 -1
- package/dist/server/services/document-manager.js +13 -19
- package/dist/server/services/document-manager.js.map +1 -1
- package/dist/server/services/document-manager.mjs +13 -19
- package/dist/server/services/document-manager.mjs.map +1 -1
- package/dist/server/services/populate-builder.js.map +1 -1
- package/dist/server/services/populate-builder.mjs.map +1 -1
- package/dist/server/services/uid.js +9 -4
- package/dist/server/services/uid.js.map +1 -1
- package/dist/server/services/utils/configuration/attributes.js +14 -10
- package/dist/server/services/utils/configuration/attributes.js.map +1 -1
- package/dist/server/services/utils/configuration/layouts.js +8 -4
- package/dist/server/services/utils/configuration/layouts.js.map +1 -1
- package/dist/server/services/utils/configuration/metadatas.js +19 -15
- package/dist/server/services/utils/configuration/metadatas.js.map +1 -1
- package/dist/server/services/utils/configuration/settings.js +5 -1
- package/dist/server/services/utils/configuration/settings.js.map +1 -1
- package/dist/server/services/utils/draft-relations.js +9 -0
- package/dist/server/services/utils/draft-relations.js.map +1 -0
- package/dist/server/services/utils/draft-relations.mjs +7 -0
- package/dist/server/services/utils/draft-relations.mjs.map +1 -0
- package/dist/server/services/utils/draft.js +123 -26
- package/dist/server/services/utils/draft.js.map +1 -1
- package/dist/server/services/utils/draft.mjs +118 -25
- package/dist/server/services/utils/draft.mjs.map +1 -1
- package/dist/server/services/utils/populate.js +23 -5
- package/dist/server/services/utils/populate.js.map +1 -1
- package/dist/server/services/utils/populate.mjs +15 -1
- package/dist/server/services/utils/populate.mjs.map +1 -1
- package/dist/server/services/utils/store.js +9 -5
- package/dist/server/services/utils/store.js.map +1 -1
- package/dist/server/src/controllers/index.d.ts +1 -1
- package/dist/server/src/controllers/relations.d.ts.map +1 -1
- package/dist/server/src/controllers/utils/clone.d.ts +1 -1
- package/dist/server/src/controllers/utils/clone.d.ts.map +1 -1
- package/dist/server/src/controllers/utils/document-status.d.ts +1 -1
- package/dist/server/src/controllers/utils/document-status.d.ts.map +1 -1
- package/dist/server/src/controllers/utils/metadata.d.ts +5 -5
- package/dist/server/src/controllers/utils/metadata.d.ts.map +1 -1
- package/dist/server/src/controllers/validation/dimensions.d.ts.map +1 -1
- package/dist/server/src/controllers/validation/index.d.ts +3 -3
- package/dist/server/src/controllers/validation/index.d.ts.map +1 -1
- package/dist/server/src/controllers/validation/model-configuration.d.ts.map +1 -1
- package/dist/server/src/controllers/validation/relations.d.ts +2 -2
- package/dist/server/src/history/controllers/history-version.d.ts +1 -7
- package/dist/server/src/history/controllers/history-version.d.ts.map +1 -1
- package/dist/server/src/history/controllers/index.d.ts +2 -1
- package/dist/server/src/history/controllers/index.d.ts.map +1 -1
- package/dist/server/src/history/controllers/validation/history-version.d.ts +1 -1
- package/dist/server/src/history/services/history.d.ts +0 -2
- package/dist/server/src/history/services/history.d.ts.map +1 -1
- package/dist/server/src/history/services/lifecycles.d.ts.map +1 -1
- package/dist/server/src/history/services/utils.d.ts +3 -3
- package/dist/server/src/history/services/utils.d.ts.map +1 -1
- package/dist/server/src/history/utils.d.ts +1 -18
- package/dist/server/src/history/utils.d.ts.map +1 -1
- package/dist/server/src/homepage/controllers/homepage.d.ts +0 -1
- package/dist/server/src/homepage/controllers/homepage.d.ts.map +1 -1
- package/dist/server/src/homepage/controllers/index.d.ts +2 -1
- package/dist/server/src/homepage/controllers/index.d.ts.map +1 -1
- package/dist/server/src/homepage/index.d.ts +4 -8
- package/dist/server/src/homepage/index.d.ts.map +1 -1
- package/dist/server/src/homepage/services/homepage-query-utils.d.ts.map +1 -1
- package/dist/server/src/homepage/services/homepage.d.ts +3 -4
- package/dist/server/src/homepage/services/homepage.d.ts.map +1 -1
- package/dist/server/src/homepage/services/index.d.ts +4 -8
- package/dist/server/src/homepage/services/index.d.ts.map +1 -1
- package/dist/server/src/index.d.ts +82 -86
- package/dist/server/src/index.d.ts.map +1 -1
- package/dist/server/src/mcp/derive-content-type-mcp-tools.d.ts.map +1 -1
- package/dist/server/src/mcp/handlers/collection-handlers.d.ts.map +1 -1
- package/dist/server/src/mcp/handlers/single-type-handlers.d.ts.map +1 -1
- package/dist/server/src/mcp/permissions.d.ts +1 -1
- package/dist/server/src/mcp/permissions.d.ts.map +1 -1
- package/dist/server/src/mcp/register-content-manager-mcp-tools.d.ts +2 -1
- package/dist/server/src/mcp/register-content-manager-mcp-tools.d.ts.map +1 -1
- package/dist/server/src/mcp/sanitizers/shape-relations.d.ts +38 -0
- package/dist/server/src/mcp/sanitizers/shape-relations.d.ts.map +1 -0
- package/dist/server/src/mcp/schemas/blocks-schema.d.ts.map +1 -1
- package/dist/server/src/mcp/schemas/data-schema.d.ts +0 -3
- package/dist/server/src/mcp/schemas/data-schema.d.ts.map +1 -1
- package/dist/server/src/mcp/schemas/filters-schema.d.ts.map +1 -1
- package/dist/server/src/mcp/schemas/output-schemas.d.ts +2 -2
- package/dist/server/src/mcp/schemas/output-schemas.d.ts.map +1 -1
- package/dist/server/src/mcp/schemas/sort-schema.d.ts.map +1 -1
- package/dist/server/src/mcp/types.d.ts +2 -2
- package/dist/server/src/mcp/types.d.ts.map +1 -1
- package/dist/server/src/mcp/utils.d.ts +19 -1
- package/dist/server/src/mcp/utils.d.ts.map +1 -1
- package/dist/server/src/middlewares/routing.d.ts.map +1 -1
- package/dist/server/src/policies/hasPermissions.d.ts.map +1 -1
- package/dist/server/src/policies/index.d.ts.map +1 -1
- package/dist/server/src/preview/controllers/index.d.ts +2 -1
- package/dist/server/src/preview/controllers/index.d.ts.map +1 -1
- package/dist/server/src/preview/controllers/preview.d.ts +5 -0
- package/dist/server/src/preview/controllers/preview.d.ts.map +1 -1
- package/dist/server/src/preview/controllers/validation/preview.d.ts +1 -2
- package/dist/server/src/preview/controllers/validation/preview.d.ts.map +1 -1
- package/dist/server/src/preview/routes/preview.d.ts.map +1 -1
- package/dist/server/src/preview/services/index.d.ts +1 -1
- package/dist/server/src/preview/services/index.d.ts.map +1 -1
- package/dist/server/src/preview/services/preview-config.d.ts +1 -1
- package/dist/server/src/preview/services/preview-config.d.ts.map +1 -1
- package/dist/server/src/preview/services/preview.d.ts.map +1 -1
- package/dist/server/src/preview/utils.d.ts +1 -16
- package/dist/server/src/preview/utils.d.ts.map +1 -1
- package/dist/server/src/services/components.d.ts +2 -2
- package/dist/server/src/services/components.d.ts.map +1 -1
- package/dist/server/src/services/configuration.d.ts.map +1 -1
- package/dist/server/src/services/content-types.d.ts.map +1 -1
- package/dist/server/src/services/data-mapper.d.ts +5 -5
- package/dist/server/src/services/data-mapper.d.ts.map +1 -1
- package/dist/server/src/services/document-manager.d.ts +14 -14
- package/dist/server/src/services/document-manager.d.ts.map +1 -1
- package/dist/server/src/services/document-metadata.d.ts +6 -6
- package/dist/server/src/services/document-metadata.d.ts.map +1 -1
- package/dist/server/src/services/field-sizes.d.ts +2 -2
- package/dist/server/src/services/field-sizes.d.ts.map +1 -1
- package/dist/server/src/services/index.d.ts +81 -85
- package/dist/server/src/services/index.d.ts.map +1 -1
- package/dist/server/src/services/metrics.d.ts.map +1 -1
- package/dist/server/src/services/permission-checker.d.ts +12 -31
- package/dist/server/src/services/permission-checker.d.ts.map +1 -1
- package/dist/server/src/services/permission.d.ts.map +1 -1
- package/dist/server/src/services/populate-builder.d.ts +7 -5
- package/dist/server/src/services/populate-builder.d.ts.map +1 -1
- package/dist/server/src/services/uid.d.ts.map +1 -1
- package/dist/server/src/services/utils/configuration/attributes.d.ts.map +1 -1
- package/dist/server/src/services/utils/configuration/settings.d.ts.map +1 -1
- package/dist/server/src/services/utils/count.d.ts.map +1 -1
- package/dist/server/src/services/utils/draft-relations.d.ts +19 -0
- package/dist/server/src/services/utils/draft-relations.d.ts.map +1 -0
- package/dist/server/src/services/utils/draft.d.ts +8 -7
- package/dist/server/src/services/utils/draft.d.ts.map +1 -1
- package/dist/server/src/services/utils/populate.d.ts +3 -1
- package/dist/server/src/services/utils/populate.d.ts.map +1 -1
- package/dist/server/src/services/utils/store.d.ts.map +1 -1
- package/dist/server/src/utils/index.d.ts.map +1 -1
- package/dist/server/src/validation/policies/hasPermissions.d.ts +1 -1
- package/dist/server/src/validation/zod.d.ts +1 -1
- package/dist/server/src/validation/zod.d.ts.map +1 -1
- package/dist/shared/contracts/collection-types.d.ts +4 -1
- package/dist/shared/contracts/collection-types.d.ts.map +1 -1
- package/dist/shared/contracts/single-types.d.ts +4 -1
- package/dist/shared/contracts/single-types.d.ts.map +1 -1
- package/package.json +10 -10
- package/dist/admin/preview/utils/previewScript.js +0 -1068
- package/dist/admin/preview/utils/previewScript.js.map +0 -1
- package/dist/admin/preview/utils/previewScript.mjs +0 -1066
- package/dist/admin/preview/utils/previewScript.mjs.map +0 -1
- package/dist/admin/src/preview/utils/previewScript.d.ts +0 -32
|
@@ -1,55 +1,148 @@
|
|
|
1
1
|
import { castArray } from 'lodash/fp';
|
|
2
2
|
import strapiUtils from '@strapi/utils';
|
|
3
|
+
import { isBidirectionalManyToMany } from './draft-relations.mjs';
|
|
3
4
|
|
|
4
5
|
const { isVisibleAttribute, hasDraftAndPublish } = strapiUtils.contentTypes;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
const isLocalizedContentType = (model)=>model.pluginOptions?.i18n?.localized === true;
|
|
7
|
+
const toPublishedDocumentKey = (documentId, locale)=>`${documentId}:${locale ?? ''}`;
|
|
8
|
+
const mergeCollectedLinks = (left, right)=>({
|
|
9
|
+
m2mLinks: [
|
|
10
|
+
...left.m2mLinks,
|
|
11
|
+
...right.m2mLinks
|
|
12
|
+
],
|
|
13
|
+
xToOneLinks: [
|
|
14
|
+
...left.xToOneLinks,
|
|
15
|
+
...right.xToOneLinks
|
|
16
|
+
]
|
|
17
|
+
});
|
|
18
|
+
const toDraftRelationLink = (entry, targetUid, targetIsLocalized, documentLocale)=>{
|
|
19
|
+
if (!entry?.documentId) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
targetUid,
|
|
24
|
+
documentId: entry.documentId,
|
|
25
|
+
locale: targetIsLocalized ? entry.locale ?? documentLocale : null
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
const collectDraftRelationLinks = (strapi, entity, uid, documentLocale)=>{
|
|
13
29
|
const model = strapi.getModel(uid);
|
|
14
|
-
|
|
30
|
+
const locale = entity.locale ?? documentLocale;
|
|
31
|
+
return Object.keys(model.attributes).reduce((collected, attributeName)=>{
|
|
15
32
|
const attribute = model.attributes[attributeName];
|
|
16
33
|
const value = entity[attributeName];
|
|
17
34
|
if (!value) {
|
|
18
|
-
return
|
|
35
|
+
return collected;
|
|
19
36
|
}
|
|
20
37
|
switch(attribute.type){
|
|
21
38
|
case 'relation':
|
|
22
39
|
{
|
|
23
40
|
if (!('target' in attribute)) {
|
|
24
|
-
return
|
|
41
|
+
return collected;
|
|
25
42
|
}
|
|
26
43
|
const targetModel = strapi.getModel(attribute.target);
|
|
27
44
|
if (!targetModel || !hasDraftAndPublish(targetModel)) {
|
|
28
|
-
return
|
|
45
|
+
return collected;
|
|
46
|
+
}
|
|
47
|
+
if (attribute.target === uid || !isVisibleAttribute(model, attributeName)) {
|
|
48
|
+
return collected;
|
|
29
49
|
}
|
|
30
|
-
|
|
31
|
-
|
|
50
|
+
const targetIsLocalized = isLocalizedContentType(targetModel);
|
|
51
|
+
const relatedEntries = castArray(value);
|
|
52
|
+
const links = relatedEntries.map((entry)=>toDraftRelationLink(entry, attribute.target, targetIsLocalized, locale)).filter((link)=>link !== null);
|
|
53
|
+
if (links.length === 0) {
|
|
54
|
+
return collected;
|
|
32
55
|
}
|
|
33
|
-
|
|
56
|
+
if (isBidirectionalManyToMany(attribute)) {
|
|
57
|
+
return {
|
|
58
|
+
...collected,
|
|
59
|
+
m2mLinks: [
|
|
60
|
+
...collected.m2mLinks,
|
|
61
|
+
...links
|
|
62
|
+
]
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
...collected,
|
|
67
|
+
xToOneLinks: [
|
|
68
|
+
...collected.xToOneLinks,
|
|
69
|
+
...links
|
|
70
|
+
]
|
|
71
|
+
};
|
|
34
72
|
}
|
|
35
73
|
case 'component':
|
|
36
74
|
{
|
|
37
|
-
|
|
38
|
-
return acc + sumDraftCounts(componentValue, attribute.component);
|
|
39
|
-
}, 0);
|
|
40
|
-
return sum + compoSum;
|
|
75
|
+
return castArray(value).reduce((componentCollected, componentValue)=>mergeCollectedLinks(componentCollected, collectDraftRelationLinks(strapi, componentValue, attribute.component, locale)), collected);
|
|
41
76
|
}
|
|
42
77
|
case 'dynamiczone':
|
|
43
78
|
{
|
|
44
|
-
|
|
45
|
-
return
|
|
46
|
-
},
|
|
47
|
-
return sum + dzSum;
|
|
79
|
+
return value.reduce((zoneCollected, componentValue)=>{
|
|
80
|
+
return mergeCollectedLinks(zoneCollected, collectDraftRelationLinks(strapi, componentValue, componentValue.__component, locale));
|
|
81
|
+
}, collected);
|
|
48
82
|
}
|
|
49
83
|
default:
|
|
50
|
-
return
|
|
84
|
+
return collected;
|
|
51
85
|
}
|
|
52
|
-
},
|
|
86
|
+
}, {
|
|
87
|
+
m2mLinks: [],
|
|
88
|
+
xToOneLinks: []
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
const countLinksToUnpublishedDocuments = async (strapi, links)=>{
|
|
92
|
+
if (links.length === 0) {
|
|
93
|
+
return 0;
|
|
94
|
+
}
|
|
95
|
+
const linksByTarget = links.reduce((acc, link)=>{
|
|
96
|
+
const targetLinks = acc.get(link.targetUid) ?? [];
|
|
97
|
+
targetLinks.push(link);
|
|
98
|
+
acc.set(link.targetUid, targetLinks);
|
|
99
|
+
return acc;
|
|
100
|
+
}, new Map());
|
|
101
|
+
const counts = await Promise.all(Array.from(linksByTarget.entries()).map(async ([targetUid, targetLinks])=>{
|
|
102
|
+
const targetModel = strapi.getModel(targetUid);
|
|
103
|
+
const targetIsLocalized = isLocalizedContentType(targetModel);
|
|
104
|
+
const documentIds = [
|
|
105
|
+
...new Set(targetLinks.map((link)=>link.documentId))
|
|
106
|
+
];
|
|
107
|
+
const publishedRows = await strapi.db.query(targetUid).findMany({
|
|
108
|
+
select: [
|
|
109
|
+
'documentId',
|
|
110
|
+
'locale'
|
|
111
|
+
],
|
|
112
|
+
where: {
|
|
113
|
+
documentId: {
|
|
114
|
+
$in: documentIds
|
|
115
|
+
},
|
|
116
|
+
publishedAt: {
|
|
117
|
+
$notNull: true
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
if (!targetIsLocalized) {
|
|
122
|
+
const publishedDocumentIds = new Set(publishedRows.map((row)=>row.documentId));
|
|
123
|
+
return targetLinks.filter((link)=>!publishedDocumentIds.has(link.documentId)).length;
|
|
124
|
+
}
|
|
125
|
+
const publishedDocumentKeys = new Set(publishedRows.map((row)=>toPublishedDocumentKey(row.documentId, row.locale)));
|
|
126
|
+
return targetLinks.filter((link)=>!publishedDocumentKeys.has(toPublishedDocumentKey(link.documentId, link.locale))).length;
|
|
127
|
+
}));
|
|
128
|
+
return counts.reduce((total, count)=>total + count, 0);
|
|
129
|
+
};
|
|
130
|
+
/**
|
|
131
|
+
* sumDraftCounts works recursively on the attributes of a model counting draft relations
|
|
132
|
+
* that matter for publish warnings.
|
|
133
|
+
*
|
|
134
|
+
* - unpublishedRelations: xToOne / oneToMany style links stripped from the published version
|
|
135
|
+
* - draftM2mLinks: bidirectional manyToMany links to documents without a published version
|
|
136
|
+
*/ const sumDraftCounts = async (strapi, entity, uid)=>{
|
|
137
|
+
const { m2mLinks, xToOneLinks } = collectDraftRelationLinks(strapi, entity, uid);
|
|
138
|
+
const [draftM2mLinks, unpublishedRelations] = await Promise.all([
|
|
139
|
+
countLinksToUnpublishedDocuments(strapi, m2mLinks),
|
|
140
|
+
countLinksToUnpublishedDocuments(strapi, xToOneLinks)
|
|
141
|
+
]);
|
|
142
|
+
return {
|
|
143
|
+
unpublishedRelations,
|
|
144
|
+
draftM2mLinks
|
|
145
|
+
};
|
|
53
146
|
};
|
|
54
147
|
|
|
55
148
|
export { sumDraftCounts };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"draft.mjs","sources":["../../../../server/src/services/utils/draft.ts"],"sourcesContent":["import { castArray } from 'lodash/fp';\nimport strapiUtils from '@strapi/utils';\n\nconst { isVisibleAttribute, hasDraftAndPublish } = strapiUtils.contentTypes;\n/**\n * sumDraftCounts works recursively on the attributes of a model counting the\n * number of draft relations\n * These relations can be direct to this content type or contained within components/dynamic zones\n * @param {Object} entity containing the draft relation counts\n * @param {String} uid of the content type\n * @returns {Number} of draft relations\n */\nconst sumDraftCounts = (entity: any, uid: any): number => {\n const model = strapi.getModel(uid);\n\n return Object.keys(model.attributes).reduce((sum, attributeName) => {\n const attribute: any = model.attributes[attributeName];\n const value = entity[attributeName];\n if (!value) {\n return sum;\n }\n\n switch (attribute.type) {\n case 'relation': {\n if (!('target' in attribute)) {\n return sum;\n }\n\n const targetModel = strapi.getModel(attribute.target);\n if (!targetModel || !hasDraftAndPublish(targetModel)) {\n return sum;\n }\n if (isVisibleAttribute(model, attributeName)) {\n return sum + value.count;\n }\n return sum;\n }\n case 'component': {\n const compoSum = castArray(value).reduce((acc, componentValue) => {\n return acc + sumDraftCounts(componentValue, attribute.component);\n }, 0);\n return sum + compoSum;\n }\n case 'dynamiczone': {\n const dzSum = value.reduce((acc: any, componentValue: any) => {\n return acc + sumDraftCounts(componentValue, componentValue.__component);\n }, 0);\n return sum + dzSum;\n }\n default:\n return sum;\n }\n }, 0);\n};\n\nexport { sumDraftCounts };\n"],"names":["isVisibleAttribute","hasDraftAndPublish","strapiUtils","contentTypes","sumDraftCounts","entity","uid","model","strapi","getModel","Object","keys","attributes","reduce","sum","attributeName","attribute","value","type","targetModel","target","count","compoSum","castArray","acc","componentValue","component","dzSum","__component"],"mappings":";;;AAGA,MAAM,EAAEA,kBAAkB,EAAEC,kBAAkB,EAAE,GAAGC,YAAYC,YAAY;AAC3E;;;;;;;IAQA,MAAMC,cAAAA,GAAiB,CAACC,MAAAA,EAAaC,GAAAA,GA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aAAA;AAAe,gBAAA;AAClB,oBAAA,MAAMK,KAAAA,GAAQV,KAAAA,CAAMJ,MAAM,CAAC,CAACW,GAAAA,EAAUC,cAAAA,GAAAA;AACpC,wBAAA,OAAOD,GAAAA,GAAMpB,cAAAA,CAAeqB,cAAAA,EAAgBA,cAAAA,CAAeG,WAAW,CAAA;oBACxE,CAAA,EAAG,CAAA,CAAA;AACH,oBAAA,OAAOd,GAAAA,GAAMa,KAAAA;AACf,gBAAA;AACA,YAAA;gBACE,OAAOb,GAAAA;AACX;IACF,CAAA,EAAG,CAAA,CAAA;AACL;;;;"}
|
|
1
|
+
{"version":3,"file":"draft.mjs","sources":["../../../../server/src/services/utils/draft.ts"],"sourcesContent":["import { castArray } from 'lodash/fp';\nimport strapiUtils from '@strapi/utils';\nimport type { Core, UID } from '@strapi/types';\n\nimport { type DraftRelationCounts, isBidirectionalManyToMany } from './draft-relations';\n\nconst { isVisibleAttribute, hasDraftAndPublish } = strapiUtils.contentTypes;\n\nconst isLocalizedContentType = (model: { pluginOptions?: unknown }) =>\n (model.pluginOptions as { i18n?: { localized?: boolean } } | undefined)?.i18n?.localized === true;\n\ntype DraftRelationLinkRef = {\n targetUid: UID.Schema;\n documentId: string;\n locale?: string | null;\n};\n\ntype CollectedDraftRelationLinks = {\n m2mLinks: DraftRelationLinkRef[];\n xToOneLinks: DraftRelationLinkRef[];\n};\n\nconst toPublishedDocumentKey = (documentId: string, locale?: string | null) =>\n `${documentId}:${locale ?? ''}`;\n\nconst mergeCollectedLinks = (\n left: CollectedDraftRelationLinks,\n right: CollectedDraftRelationLinks\n): CollectedDraftRelationLinks => ({\n m2mLinks: [...left.m2mLinks, ...right.m2mLinks],\n xToOneLinks: [...left.xToOneLinks, ...right.xToOneLinks],\n});\n\nconst toDraftRelationLink = (\n entry: { documentId?: string; locale?: string | null },\n targetUid: UID.Schema,\n targetIsLocalized: boolean,\n documentLocale?: string | null\n): DraftRelationLinkRef | null => {\n if (!entry?.documentId) {\n return null;\n }\n\n return {\n targetUid,\n documentId: entry.documentId,\n locale: targetIsLocalized ? (entry.locale ?? documentLocale) : null,\n };\n};\n\nconst collectDraftRelationLinks = (\n strapi: Core.Strapi,\n entity: any,\n uid: UID.Schema,\n documentLocale?: string | null\n): CollectedDraftRelationLinks => {\n const model = strapi.getModel(uid);\n const locale = entity.locale ?? documentLocale;\n\n return Object.keys(model.attributes).reduce(\n (collected, attributeName) => {\n const attribute: any = model.attributes[attributeName];\n const value = entity[attributeName];\n\n if (!value) {\n return collected;\n }\n\n switch (attribute.type) {\n case 'relation': {\n if (!('target' in attribute)) {\n return collected;\n }\n\n const targetModel = strapi.getModel(attribute.target as UID.Schema);\n if (!targetModel || !hasDraftAndPublish(targetModel)) {\n return collected;\n }\n\n if (attribute.target === uid || !isVisibleAttribute(model, attributeName)) {\n return collected;\n }\n\n const targetIsLocalized = isLocalizedContentType(targetModel);\n const relatedEntries = castArray(value);\n const links = relatedEntries\n .map((entry) => toDraftRelationLink(entry, attribute.target, targetIsLocalized, locale))\n .filter((link): link is DraftRelationLinkRef => link !== null);\n\n if (links.length === 0) {\n return collected;\n }\n\n if (isBidirectionalManyToMany(attribute)) {\n return {\n ...collected,\n m2mLinks: [...collected.m2mLinks, ...links],\n };\n }\n\n return {\n ...collected,\n xToOneLinks: [...collected.xToOneLinks, ...links],\n };\n }\n case 'component': {\n return castArray(value).reduce(\n (componentCollected, componentValue) =>\n mergeCollectedLinks(\n componentCollected,\n collectDraftRelationLinks(strapi, componentValue, attribute.component, locale)\n ),\n collected\n );\n }\n case 'dynamiczone': {\n return value.reduce((zoneCollected: CollectedDraftRelationLinks, componentValue: any) => {\n return mergeCollectedLinks(\n zoneCollected,\n collectDraftRelationLinks(strapi, componentValue, componentValue.__component, locale)\n );\n }, collected);\n }\n default:\n return collected;\n }\n },\n { m2mLinks: [], xToOneLinks: [] } as CollectedDraftRelationLinks\n );\n};\n\nconst countLinksToUnpublishedDocuments = async (\n strapi: Core.Strapi,\n links: DraftRelationLinkRef[]\n) => {\n if (links.length === 0) {\n return 0;\n }\n\n const linksByTarget = links.reduce<Map<UID.Schema, DraftRelationLinkRef[]>>((acc, link) => {\n const targetLinks = acc.get(link.targetUid) ?? [];\n targetLinks.push(link);\n acc.set(link.targetUid, targetLinks);\n return acc;\n }, new Map());\n\n const counts = await Promise.all(\n Array.from(linksByTarget.entries()).map(async ([targetUid, targetLinks]) => {\n const targetModel = strapi.getModel(targetUid);\n const targetIsLocalized = isLocalizedContentType(targetModel);\n const documentIds = [...new Set(targetLinks.map((link) => link.documentId))];\n\n const publishedRows = await strapi.db.query(targetUid).findMany({\n select: ['documentId', 'locale'],\n where: {\n documentId: { $in: documentIds },\n publishedAt: { $notNull: true },\n },\n });\n\n if (!targetIsLocalized) {\n const publishedDocumentIds = new Set(publishedRows.map((row) => row.documentId));\n\n return targetLinks.filter((link) => !publishedDocumentIds.has(link.documentId)).length;\n }\n\n const publishedDocumentKeys = new Set(\n publishedRows.map((row) => toPublishedDocumentKey(row.documentId, row.locale))\n );\n\n return targetLinks.filter(\n (link) => !publishedDocumentKeys.has(toPublishedDocumentKey(link.documentId, link.locale))\n ).length;\n })\n );\n\n return counts.reduce((total, count) => total + count, 0);\n};\n\n/**\n * sumDraftCounts works recursively on the attributes of a model counting draft relations\n * that matter for publish warnings.\n *\n * - unpublishedRelations: xToOne / oneToMany style links stripped from the published version\n * - draftM2mLinks: bidirectional manyToMany links to documents without a published version\n */\nconst sumDraftCounts = async (\n strapi: Core.Strapi,\n entity: any,\n uid: UID.Schema\n): Promise<DraftRelationCounts> => {\n const { m2mLinks, xToOneLinks } = collectDraftRelationLinks(strapi, entity, uid);\n\n const [draftM2mLinks, unpublishedRelations] = await Promise.all([\n countLinksToUnpublishedDocuments(strapi, m2mLinks),\n countLinksToUnpublishedDocuments(strapi, xToOneLinks),\n ]);\n\n return {\n unpublishedRelations,\n draftM2mLinks,\n };\n};\n\nexport { sumDraftCounts };\n"],"names":["isVisibleAttribute","hasDraftAndPublish","strapiUtils","contentTypes","isLocalizedContentType","model","pluginOptions","i18n","localized","toPublishedDocumentKey","documentId","locale","mergeCollectedLinks","left","right","m2mLinks","xToOneLinks","toDraftRelationLink","entry","targetUid","targetIsLocalized","documentLocale","collectDraftRelationLinks","strapi","entity","uid","getModel","Object","keys","attributes","reduce","collected","attributeName","attribute","value","type","targetModel","target","relatedEntries","castArray","links","map","filter","link","length","isBidirectionalManyToMany","componentCollected","componentValue","component","zoneCollected","__component","countLinksToUnpublishedDocuments","linksByTarget","acc","targetLinks","get","push","set","Map","counts","Promise","all","Array","from","entries","documentIds","Set","publishedRows","db","query","findMany","select","where","$in","publishedAt","$notNull","publishedDocumentIds","row","has","publishedDocumentKeys","total","count","sumDraftCounts","draftM2mLinks","unpublishedRelations"],"mappings":";;;;AAMA,MAAM,EAAEA,kBAAkB,EAAEC,kBAAkB,EAAE,GAAGC,YAAYC,YAAY;AAE3E,MAAMC,sBAAAA,GAAyB,CAACC,KAAAA,GAC7BA,MAAMC,aAAa,EAAqDC,MAAMC,SAAAA,KAAc,IAAA;AAa/F,MAAMC,sBAAAA,GAAyB,CAACC,UAAAA,EAAoBC,MAAAA,GAClD,GAAGD,UAAAA,CAAW,CAAC,EAAEC,MAAAA,IAAU,EAAA,CAAA,CAAI;AAEjC,MAAMC,mBAAAA,GAAsB,CAC1BC,IAAAA,EACAC,KAAAA,IACiC;QACjCC,QAAAA,EAAU;AAAIF,YAAAA,GAAAA,IAAAA,CAAKE,QAAQ;AAAKD,YAAAA,GAAAA,KAAAA,CAAMC;AAAS,SAAA;QAC/CC,WAAAA,EAAa;AAAIH,YAAAA,GAAAA,IAAAA,CAAKG,WAAW;AAAKF,YAAAA,GAAAA,KAAAA,CAAME;AAAY;KAC1D,CAAA;AAEA,MAAMC,mBAAAA,GAAsB,CAC1BC,KAAAA,EACAC,SAAAA,EACAC,iBAAAA,EACAC,cAAAA,GAAAA;IAEA,IAAI,CAACH,OAAOR,UAAAA,EAAY;QACtB,OAAO,IAAA;AACT,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C,KAAAA,EAAO,CAAA,CAAA;AACxD,CAAA;AAEA;;;;;;AAMC,IACD,MAAMC,cAAAA,GAAiB,OACrB3D,MAAAA,EACAC,MAAAA,EACAC,GAAAA,GAAAA;IAEA,MAAM,EAAEV,QAAQ,EAAEC,WAAW,EAAE,GAAGM,yBAAAA,CAA0BC,QAAQC,MAAAA,EAAQC,GAAAA,CAAAA;AAE5E,IAAA,MAAM,CAAC0D,aAAAA,EAAeC,oBAAAA,CAAqB,GAAG,MAAMxB,OAAAA,CAAQC,GAAG,CAAC;AAC9DV,QAAAA,gCAAAA,CAAiC5B,MAAAA,EAAQR,QAAAA,CAAAA;AACzCoC,QAAAA,gCAAAA,CAAiC5B,MAAAA,EAAQP,WAAAA;AAC1C,KAAA,CAAA;IAED,OAAO;AACLoE,QAAAA,oBAAAA;AACAD,QAAAA;AACF,KAAA;AACF;;;;"}
|
|
@@ -4,9 +4,14 @@ var fp = require('lodash/fp');
|
|
|
4
4
|
var strapiUtils = require('@strapi/utils');
|
|
5
5
|
var index = require('../../utils/index.js');
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
|
+
|
|
9
|
+
var strapiUtils__default = /*#__PURE__*/_interopDefault(strapiUtils);
|
|
10
|
+
|
|
11
|
+
const { isVisibleAttribute, isScalarAttribute, getDoesAttributeRequireValidation, isPrivateAttribute, hasDraftAndPublish } = strapiUtils__default.default.contentTypes;
|
|
12
|
+
const { isAnyToMany } = strapiUtils__default.default.relations;
|
|
13
|
+
const { PUBLISHED_AT_ATTRIBUTE } = strapiUtils__default.default.contentTypes.constants;
|
|
14
|
+
const isLocalizedContentType = (model)=>model.pluginOptions?.i18n?.localized === true;
|
|
10
15
|
const isMorphToRelation = (attribute)=>isRelation(attribute) && attribute.relation.includes('morphTo');
|
|
11
16
|
const isMedia = fp.propEq('type', 'media');
|
|
12
17
|
const isRelation = fp.propEq('type', 'relation');
|
|
@@ -234,9 +239,22 @@ const getDeepPopulateDraftCount = (uid)=>{
|
|
|
234
239
|
if (!targetModel || !hasDraftAndPublish(targetModel)) {
|
|
235
240
|
break;
|
|
236
241
|
}
|
|
242
|
+
// Self-referential relations are preserved on publish (see self-referential-relations.ts).
|
|
243
|
+
if (attribute.target === uid) {
|
|
244
|
+
break;
|
|
245
|
+
}
|
|
237
246
|
if (isVisibleAttribute(model, attributeName)) {
|
|
247
|
+
// Draft entries link to draft rows of related documents. Populate documentId/locale
|
|
248
|
+
// so we can distinguish truly unpublished targets from published documents that
|
|
249
|
+
// still have a draft row (those links are kept on publish for M2M, or remapped for xToOne).
|
|
250
|
+
const fields = [
|
|
251
|
+
'documentId'
|
|
252
|
+
];
|
|
253
|
+
if (isLocalizedContentType(targetModel)) {
|
|
254
|
+
fields.push('locale');
|
|
255
|
+
}
|
|
238
256
|
populateAcc[attributeName] = {
|
|
239
|
-
|
|
257
|
+
fields,
|
|
240
258
|
filters: {
|
|
241
259
|
[PUBLISHED_AT_ATTRIBUTE]: {
|
|
242
260
|
$null: true
|
|
@@ -294,7 +312,7 @@ const getDeepPopulateDraftCount = (uid)=>{
|
|
|
294
312
|
* Create a Strapi populate object which populates all attribute fields of a Strapi query.
|
|
295
313
|
*/ const getQueryPopulate = async (uid, query)=>{
|
|
296
314
|
let populateQuery = {};
|
|
297
|
-
await
|
|
315
|
+
await strapiUtils__default.default.traverse.traverseQueryFilters(/**
|
|
298
316
|
*
|
|
299
317
|
* @param {Object} param0
|
|
300
318
|
* @param {string} param0.key - Attribute name
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"populate.js","sources":["../../../../server/src/services/utils/populate.ts"],"sourcesContent":["import { merge, isEmpty, set, propEq } from 'lodash/fp';\nimport strapiUtils from '@strapi/utils';\nimport type { UID, Schema, Modules } from '@strapi/types';\nimport { getService } from '../../utils';\n\nconst {\n isVisibleAttribute,\n isScalarAttribute,\n getDoesAttributeRequireValidation,\n isPrivateAttribute,\n hasDraftAndPublish,\n} = strapiUtils.contentTypes;\nconst { isAnyToMany } = strapiUtils.relations;\nconst { PUBLISHED_AT_ATTRIBUTE } = strapiUtils.contentTypes.constants;\n\nconst isMorphToRelation = (attribute: any) =>\n isRelation(attribute) && attribute.relation.includes('morphTo');\nconst isMedia = propEq('type', 'media');\nconst isRelation = propEq('type', 'relation');\nconst isComponent = propEq('type', 'component');\nconst isDynamicZone = propEq('type', 'dynamiczone');\n\n// TODO: Import from @strapi/types when it's available there\ntype Model = Parameters<typeof isVisibleAttribute>[0];\nexport type Populate = Modules.EntityService.Params.Populate.Any<UID.Schema>;\n\ntype PopulateOptions = {\n initialPopulate?: Populate;\n countMany?: boolean;\n countOne?: boolean;\n maxLevel?: number;\n};\n\n/**\n * Populate the model for relation\n * @param attribute - Attribute containing a relation\n * @param attribute.relation - type of relation\n * @param model - Model of the populated entity\n * @param attributeName\n * @param options - Options to apply while populating\n */\nfunction getPopulateForRelation(\n attribute: Schema.Attribute.AnyAttribute,\n model: Model,\n attributeName: string,\n { countMany, countOne, initialPopulate }: PopulateOptions\n) {\n const isManyRelation = isAnyToMany(attribute);\n\n // Use initialPopulate when explicitly provided (including `false` to suppress population)\n if (initialPopulate !== undefined) {\n return initialPopulate;\n }\n\n // If populating localizations attribute, also include validatable fields\n // Mainly needed for bulk locale publishing, so the Client has all the information necessary to perform validations\n if (attributeName === 'localizations') {\n const validationPopulate = getPopulateForValidation(model.uid as UID.Schema);\n\n return {\n populate: validationPopulate.populate,\n };\n }\n\n // always populate createdBy, updatedBy, localizations etc.\n if (!isVisibleAttribute(model, attributeName)) {\n return true;\n }\n\n if ((isManyRelation && countMany) || (!isManyRelation && countOne)) {\n return { count: true };\n }\n\n return true;\n}\n\n/**\n * Populate the model for Dynamic Zone components\n * @param attribute - Attribute containing the components\n * @param attribute.components - IDs of components\n * @param options - Options to apply while populating\n */\nfunction getPopulateForDZ(\n attribute: Schema.Attribute.DynamicZone,\n options: PopulateOptions,\n level: number\n) {\n // Use fragments to populate the dynamic zone components\n const populatedComponents = (attribute.components || []).reduce(\n (acc: any, componentUID: UID.Component) => ({\n ...acc,\n [componentUID]: {\n populate: getDeepPopulate(componentUID, options, level + 1),\n },\n }),\n {}\n );\n\n return { on: populatedComponents };\n}\n\n/**\n * Get the populated value based on the type of the attribute\n * @param attributeName - Name of the attribute\n * @param model - Model of the populated entity\n * @param model.attributes\n * @param options - Options to apply while populating\n * @param options.countMany\n * @param options.countOne\n * @param options.maxLevel\n * @param level\n */\nfunction getPopulateFor(\n attributeName: string,\n model: any,\n options: PopulateOptions,\n level: number\n): { [key: string]: boolean | object } {\n const attribute = model.attributes[attributeName];\n\n switch (attribute.type) {\n case 'relation':\n // @ts-expect-error - TODO: support populate count typing\n return {\n [attributeName]: getPopulateForRelation(attribute, model, attributeName, options),\n };\n case 'component':\n return {\n [attributeName]: {\n populate: getDeepPopulate(attribute.component, options, level + 1),\n },\n };\n case 'media':\n return {\n [attributeName]: {\n populate: {\n folder: true,\n },\n },\n };\n case 'dynamiczone':\n return {\n [attributeName]: getPopulateForDZ(attribute, options, level),\n };\n default:\n return {};\n }\n}\n\n/**\n * Deeply populate a model based on UID\n * @param uid - Unique identifier of the model\n * @param options - Options to apply while populating\n * @param level - Current level of nested call\n */\nconst getDeepPopulate = (\n uid: UID.Schema,\n {\n initialPopulate = {} as any,\n countMany = false,\n countOne = false,\n maxLevel = Infinity,\n }: PopulateOptions = {},\n level = 1\n) => {\n if (level > maxLevel) {\n return {};\n }\n\n const model = strapi.getModel(uid);\n\n if (!model) {\n return {};\n }\n\n return Object.keys(model.attributes).reduce(\n (populateAcc, attributeName: string) =>\n merge(\n populateAcc,\n getPopulateFor(\n attributeName,\n model,\n {\n // @ts-expect-error - improve types\n initialPopulate: initialPopulate?.[attributeName],\n countMany,\n countOne,\n maxLevel,\n },\n level\n )\n ),\n {}\n );\n};\n\n/**\n * Deeply populate a model based on UID. Only populating fields that require validation.\n * @param uid - Unique identifier of the model\n * @param options - Options to apply while populating\n * @param level - Current level of nested call\n */\nconst validationPopulateCache = new Map<string, Record<string, any>>();\n\nconst getPopulateForValidation = (uid: UID.Schema): Record<string, any> => {\n const cached = validationPopulateCache.get(uid);\n if (cached) {\n return cached;\n }\n\n const model = strapi.getModel(uid);\n if (!model) {\n return {};\n }\n\n const result = Object.entries(model.attributes).reduce(\n (populateAcc: any, [attributeName, attribute]) => {\n if (isScalarAttribute(attribute)) {\n // If the scalar attribute requires validation, add it to the fields array\n if (\n getDoesAttributeRequireValidation(attribute) &&\n !isPrivateAttribute(model, attributeName)\n ) {\n populateAcc.fields = populateAcc.fields || [];\n populateAcc.fields.push(attributeName);\n }\n return populateAcc;\n }\n\n if (isMedia(attribute)) {\n if (\n getDoesAttributeRequireValidation(attribute) &&\n !isPrivateAttribute(model, attributeName)\n ) {\n populateAcc.populate = populateAcc.populate || {};\n populateAcc.populate[attributeName] = {\n populate: {\n folder: true,\n },\n };\n return populateAcc;\n }\n }\n\n if (isComponent(attribute)) {\n // @ts-expect-error - should be a component\n const component = attribute.component;\n\n // Get the validation result for this component\n const componentResult = getPopulateForValidation(component);\n\n if (Object.keys(componentResult).length > 0) {\n populateAcc.populate = populateAcc.populate || {};\n populateAcc.populate[attributeName] = componentResult;\n }\n\n return populateAcc;\n }\n\n if (isDynamicZone(attribute)) {\n const components = (attribute as Schema.Attribute.DynamicZone).components;\n // Handle dynamic zone components\n const componentsResult = (components || []).reduce(\n (acc, componentUID) => {\n // Get validation populate for this component\n const componentResult = getPopulateForValidation(componentUID);\n\n // Only include component if it has fields requiring validation\n if (Object.keys(componentResult).length > 0) {\n acc[componentUID] = componentResult;\n }\n\n return acc;\n },\n {} as Record<string, any>\n );\n\n // Only add to populate if we have components requiring validation\n if (Object.keys(componentsResult).length > 0) {\n populateAcc.populate = populateAcc.populate || {};\n populateAcc.populate[attributeName] = { on: componentsResult };\n }\n }\n\n return populateAcc;\n },\n {}\n );\n\n validationPopulateCache.set(uid, result);\n return result;\n};\n\n/**\n * getDeepPopulateDraftCount works recursively on the attributes of a model\n * creating a populated object to count all the unpublished relations within the model\n * These relations can be direct to this content type or contained within components/dynamic zones\n * @param uid of the model\n * @returns result\n * @returns result.populate\n * @returns result.hasRelations\n */\nconst draftCountPopulateCache = new Map<string, { populate: any; hasRelations: boolean }>();\n\nconst getDeepPopulateDraftCount = (uid: UID.Schema) => {\n const cached = draftCountPopulateCache.get(uid);\n if (cached) {\n return cached;\n }\n\n const model = strapi.getModel(uid);\n if (!model) {\n return { populate: {}, hasRelations: false };\n }\n let hasRelations = false;\n\n const populate = Object.keys(model.attributes).reduce((populateAcc: any, attributeName) => {\n const attribute: Schema.Attribute.AnyAttribute = model.attributes[attributeName];\n\n switch (attribute.type) {\n case 'relation': {\n // TODO: Support polymorphic relations\n const isMorphRelation = attribute.relation.toLowerCase().startsWith('morph');\n if (isMorphRelation) {\n break;\n }\n\n // Skip relations to content types without draft & publish,\n // as they don't have a publishedAt attribute and can't have drafts\n if (!('target' in attribute)) {\n break;\n }\n\n const targetModel = strapi.getModel(attribute.target);\n if (!targetModel || !hasDraftAndPublish(targetModel)) {\n break;\n }\n\n if (isVisibleAttribute(model, attributeName)) {\n populateAcc[attributeName] = {\n count: true,\n filters: { [PUBLISHED_AT_ATTRIBUTE]: { $null: true } },\n };\n hasRelations = true;\n }\n break;\n }\n case 'component': {\n const { populate, hasRelations: childHasRelations } = getDeepPopulateDraftCount(\n attribute.component\n );\n if (childHasRelations) {\n populateAcc[attributeName] = {\n populate,\n };\n hasRelations = true;\n }\n break;\n }\n case 'dynamiczone': {\n const dzPopulateFragment = attribute.components?.reduce((acc, componentUID) => {\n const { populate: componentPopulate, hasRelations: componentHasRelations } =\n getDeepPopulateDraftCount(componentUID);\n\n if (componentHasRelations) {\n hasRelations = true;\n\n return { ...acc, [componentUID]: { populate: componentPopulate } };\n }\n\n return acc;\n }, {});\n\n if (!isEmpty(dzPopulateFragment)) {\n populateAcc[attributeName] = { on: dzPopulateFragment };\n }\n break;\n }\n default:\n }\n\n return populateAcc;\n }, {});\n\n const result = { populate, hasRelations };\n draftCountPopulateCache.set(uid, result);\n return result;\n};\n\n/**\n * Create a Strapi populate object which populates all attribute fields of a Strapi query.\n */\nconst getQueryPopulate = async (uid: UID.Schema, query: object): Promise<Populate> => {\n let populateQuery: Populate = {};\n\n await strapiUtils.traverse.traverseQueryFilters(\n /**\n *\n * @param {Object} param0\n * @param {string} param0.key - Attribute name\n * @param {Object} param0.attribute - Attribute definition\n * @param {string} param0.path - Content Type path to the attribute\n * @returns\n */\n ({ attribute, path }: any) => {\n // TODO: handle dynamic zones and morph relations\n if (!attribute || isDynamicZone(attribute) || isMorphToRelation(attribute)) {\n return;\n }\n\n // Populate all relations, components and media\n if (isRelation(attribute) || isMedia(attribute) || isComponent(attribute)) {\n const populatePath = path.attribute.replace(/\\./g, '.populate.');\n // @ts-expect-error - lodash doesn't resolve the Populate type correctly\n populateQuery = set(populatePath, {}, populateQuery);\n }\n },\n { schema: strapi.getModel(uid), getModel: strapi.getModel.bind(strapi) },\n query\n );\n\n return populateQuery;\n};\n\nconst deepPopulateCache = new Map<string, object>();\n\nconst buildDeepPopulate = async (uid: UID.CollectionType) => {\n const cached = deepPopulateCache.get(uid);\n if (cached) {\n return cached;\n }\n\n const result = await getService('populate-builder')(uid)\n .populateDeep(Infinity)\n .countRelations()\n .build();\n\n deepPopulateCache.set(uid, result);\n\n return result;\n};\n\n/**\n * Restrict localizations populate to only metadata fields for localized content types.\n * Returns an empty object for non-localized content types.\n *\n * By default, localizations are deeply populated which includes all relations and\n * components for every locale — this is expensive and unnecessary for CM responses.\n * The CM only needs these fields from localizations:\n * - locale: to identify which locales exist\n * - documentId: to link to the localized document\n * - publishedAt: to determine published/draft status\n * - updatedAt: to support the modified state indicator in the UI\n */\nconst getPopulateForLocalizations = (model: UID.Schema) => {\n const modelSchema = strapi.getModel(model);\n if (\n (modelSchema as unknown as { pluginOptions: { i18n: { localized?: boolean } } }).pluginOptions\n ?.i18n?.localized\n ) {\n return { localizations: { fields: ['locale', 'documentId', 'publishedAt', 'updatedAt'] } };\n }\n\n return {};\n};\n\nexport {\n getDeepPopulate,\n getDeepPopulateDraftCount,\n getPopulateForValidation,\n getQueryPopulate,\n buildDeepPopulate,\n getPopulateForLocalizations,\n};\n"],"names":["isVisibleAttribute","isScalarAttribute","getDoesAttributeRequireValidation","isPrivateAttribute","hasDraftAndPublish","strapiUtils","contentTypes","isAnyToMany","relations","PUBLISHED_AT_ATTRIBUTE","constants","isMorphToRelation","attribute","isRelation","relation","includes","isMedia","propEq","isComponent","isDynamicZone","getPopulateForRelation","model","attributeName","countMany","countOne","initialPopulate","isManyRelation","undefined","validationPopulate","getPopulateForValidation","uid","populate","count","getPopulateForDZ","options","level","populatedComponents","components","reduce","acc","componentUID","getDeepPopulate","on","getPopulateFor","attributes","type","component","folder","maxLevel","Infinity","strapi","getModel","Object","keys","populateAcc","merge","validationPopulateCache","Map","cached","get","result","entries","fields","push","componentResult","length","componentsResult","set","draftCountPopulateCache","getDeepPopulateDraftCount","hasRelations","isMorphRelation","toLowerCase","startsWith","targetModel","target","filters","$null","childHasRelations","dzPopulateFragment","componentPopulate","componentHasRelations","isEmpty","getQueryPopulate","query","populateQuery","traverse","traverseQueryFilters","path","populatePath","replace","schema","bind","deepPopulateCache","buildDeepPopulate","getService","populateDeep","countRelations","build","getPopulateForLocalizations","modelSchema","pluginOptions","i18n","localized","localizations"],"mappings":";;;;;;AAKA,MAAM,EACJA,kBAAkB,EAClBC,iBAAiB,EACjBC,iCAAiC,EACjCC,kBAAkB,EAClBC,kBAAkB,EACnB,GAAGC,YAAYC,YAAY;AAC5B,MAAM,EAAEC,WAAW,EAAE,GAAGF,YAAYG,SAAS;AAC7C,MAAM,EAAEC,sBAAsB,EAAE,GAAGJ,WAAAA,CAAYC,YAAY,CAACI,SAAS;AAErE,MAAMC,iBAAAA,GAAoB,CAACC,SAAAA,GACzBC,UAAAA,CAAWD,cAAcA,SAAAA,CAAUE,QAAQ,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E,WAAAA,GAAclD,MAAAA,CAAOC,QAAQ,CAAC9B,KAAAA,CAAAA;AACpC,IAAA,IACE,WAAC+E,CAAgFC,aAAa,EAC1FC,MAAMC,SAAAA,EACV;QACA,OAAO;YAAEC,aAAAA,EAAe;gBAAE1C,MAAAA,EAAQ;AAAC,oBAAA,QAAA;AAAU,oBAAA,YAAA;AAAc,oBAAA,aAAA;AAAe,oBAAA;AAAY;AAAC;AAAE,SAAA;AAC3F,IAAA;AAEA,IAAA,OAAO,EAAC;AACV;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"populate.js","sources":["../../../../server/src/services/utils/populate.ts"],"sourcesContent":["import { merge, isEmpty, set, propEq } from 'lodash/fp';\nimport strapiUtils from '@strapi/utils';\nimport type { UID, Schema, Modules } from '@strapi/types';\nimport { getService } from '../../utils';\n\nconst {\n isVisibleAttribute,\n isScalarAttribute,\n getDoesAttributeRequireValidation,\n isPrivateAttribute,\n hasDraftAndPublish,\n} = strapiUtils.contentTypes;\nconst { isAnyToMany } = strapiUtils.relations;\nconst { PUBLISHED_AT_ATTRIBUTE } = strapiUtils.contentTypes.constants;\n\nconst isLocalizedContentType = (model: { pluginOptions?: unknown }) =>\n (model.pluginOptions as { i18n?: { localized?: boolean } } | undefined)?.i18n?.localized === true;\n\nconst isMorphToRelation = (attribute: any) =>\n isRelation(attribute) && attribute.relation.includes('morphTo');\nconst isMedia = propEq('type', 'media');\nconst isRelation = propEq('type', 'relation');\nconst isComponent = propEq('type', 'component');\nconst isDynamicZone = propEq('type', 'dynamiczone');\n\n// TODO: Import from @strapi/types when it's available there\ntype Model = Parameters<typeof isVisibleAttribute>[0];\nexport type Populate = Modules.EntityService.Params.Populate.Any<UID.Schema>;\n\ntype PopulateOptions = {\n initialPopulate?: Populate;\n countMany?: boolean;\n countOne?: boolean;\n maxLevel?: number;\n};\n\n/**\n * Populate the model for relation\n * @param attribute - Attribute containing a relation\n * @param attribute.relation - type of relation\n * @param model - Model of the populated entity\n * @param attributeName\n * @param options - Options to apply while populating\n */\nfunction getPopulateForRelation(\n attribute: Schema.Attribute.AnyAttribute,\n model: Model,\n attributeName: string,\n { countMany, countOne, initialPopulate }: PopulateOptions\n) {\n const isManyRelation = isAnyToMany(attribute);\n\n // Use initialPopulate when explicitly provided (including `false` to suppress population)\n if (initialPopulate !== undefined) {\n return initialPopulate;\n }\n\n // If populating localizations attribute, also include validatable fields\n // Mainly needed for bulk locale publishing, so the Client has all the information necessary to perform validations\n if (attributeName === 'localizations') {\n const validationPopulate = getPopulateForValidation(model.uid as UID.Schema);\n\n return {\n populate: validationPopulate.populate,\n };\n }\n\n // always populate createdBy, updatedBy, localizations etc.\n if (!isVisibleAttribute(model, attributeName)) {\n return true;\n }\n\n if ((isManyRelation && countMany) || (!isManyRelation && countOne)) {\n return { count: true };\n }\n\n return true;\n}\n\n/**\n * Populate the model for Dynamic Zone components\n * @param attribute - Attribute containing the components\n * @param attribute.components - IDs of components\n * @param options - Options to apply while populating\n */\nfunction getPopulateForDZ(\n attribute: Schema.Attribute.DynamicZone,\n options: PopulateOptions,\n level: number\n): { on: { [key: string]: { populate: { [key: string]: boolean | object } } } } {\n // Use fragments to populate the dynamic zone components\n const populatedComponents = (attribute.components || []).reduce(\n (acc: any, componentUID: UID.Component) => ({\n ...acc,\n [componentUID]: {\n populate: getDeepPopulate(componentUID, options, level + 1),\n },\n }),\n {}\n );\n\n return { on: populatedComponents };\n}\n\n/**\n * Get the populated value based on the type of the attribute\n * @param attributeName - Name of the attribute\n * @param model - Model of the populated entity\n * @param model.attributes\n * @param options - Options to apply while populating\n * @param options.countMany\n * @param options.countOne\n * @param options.maxLevel\n * @param level\n */\nfunction getPopulateFor(\n attributeName: string,\n model: any,\n options: PopulateOptions,\n level: number\n): { [key: string]: boolean | object } {\n const attribute = model.attributes[attributeName];\n\n switch (attribute.type) {\n case 'relation':\n // @ts-expect-error - TODO: support populate count typing\n return {\n [attributeName]: getPopulateForRelation(attribute, model, attributeName, options),\n };\n case 'component':\n return {\n [attributeName]: {\n populate: getDeepPopulate(attribute.component, options, level + 1),\n },\n };\n case 'media':\n return {\n [attributeName]: {\n populate: {\n folder: true,\n },\n },\n };\n case 'dynamiczone':\n return {\n [attributeName]: getPopulateForDZ(attribute, options, level),\n };\n default:\n return {};\n }\n}\n\n/**\n * Deeply populate a model based on UID\n * @param uid - Unique identifier of the model\n * @param options - Options to apply while populating\n * @param level - Current level of nested call\n */\nconst getDeepPopulate = (\n uid: UID.Schema,\n {\n initialPopulate = {} as any,\n countMany = false,\n countOne = false,\n maxLevel = Infinity,\n }: PopulateOptions = {},\n level = 1\n): { [key: string]: boolean | object } => {\n if (level > maxLevel) {\n return {};\n }\n\n const model = strapi.getModel(uid);\n\n if (!model) {\n return {};\n }\n\n return Object.keys(model.attributes).reduce(\n (populateAcc, attributeName: string) =>\n merge(\n populateAcc,\n getPopulateFor(\n attributeName,\n model,\n {\n // @ts-expect-error - improve types\n initialPopulate: initialPopulate?.[attributeName],\n countMany,\n countOne,\n maxLevel,\n },\n level\n )\n ),\n {}\n );\n};\n\n/**\n * Deeply populate a model based on UID. Only populating fields that require validation.\n * @param uid - Unique identifier of the model\n * @param options - Options to apply while populating\n * @param level - Current level of nested call\n */\nconst validationPopulateCache = new Map<string, Record<string, any>>();\n\nconst getPopulateForValidation = (uid: UID.Schema): Record<string, any> => {\n const cached = validationPopulateCache.get(uid);\n if (cached) {\n return cached;\n }\n\n const model = strapi.getModel(uid);\n if (!model) {\n return {};\n }\n\n const result = Object.entries(model.attributes).reduce(\n (populateAcc: any, [attributeName, attribute]) => {\n if (isScalarAttribute(attribute)) {\n // If the scalar attribute requires validation, add it to the fields array\n if (\n getDoesAttributeRequireValidation(attribute) &&\n !isPrivateAttribute(model, attributeName)\n ) {\n populateAcc.fields = populateAcc.fields || [];\n populateAcc.fields.push(attributeName);\n }\n return populateAcc;\n }\n\n if (isMedia(attribute)) {\n if (\n getDoesAttributeRequireValidation(attribute) &&\n !isPrivateAttribute(model, attributeName)\n ) {\n populateAcc.populate = populateAcc.populate || {};\n populateAcc.populate[attributeName] = {\n populate: {\n folder: true,\n },\n };\n return populateAcc;\n }\n }\n\n if (isComponent(attribute)) {\n // @ts-expect-error - should be a component\n const component = attribute.component;\n\n // Get the validation result for this component\n const componentResult = getPopulateForValidation(component);\n\n if (Object.keys(componentResult).length > 0) {\n populateAcc.populate = populateAcc.populate || {};\n populateAcc.populate[attributeName] = componentResult;\n }\n\n return populateAcc;\n }\n\n if (isDynamicZone(attribute)) {\n const components = (attribute as Schema.Attribute.DynamicZone).components;\n // Handle dynamic zone components\n const componentsResult = (components || []).reduce(\n (acc, componentUID) => {\n // Get validation populate for this component\n const componentResult = getPopulateForValidation(componentUID);\n\n // Only include component if it has fields requiring validation\n if (Object.keys(componentResult).length > 0) {\n acc[componentUID] = componentResult;\n }\n\n return acc;\n },\n {} as Record<string, any>\n );\n\n // Only add to populate if we have components requiring validation\n if (Object.keys(componentsResult).length > 0) {\n populateAcc.populate = populateAcc.populate || {};\n populateAcc.populate[attributeName] = { on: componentsResult };\n }\n }\n\n return populateAcc;\n },\n {}\n );\n\n validationPopulateCache.set(uid, result);\n return result;\n};\n\n/**\n * getDeepPopulateDraftCount works recursively on the attributes of a model\n * creating a populated object to count all the unpublished relations within the model\n * These relations can be direct to this content type or contained within components/dynamic zones\n * @param uid of the model\n * @returns result\n * @returns result.populate\n * @returns result.hasRelations\n */\nconst draftCountPopulateCache = new Map<string, { populate: any; hasRelations: boolean }>();\n\nconst getDeepPopulateDraftCount = (uid: UID.Schema): { populate: any; hasRelations: boolean } => {\n const cached = draftCountPopulateCache.get(uid);\n if (cached) {\n return cached;\n }\n\n const model = strapi.getModel(uid);\n if (!model) {\n return { populate: {}, hasRelations: false };\n }\n let hasRelations = false;\n\n const populate = Object.keys(model.attributes).reduce((populateAcc: any, attributeName) => {\n const attribute: Schema.Attribute.AnyAttribute = model.attributes[attributeName];\n\n switch (attribute.type) {\n case 'relation': {\n // TODO: Support polymorphic relations\n const isMorphRelation = attribute.relation.toLowerCase().startsWith('morph');\n if (isMorphRelation) {\n break;\n }\n\n // Skip relations to content types without draft & publish,\n // as they don't have a publishedAt attribute and can't have drafts\n if (!('target' in attribute)) {\n break;\n }\n\n const targetModel = strapi.getModel(attribute.target);\n if (!targetModel || !hasDraftAndPublish(targetModel)) {\n break;\n }\n\n // Self-referential relations are preserved on publish (see self-referential-relations.ts).\n if (attribute.target === uid) {\n break;\n }\n\n if (isVisibleAttribute(model, attributeName)) {\n // Draft entries link to draft rows of related documents. Populate documentId/locale\n // so we can distinguish truly unpublished targets from published documents that\n // still have a draft row (those links are kept on publish for M2M, or remapped for xToOne).\n const fields: string[] = ['documentId'];\n if (isLocalizedContentType(targetModel)) {\n fields.push('locale');\n }\n populateAcc[attributeName] = {\n fields,\n filters: { [PUBLISHED_AT_ATTRIBUTE]: { $null: true } },\n };\n hasRelations = true;\n }\n break;\n }\n case 'component': {\n const { populate, hasRelations: childHasRelations } = getDeepPopulateDraftCount(\n attribute.component\n );\n if (childHasRelations) {\n populateAcc[attributeName] = {\n populate,\n };\n hasRelations = true;\n }\n break;\n }\n case 'dynamiczone': {\n const dzPopulateFragment = attribute.components?.reduce((acc, componentUID) => {\n const { populate: componentPopulate, hasRelations: componentHasRelations } =\n getDeepPopulateDraftCount(componentUID);\n\n if (componentHasRelations) {\n hasRelations = true;\n\n return { ...acc, [componentUID]: { populate: componentPopulate } };\n }\n\n return acc;\n }, {});\n\n if (!isEmpty(dzPopulateFragment)) {\n populateAcc[attributeName] = { on: dzPopulateFragment };\n }\n break;\n }\n default:\n }\n\n return populateAcc;\n }, {});\n\n const result = { populate, hasRelations };\n draftCountPopulateCache.set(uid, result);\n return result;\n};\n\n/**\n * Create a Strapi populate object which populates all attribute fields of a Strapi query.\n */\nconst getQueryPopulate = async (uid: UID.Schema, query: object): Promise<Populate> => {\n let populateQuery: Populate = {};\n\n await strapiUtils.traverse.traverseQueryFilters(\n /**\n *\n * @param {Object} param0\n * @param {string} param0.key - Attribute name\n * @param {Object} param0.attribute - Attribute definition\n * @param {string} param0.path - Content Type path to the attribute\n * @returns\n */\n ({ attribute, path }: any) => {\n // TODO: handle dynamic zones and morph relations\n if (!attribute || isDynamicZone(attribute) || isMorphToRelation(attribute)) {\n return;\n }\n\n // Populate all relations, components and media\n if (isRelation(attribute) || isMedia(attribute) || isComponent(attribute)) {\n const populatePath = path.attribute.replace(/\\./g, '.populate.');\n // @ts-expect-error - lodash doesn't resolve the Populate type correctly\n populateQuery = set(populatePath, {}, populateQuery);\n }\n },\n { schema: strapi.getModel(uid), getModel: strapi.getModel.bind(strapi) },\n query\n );\n\n return populateQuery;\n};\n\nconst deepPopulateCache = new Map<string, object>();\n\nconst buildDeepPopulate = async (uid: UID.CollectionType) => {\n const cached = deepPopulateCache.get(uid);\n if (cached) {\n return cached;\n }\n\n const result = await getService('populate-builder')(uid)\n .populateDeep(Infinity)\n .countRelations()\n .build();\n\n deepPopulateCache.set(uid, result);\n\n return result;\n};\n\n/**\n * Restrict localizations populate to only metadata fields for localized content types.\n * Returns an empty object for non-localized content types.\n *\n * By default, localizations are deeply populated which includes all relations and\n * components for every locale — this is expensive and unnecessary for CM responses.\n * The CM only needs these fields from localizations:\n * - locale: to identify which locales exist\n * - documentId: to link to the localized document\n * - publishedAt: to determine published/draft status\n * - updatedAt: to support the modified state indicator in the UI\n */\nconst getPopulateForLocalizations = (model: UID.Schema) => {\n const modelSchema = strapi.getModel(model);\n if (\n (modelSchema as unknown as { pluginOptions: { i18n: { localized?: boolean } } }).pluginOptions\n ?.i18n?.localized\n ) {\n return { localizations: { fields: ['locale', 'documentId', 'publishedAt', 'updatedAt'] } };\n }\n\n return {};\n};\n\nexport {\n getDeepPopulate,\n getDeepPopulateDraftCount,\n getPopulateForValidation,\n getQueryPopulate,\n buildDeepPopulate,\n getPopulateForLocalizations,\n};\n"],"names":["isVisibleAttribute","isScalarAttribute","getDoesAttributeRequireValidation","isPrivateAttribute","hasDraftAndPublish","strapiUtils","contentTypes","isAnyToMany","relations","PUBLISHED_AT_ATTRIBUTE","constants","isLocalizedContentType","model","pluginOptions","i18n","localized","isMorphToRelation","attribute","isRelation","relation","includes","isMedia","propEq","isComponent","isDynamicZone","getPopulateForRelation","attributeName","countMany","countOne","initialPopulate","isManyRelation","undefined","validationPopulate","getPopulateForValidation","uid","populate","count","getPopulateForDZ","options","level","populatedComponents","components","reduce","acc","componentUID","getDeepPopulate","on","getPopulateFor","attributes","type","component","folder","maxLevel","Infinity","strapi","getModel","Object","keys","populateAcc","merge","validationPopulateCache","Map","cached","get","result","entries","fields","push","componentResult","length","componentsResult","set","draftCountPopulateCache","getDeepPopulateDraftCount","hasRelations","isMorphRelation","toLowerCase","startsWith","targetModel","target","filters","$null","childHasRelations","dzPopulateFragment","componentPopulate","componentHasRelations","isEmpty","getQueryPopulate","query","populateQuery","traverse","traverseQueryFilters","path","populatePath","replace","schema","bind","deepPopulateCache","buildDeepPopulate","getService","populateDeep","countRelations","build","getPopulateForLocalizations","modelSchema","localizations"],"mappings":";;;;;;;;;;AAKA,MAAM,EACJA,kBAAkB,EAClBC,iBAAiB,EACjBC,iCAAiC,EACjCC,kBAAkB,EAClBC,kBAAkB,EACnB,GAAGC,6BAAYC,YAAY;AAC5B,MAAM,EAAEC,WAAW,EAAE,GAAGF,6BAAYG,SAAS;AAC7C,MAAM,EAAEC,sBAAsB,EAAE,GAAGJ,4BAAAA,CAAYC,YAAY,CAACI,SAAS;AAErE,MAAMC,sBAAAA,GAAyB,CAACC,KAAAA,GAC7BA,MAAMC,aAAa,EAAqDC,MAAMC,SAAAA,KAAc,IAAA;AAE/F,MAAMC,iBAAAA,GAAoB,CAACC,SAAAA,GACzBC,UAAAA,CAAWD,cAAcA,SAAAA,CAAUE,QAAQ,CAACC,QAAQ,CAAC,SAAA,CAAA;AACvD,MAAMC,OAAAA,GAAUC,UAAO,MAAA,EAAQ,OAAA,CAAA;AAC/B,MAAMJ,UAAAA,GAAaI,UAAO,MAAA,EAAQ,UAAA,C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AAA,EAAK8B,MAAAA,CAAAA;IAE3B,OAAOA,MAAAA;AACT;AAEA;;;;;;;;;;;IAYA,MAAMuC,8BAA8B,CAAC3F,KAAAA,GAAAA;IACnC,MAAM4F,WAAAA,GAAclD,MAAAA,CAAOC,QAAQ,CAAC3C,KAAAA,CAAAA;AACpC,IAAA,IACE,WAAC4F,CAAgF3F,aAAa,EAC1FC,MAAMC,SAAAA,EACV;QACA,OAAO;YAAE0F,aAAAA,EAAe;gBAAEvC,MAAAA,EAAQ;AAAC,oBAAA,QAAA;AAAU,oBAAA,YAAA;AAAc,oBAAA,aAAA;AAAe,oBAAA;AAAY;AAAC;AAAE,SAAA;AAC3F,IAAA;AAEA,IAAA,OAAO,EAAC;AACV;;;;;;;;;"}
|
|
@@ -5,6 +5,7 @@ import { getService } from '../../utils/index.mjs';
|
|
|
5
5
|
const { isVisibleAttribute, isScalarAttribute, getDoesAttributeRequireValidation, isPrivateAttribute, hasDraftAndPublish } = strapiUtils.contentTypes;
|
|
6
6
|
const { isAnyToMany } = strapiUtils.relations;
|
|
7
7
|
const { PUBLISHED_AT_ATTRIBUTE } = strapiUtils.contentTypes.constants;
|
|
8
|
+
const isLocalizedContentType = (model)=>model.pluginOptions?.i18n?.localized === true;
|
|
8
9
|
const isMorphToRelation = (attribute)=>isRelation(attribute) && attribute.relation.includes('morphTo');
|
|
9
10
|
const isMedia = propEq('type', 'media');
|
|
10
11
|
const isRelation = propEq('type', 'relation');
|
|
@@ -232,9 +233,22 @@ const getDeepPopulateDraftCount = (uid)=>{
|
|
|
232
233
|
if (!targetModel || !hasDraftAndPublish(targetModel)) {
|
|
233
234
|
break;
|
|
234
235
|
}
|
|
236
|
+
// Self-referential relations are preserved on publish (see self-referential-relations.ts).
|
|
237
|
+
if (attribute.target === uid) {
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
235
240
|
if (isVisibleAttribute(model, attributeName)) {
|
|
241
|
+
// Draft entries link to draft rows of related documents. Populate documentId/locale
|
|
242
|
+
// so we can distinguish truly unpublished targets from published documents that
|
|
243
|
+
// still have a draft row (those links are kept on publish for M2M, or remapped for xToOne).
|
|
244
|
+
const fields = [
|
|
245
|
+
'documentId'
|
|
246
|
+
];
|
|
247
|
+
if (isLocalizedContentType(targetModel)) {
|
|
248
|
+
fields.push('locale');
|
|
249
|
+
}
|
|
236
250
|
populateAcc[attributeName] = {
|
|
237
|
-
|
|
251
|
+
fields,
|
|
238
252
|
filters: {
|
|
239
253
|
[PUBLISHED_AT_ATTRIBUTE]: {
|
|
240
254
|
$null: true
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"populate.mjs","sources":["../../../../server/src/services/utils/populate.ts"],"sourcesContent":["import { merge, isEmpty, set, propEq } from 'lodash/fp';\nimport strapiUtils from '@strapi/utils';\nimport type { UID, Schema, Modules } from '@strapi/types';\nimport { getService } from '../../utils';\n\nconst {\n isVisibleAttribute,\n isScalarAttribute,\n getDoesAttributeRequireValidation,\n isPrivateAttribute,\n hasDraftAndPublish,\n} = strapiUtils.contentTypes;\nconst { isAnyToMany } = strapiUtils.relations;\nconst { PUBLISHED_AT_ATTRIBUTE } = strapiUtils.contentTypes.constants;\n\nconst isMorphToRelation = (attribute: any) =>\n isRelation(attribute) && attribute.relation.includes('morphTo');\nconst isMedia = propEq('type', 'media');\nconst isRelation = propEq('type', 'relation');\nconst isComponent = propEq('type', 'component');\nconst isDynamicZone = propEq('type', 'dynamiczone');\n\n// TODO: Import from @strapi/types when it's available there\ntype Model = Parameters<typeof isVisibleAttribute>[0];\nexport type Populate = Modules.EntityService.Params.Populate.Any<UID.Schema>;\n\ntype PopulateOptions = {\n initialPopulate?: Populate;\n countMany?: boolean;\n countOne?: boolean;\n maxLevel?: number;\n};\n\n/**\n * Populate the model for relation\n * @param attribute - Attribute containing a relation\n * @param attribute.relation - type of relation\n * @param model - Model of the populated entity\n * @param attributeName\n * @param options - Options to apply while populating\n */\nfunction getPopulateForRelation(\n attribute: Schema.Attribute.AnyAttribute,\n model: Model,\n attributeName: string,\n { countMany, countOne, initialPopulate }: PopulateOptions\n) {\n const isManyRelation = isAnyToMany(attribute);\n\n // Use initialPopulate when explicitly provided (including `false` to suppress population)\n if (initialPopulate !== undefined) {\n return initialPopulate;\n }\n\n // If populating localizations attribute, also include validatable fields\n // Mainly needed for bulk locale publishing, so the Client has all the information necessary to perform validations\n if (attributeName === 'localizations') {\n const validationPopulate = getPopulateForValidation(model.uid as UID.Schema);\n\n return {\n populate: validationPopulate.populate,\n };\n }\n\n // always populate createdBy, updatedBy, localizations etc.\n if (!isVisibleAttribute(model, attributeName)) {\n return true;\n }\n\n if ((isManyRelation && countMany) || (!isManyRelation && countOne)) {\n return { count: true };\n }\n\n return true;\n}\n\n/**\n * Populate the model for Dynamic Zone components\n * @param attribute - Attribute containing the components\n * @param attribute.components - IDs of components\n * @param options - Options to apply while populating\n */\nfunction getPopulateForDZ(\n attribute: Schema.Attribute.DynamicZone,\n options: PopulateOptions,\n level: number\n) {\n // Use fragments to populate the dynamic zone components\n const populatedComponents = (attribute.components || []).reduce(\n (acc: any, componentUID: UID.Component) => ({\n ...acc,\n [componentUID]: {\n populate: getDeepPopulate(componentUID, options, level + 1),\n },\n }),\n {}\n );\n\n return { on: populatedComponents };\n}\n\n/**\n * Get the populated value based on the type of the attribute\n * @param attributeName - Name of the attribute\n * @param model - Model of the populated entity\n * @param model.attributes\n * @param options - Options to apply while populating\n * @param options.countMany\n * @param options.countOne\n * @param options.maxLevel\n * @param level\n */\nfunction getPopulateFor(\n attributeName: string,\n model: any,\n options: PopulateOptions,\n level: number\n): { [key: string]: boolean | object } {\n const attribute = model.attributes[attributeName];\n\n switch (attribute.type) {\n case 'relation':\n // @ts-expect-error - TODO: support populate count typing\n return {\n [attributeName]: getPopulateForRelation(attribute, model, attributeName, options),\n };\n case 'component':\n return {\n [attributeName]: {\n populate: getDeepPopulate(attribute.component, options, level + 1),\n },\n };\n case 'media':\n return {\n [attributeName]: {\n populate: {\n folder: true,\n },\n },\n };\n case 'dynamiczone':\n return {\n [attributeName]: getPopulateForDZ(attribute, options, level),\n };\n default:\n return {};\n }\n}\n\n/**\n * Deeply populate a model based on UID\n * @param uid - Unique identifier of the model\n * @param options - Options to apply while populating\n * @param level - Current level of nested call\n */\nconst getDeepPopulate = (\n uid: UID.Schema,\n {\n initialPopulate = {} as any,\n countMany = false,\n countOne = false,\n maxLevel = Infinity,\n }: PopulateOptions = {},\n level = 1\n) => {\n if (level > maxLevel) {\n return {};\n }\n\n const model = strapi.getModel(uid);\n\n if (!model) {\n return {};\n }\n\n return Object.keys(model.attributes).reduce(\n (populateAcc, attributeName: string) =>\n merge(\n populateAcc,\n getPopulateFor(\n attributeName,\n model,\n {\n // @ts-expect-error - improve types\n initialPopulate: initialPopulate?.[attributeName],\n countMany,\n countOne,\n maxLevel,\n },\n level\n )\n ),\n {}\n );\n};\n\n/**\n * Deeply populate a model based on UID. Only populating fields that require validation.\n * @param uid - Unique identifier of the model\n * @param options - Options to apply while populating\n * @param level - Current level of nested call\n */\nconst validationPopulateCache = new Map<string, Record<string, any>>();\n\nconst getPopulateForValidation = (uid: UID.Schema): Record<string, any> => {\n const cached = validationPopulateCache.get(uid);\n if (cached) {\n return cached;\n }\n\n const model = strapi.getModel(uid);\n if (!model) {\n return {};\n }\n\n const result = Object.entries(model.attributes).reduce(\n (populateAcc: any, [attributeName, attribute]) => {\n if (isScalarAttribute(attribute)) {\n // If the scalar attribute requires validation, add it to the fields array\n if (\n getDoesAttributeRequireValidation(attribute) &&\n !isPrivateAttribute(model, attributeName)\n ) {\n populateAcc.fields = populateAcc.fields || [];\n populateAcc.fields.push(attributeName);\n }\n return populateAcc;\n }\n\n if (isMedia(attribute)) {\n if (\n getDoesAttributeRequireValidation(attribute) &&\n !isPrivateAttribute(model, attributeName)\n ) {\n populateAcc.populate = populateAcc.populate || {};\n populateAcc.populate[attributeName] = {\n populate: {\n folder: true,\n },\n };\n return populateAcc;\n }\n }\n\n if (isComponent(attribute)) {\n // @ts-expect-error - should be a component\n const component = attribute.component;\n\n // Get the validation result for this component\n const componentResult = getPopulateForValidation(component);\n\n if (Object.keys(componentResult).length > 0) {\n populateAcc.populate = populateAcc.populate || {};\n populateAcc.populate[attributeName] = componentResult;\n }\n\n return populateAcc;\n }\n\n if (isDynamicZone(attribute)) {\n const components = (attribute as Schema.Attribute.DynamicZone).components;\n // Handle dynamic zone components\n const componentsResult = (components || []).reduce(\n (acc, componentUID) => {\n // Get validation populate for this component\n const componentResult = getPopulateForValidation(componentUID);\n\n // Only include component if it has fields requiring validation\n if (Object.keys(componentResult).length > 0) {\n acc[componentUID] = componentResult;\n }\n\n return acc;\n },\n {} as Record<string, any>\n );\n\n // Only add to populate if we have components requiring validation\n if (Object.keys(componentsResult).length > 0) {\n populateAcc.populate = populateAcc.populate || {};\n populateAcc.populate[attributeName] = { on: componentsResult };\n }\n }\n\n return populateAcc;\n },\n {}\n );\n\n validationPopulateCache.set(uid, result);\n return result;\n};\n\n/**\n * getDeepPopulateDraftCount works recursively on the attributes of a model\n * creating a populated object to count all the unpublished relations within the model\n * These relations can be direct to this content type or contained within components/dynamic zones\n * @param uid of the model\n * @returns result\n * @returns result.populate\n * @returns result.hasRelations\n */\nconst draftCountPopulateCache = new Map<string, { populate: any; hasRelations: boolean }>();\n\nconst getDeepPopulateDraftCount = (uid: UID.Schema) => {\n const cached = draftCountPopulateCache.get(uid);\n if (cached) {\n return cached;\n }\n\n const model = strapi.getModel(uid);\n if (!model) {\n return { populate: {}, hasRelations: false };\n }\n let hasRelations = false;\n\n const populate = Object.keys(model.attributes).reduce((populateAcc: any, attributeName) => {\n const attribute: Schema.Attribute.AnyAttribute = model.attributes[attributeName];\n\n switch (attribute.type) {\n case 'relation': {\n // TODO: Support polymorphic relations\n const isMorphRelation = attribute.relation.toLowerCase().startsWith('morph');\n if (isMorphRelation) {\n break;\n }\n\n // Skip relations to content types without draft & publish,\n // as they don't have a publishedAt attribute and can't have drafts\n if (!('target' in attribute)) {\n break;\n }\n\n const targetModel = strapi.getModel(attribute.target);\n if (!targetModel || !hasDraftAndPublish(targetModel)) {\n break;\n }\n\n if (isVisibleAttribute(model, attributeName)) {\n populateAcc[attributeName] = {\n count: true,\n filters: { [PUBLISHED_AT_ATTRIBUTE]: { $null: true } },\n };\n hasRelations = true;\n }\n break;\n }\n case 'component': {\n const { populate, hasRelations: childHasRelations } = getDeepPopulateDraftCount(\n attribute.component\n );\n if (childHasRelations) {\n populateAcc[attributeName] = {\n populate,\n };\n hasRelations = true;\n }\n break;\n }\n case 'dynamiczone': {\n const dzPopulateFragment = attribute.components?.reduce((acc, componentUID) => {\n const { populate: componentPopulate, hasRelations: componentHasRelations } =\n getDeepPopulateDraftCount(componentUID);\n\n if (componentHasRelations) {\n hasRelations = true;\n\n return { ...acc, [componentUID]: { populate: componentPopulate } };\n }\n\n return acc;\n }, {});\n\n if (!isEmpty(dzPopulateFragment)) {\n populateAcc[attributeName] = { on: dzPopulateFragment };\n }\n break;\n }\n default:\n }\n\n return populateAcc;\n }, {});\n\n const result = { populate, hasRelations };\n draftCountPopulateCache.set(uid, result);\n return result;\n};\n\n/**\n * Create a Strapi populate object which populates all attribute fields of a Strapi query.\n */\nconst getQueryPopulate = async (uid: UID.Schema, query: object): Promise<Populate> => {\n let populateQuery: Populate = {};\n\n await strapiUtils.traverse.traverseQueryFilters(\n /**\n *\n * @param {Object} param0\n * @param {string} param0.key - Attribute name\n * @param {Object} param0.attribute - Attribute definition\n * @param {string} param0.path - Content Type path to the attribute\n * @returns\n */\n ({ attribute, path }: any) => {\n // TODO: handle dynamic zones and morph relations\n if (!attribute || isDynamicZone(attribute) || isMorphToRelation(attribute)) {\n return;\n }\n\n // Populate all relations, components and media\n if (isRelation(attribute) || isMedia(attribute) || isComponent(attribute)) {\n const populatePath = path.attribute.replace(/\\./g, '.populate.');\n // @ts-expect-error - lodash doesn't resolve the Populate type correctly\n populateQuery = set(populatePath, {}, populateQuery);\n }\n },\n { schema: strapi.getModel(uid), getModel: strapi.getModel.bind(strapi) },\n query\n );\n\n return populateQuery;\n};\n\nconst deepPopulateCache = new Map<string, object>();\n\nconst buildDeepPopulate = async (uid: UID.CollectionType) => {\n const cached = deepPopulateCache.get(uid);\n if (cached) {\n return cached;\n }\n\n const result = await getService('populate-builder')(uid)\n .populateDeep(Infinity)\n .countRelations()\n .build();\n\n deepPopulateCache.set(uid, result);\n\n return result;\n};\n\n/**\n * Restrict localizations populate to only metadata fields for localized content types.\n * Returns an empty object for non-localized content types.\n *\n * By default, localizations are deeply populated which includes all relations and\n * components for every locale — this is expensive and unnecessary for CM responses.\n * The CM only needs these fields from localizations:\n * - locale: to identify which locales exist\n * - documentId: to link to the localized document\n * - publishedAt: to determine published/draft status\n * - updatedAt: to support the modified state indicator in the UI\n */\nconst getPopulateForLocalizations = (model: UID.Schema) => {\n const modelSchema = strapi.getModel(model);\n if (\n (modelSchema as unknown as { pluginOptions: { i18n: { localized?: boolean } } }).pluginOptions\n ?.i18n?.localized\n ) {\n return { localizations: { fields: ['locale', 'documentId', 'publishedAt', 'updatedAt'] } };\n }\n\n return {};\n};\n\nexport {\n getDeepPopulate,\n getDeepPopulateDraftCount,\n getPopulateForValidation,\n getQueryPopulate,\n buildDeepPopulate,\n getPopulateForLocalizations,\n};\n"],"names":["isVisibleAttribute","isScalarAttribute","getDoesAttributeRequireValidation","isPrivateAttribute","hasDraftAndPublish","strapiUtils","contentTypes","isAnyToMany","relations","PUBLISHED_AT_ATTRIBUTE","constants","isMorphToRelation","attribute","isRelation","relation","includes","isMedia","propEq","isComponent","isDynamicZone","getPopulateForRelation","model","attributeName","countMany","countOne","initialPopulate","isManyRelation","undefined","validationPopulate","getPopulateForValidation","uid","populate","count","getPopulateForDZ","options","level","populatedComponents","components","reduce","acc","componentUID","getDeepPopulate","on","getPopulateFor","attributes","type","component","folder","maxLevel","Infinity","strapi","getModel","Object","keys","populateAcc","merge","validationPopulateCache","Map","cached","get","result","entries","fields","push","componentResult","length","componentsResult","set","draftCountPopulateCache","getDeepPopulateDraftCount","hasRelations","isMorphRelation","toLowerCase","startsWith","targetModel","target","filters","$null","childHasRelations","dzPopulateFragment","componentPopulate","componentHasRelations","isEmpty","getQueryPopulate","query","populateQuery","traverse","traverseQueryFilters","path","populatePath","replace","schema","bind","deepPopulateCache","buildDeepPopulate","getService","populateDeep","countRelations","build","getPopulateForLocalizations","modelSchema","pluginOptions","i18n","localized","localizations"],"mappings":";;;;AAKA,MAAM,EACJA,kBAAkB,EAClBC,iBAAiB,EACjBC,iCAAiC,EACjCC,kBAAkB,EAClBC,kBAAkB,EACnB,GAAGC,YAAYC,YAAY;AAC5B,MAAM,EAAEC,WAAW,EAAE,GAAGF,YAAYG,SAAS;AAC7C,MAAM,EAAEC,sBAAsB,EAAE,GAAGJ,WAAAA,CAAYC,YAAY,CAACI,SAAS;AAErE,MAAMC,iBAAAA,GAAoB,CAACC,SAAAA,GACzBC,UAAAA,CAAWD,cAAcA,SAAAA,CAAUE,QAAQ,CAACC,QAAQ,CAAC,SAAA,CAAA;AACvD,MAAMC,OAAAA,GAAUC,OAAO,MAAA,EAAQ,OAAA,CAAA;AAC/B,MAAMJ,UAAAA,GAAaI,OAAO,MAAA,EAAQ,UAAA,CAAA;AAClC,MAAMC,WAAAA,GAAcD,OAAO,MAAA,EAAQ,WAAA,CAAA;AACnC,MAAME,aAAAA,GAAgBF,OAAO,MAAA,EAAQ,aAAA,CAAA;AAarC;;;;;;;AAOC,IACD,SAASG,sBAAAA,CACPR,SAAwC,EACxCS,KAAY,EACZC,aAAqB,EACrB,EAAEC,SAAS,EAAEC,QAAQ,EAAEC,eAAe,EAAmB,EAAA;AAEzD,IAAA,MAAMC,iBAAiBnB,WAAAA,CAAYK,SAAAA,CAAAA;;AAGnC,IAAA,IAAIa,oBAAoBE,SAAAA,EAAW;QACjC,OAAOF,eAAAA;AACT,IAAA;;;AAIA,IAAA,IAAIH,kBAAkB,eAAA,EAAiB;QACrC,MAAMM,kBAAAA,GAAqBC,wBAAAA,CAAyBR,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,CAAAA;IAGF,OAAOC,aAAAA;AACT;AAEA,MAAMQ,oBAAoB,IAAIpC,GAAAA,EAAAA;AAE9B,MAAMqC,oBAAoB,OAAOhE,GAAAA,GAAAA;IAC/B,MAAM4B,MAAAA,GAASmC,iBAAAA,CAAkBlC,GAAG,CAAC7B,GAAAA,CAAAA;AACrC,IAAA,IAAI4B,MAAAA,EAAQ;QACV,OAAOA,MAAAA;AACT,IAAA;IAEA,MAAME,MAAAA,GAAS,MAAMmC,UAAAA,CAAW,kBAAA,CAAA,CAAoBjE,GAAAA,CAAAA,CACjDkE,YAAY,CAAC/C,QAAAA,CAAAA,CACbgD,cAAc,EAAA,CACdC,KAAK,EAAA;IAERL,iBAAAA,CAAkB1B,GAAG,CAACrC,GAAAA,EAAK8B,MAAAA,CAAAA;IAE3B,OAAOA,MAAAA;AACT;AAEA;;;;;;;;;;;IAYA,MAAMuC,8BAA8B,CAAC9E,KAAAA,GAAAA;IACnC,MAAM+E,WAAAA,GAAclD,MAAAA,CAAOC,QAAQ,CAAC9B,KAAAA,CAAAA;AACpC,IAAA,IACE,WAAC+E,CAAgFC,aAAa,EAC1FC,MAAMC,SAAAA,EACV;QACA,OAAO;YAAEC,aAAAA,EAAe;gBAAE1C,MAAAA,EAAQ;AAAC,oBAAA,QAAA;AAAU,oBAAA,YAAA;AAAc,oBAAA,aAAA;AAAe,oBAAA;AAAY;AAAC;AAAE,SAAA;AAC3F,IAAA;AAEA,IAAA,OAAO,EAAC;AACV;;;;"}
|
|
1
|
+
{"version":3,"file":"populate.mjs","sources":["../../../../server/src/services/utils/populate.ts"],"sourcesContent":["import { merge, isEmpty, set, propEq } from 'lodash/fp';\nimport strapiUtils from '@strapi/utils';\nimport type { UID, Schema, Modules } from '@strapi/types';\nimport { getService } from '../../utils';\n\nconst {\n isVisibleAttribute,\n isScalarAttribute,\n getDoesAttributeRequireValidation,\n isPrivateAttribute,\n hasDraftAndPublish,\n} = strapiUtils.contentTypes;\nconst { isAnyToMany } = strapiUtils.relations;\nconst { PUBLISHED_AT_ATTRIBUTE } = strapiUtils.contentTypes.constants;\n\nconst isLocalizedContentType = (model: { pluginOptions?: unknown }) =>\n (model.pluginOptions as { i18n?: { localized?: boolean } } | undefined)?.i18n?.localized === true;\n\nconst isMorphToRelation = (attribute: any) =>\n isRelation(attribute) && attribute.relation.includes('morphTo');\nconst isMedia = propEq('type', 'media');\nconst isRelation = propEq('type', 'relation');\nconst isComponent = propEq('type', 'component');\nconst isDynamicZone = propEq('type', 'dynamiczone');\n\n// TODO: Import from @strapi/types when it's available there\ntype Model = Parameters<typeof isVisibleAttribute>[0];\nexport type Populate = Modules.EntityService.Params.Populate.Any<UID.Schema>;\n\ntype PopulateOptions = {\n initialPopulate?: Populate;\n countMany?: boolean;\n countOne?: boolean;\n maxLevel?: number;\n};\n\n/**\n * Populate the model for relation\n * @param attribute - Attribute containing a relation\n * @param attribute.relation - type of relation\n * @param model - Model of the populated entity\n * @param attributeName\n * @param options - Options to apply while populating\n */\nfunction getPopulateForRelation(\n attribute: Schema.Attribute.AnyAttribute,\n model: Model,\n attributeName: string,\n { countMany, countOne, initialPopulate }: PopulateOptions\n) {\n const isManyRelation = isAnyToMany(attribute);\n\n // Use initialPopulate when explicitly provided (including `false` to suppress population)\n if (initialPopulate !== undefined) {\n return initialPopulate;\n }\n\n // If populating localizations attribute, also include validatable fields\n // Mainly needed for bulk locale publishing, so the Client has all the information necessary to perform validations\n if (attributeName === 'localizations') {\n const validationPopulate = getPopulateForValidation(model.uid as UID.Schema);\n\n return {\n populate: validationPopulate.populate,\n };\n }\n\n // always populate createdBy, updatedBy, localizations etc.\n if (!isVisibleAttribute(model, attributeName)) {\n return true;\n }\n\n if ((isManyRelation && countMany) || (!isManyRelation && countOne)) {\n return { count: true };\n }\n\n return true;\n}\n\n/**\n * Populate the model for Dynamic Zone components\n * @param attribute - Attribute containing the components\n * @param attribute.components - IDs of components\n * @param options - Options to apply while populating\n */\nfunction getPopulateForDZ(\n attribute: Schema.Attribute.DynamicZone,\n options: PopulateOptions,\n level: number\n): { on: { [key: string]: { populate: { [key: string]: boolean | object } } } } {\n // Use fragments to populate the dynamic zone components\n const populatedComponents = (attribute.components || []).reduce(\n (acc: any, componentUID: UID.Component) => ({\n ...acc,\n [componentUID]: {\n populate: getDeepPopulate(componentUID, options, level + 1),\n },\n }),\n {}\n );\n\n return { on: populatedComponents };\n}\n\n/**\n * Get the populated value based on the type of the attribute\n * @param attributeName - Name of the attribute\n * @param model - Model of the populated entity\n * @param model.attributes\n * @param options - Options to apply while populating\n * @param options.countMany\n * @param options.countOne\n * @param options.maxLevel\n * @param level\n */\nfunction getPopulateFor(\n attributeName: string,\n model: any,\n options: PopulateOptions,\n level: number\n): { [key: string]: boolean | object } {\n const attribute = model.attributes[attributeName];\n\n switch (attribute.type) {\n case 'relation':\n // @ts-expect-error - TODO: support populate count typing\n return {\n [attributeName]: getPopulateForRelation(attribute, model, attributeName, options),\n };\n case 'component':\n return {\n [attributeName]: {\n populate: getDeepPopulate(attribute.component, options, level + 1),\n },\n };\n case 'media':\n return {\n [attributeName]: {\n populate: {\n folder: true,\n },\n },\n };\n case 'dynamiczone':\n return {\n [attributeName]: getPopulateForDZ(attribute, options, level),\n };\n default:\n return {};\n }\n}\n\n/**\n * Deeply populate a model based on UID\n * @param uid - Unique identifier of the model\n * @param options - Options to apply while populating\n * @param level - Current level of nested call\n */\nconst getDeepPopulate = (\n uid: UID.Schema,\n {\n initialPopulate = {} as any,\n countMany = false,\n countOne = false,\n maxLevel = Infinity,\n }: PopulateOptions = {},\n level = 1\n): { [key: string]: boolean | object } => {\n if (level > maxLevel) {\n return {};\n }\n\n const model = strapi.getModel(uid);\n\n if (!model) {\n return {};\n }\n\n return Object.keys(model.attributes).reduce(\n (populateAcc, attributeName: string) =>\n merge(\n populateAcc,\n getPopulateFor(\n attributeName,\n model,\n {\n // @ts-expect-error - improve types\n initialPopulate: initialPopulate?.[attributeName],\n countMany,\n countOne,\n maxLevel,\n },\n level\n )\n ),\n {}\n );\n};\n\n/**\n * Deeply populate a model based on UID. Only populating fields that require validation.\n * @param uid - Unique identifier of the model\n * @param options - Options to apply while populating\n * @param level - Current level of nested call\n */\nconst validationPopulateCache = new Map<string, Record<string, any>>();\n\nconst getPopulateForValidation = (uid: UID.Schema): Record<string, any> => {\n const cached = validationPopulateCache.get(uid);\n if (cached) {\n return cached;\n }\n\n const model = strapi.getModel(uid);\n if (!model) {\n return {};\n }\n\n const result = Object.entries(model.attributes).reduce(\n (populateAcc: any, [attributeName, attribute]) => {\n if (isScalarAttribute(attribute)) {\n // If the scalar attribute requires validation, add it to the fields array\n if (\n getDoesAttributeRequireValidation(attribute) &&\n !isPrivateAttribute(model, attributeName)\n ) {\n populateAcc.fields = populateAcc.fields || [];\n populateAcc.fields.push(attributeName);\n }\n return populateAcc;\n }\n\n if (isMedia(attribute)) {\n if (\n getDoesAttributeRequireValidation(attribute) &&\n !isPrivateAttribute(model, attributeName)\n ) {\n populateAcc.populate = populateAcc.populate || {};\n populateAcc.populate[attributeName] = {\n populate: {\n folder: true,\n },\n };\n return populateAcc;\n }\n }\n\n if (isComponent(attribute)) {\n // @ts-expect-error - should be a component\n const component = attribute.component;\n\n // Get the validation result for this component\n const componentResult = getPopulateForValidation(component);\n\n if (Object.keys(componentResult).length > 0) {\n populateAcc.populate = populateAcc.populate || {};\n populateAcc.populate[attributeName] = componentResult;\n }\n\n return populateAcc;\n }\n\n if (isDynamicZone(attribute)) {\n const components = (attribute as Schema.Attribute.DynamicZone).components;\n // Handle dynamic zone components\n const componentsResult = (components || []).reduce(\n (acc, componentUID) => {\n // Get validation populate for this component\n const componentResult = getPopulateForValidation(componentUID);\n\n // Only include component if it has fields requiring validation\n if (Object.keys(componentResult).length > 0) {\n acc[componentUID] = componentResult;\n }\n\n return acc;\n },\n {} as Record<string, any>\n );\n\n // Only add to populate if we have components requiring validation\n if (Object.keys(componentsResult).length > 0) {\n populateAcc.populate = populateAcc.populate || {};\n populateAcc.populate[attributeName] = { on: componentsResult };\n }\n }\n\n return populateAcc;\n },\n {}\n );\n\n validationPopulateCache.set(uid, result);\n return result;\n};\n\n/**\n * getDeepPopulateDraftCount works recursively on the attributes of a model\n * creating a populated object to count all the unpublished relations within the model\n * These relations can be direct to this content type or contained within components/dynamic zones\n * @param uid of the model\n * @returns result\n * @returns result.populate\n * @returns result.hasRelations\n */\nconst draftCountPopulateCache = new Map<string, { populate: any; hasRelations: boolean }>();\n\nconst getDeepPopulateDraftCount = (uid: UID.Schema): { populate: any; hasRelations: boolean } => {\n const cached = draftCountPopulateCache.get(uid);\n if (cached) {\n return cached;\n }\n\n const model = strapi.getModel(uid);\n if (!model) {\n return { populate: {}, hasRelations: false };\n }\n let hasRelations = false;\n\n const populate = Object.keys(model.attributes).reduce((populateAcc: any, attributeName) => {\n const attribute: Schema.Attribute.AnyAttribute = model.attributes[attributeName];\n\n switch (attribute.type) {\n case 'relation': {\n // TODO: Support polymorphic relations\n const isMorphRelation = attribute.relation.toLowerCase().startsWith('morph');\n if (isMorphRelation) {\n break;\n }\n\n // Skip relations to content types without draft & publish,\n // as they don't have a publishedAt attribute and can't have drafts\n if (!('target' in attribute)) {\n break;\n }\n\n const targetModel = strapi.getModel(attribute.target);\n if (!targetModel || !hasDraftAndPublish(targetModel)) {\n break;\n }\n\n // Self-referential relations are preserved on publish (see self-referential-relations.ts).\n if (attribute.target === uid) {\n break;\n }\n\n if (isVisibleAttribute(model, attributeName)) {\n // Draft entries link to draft rows of related documents. Populate documentId/locale\n // so we can distinguish truly unpublished targets from published documents that\n // still have a draft row (those links are kept on publish for M2M, or remapped for xToOne).\n const fields: string[] = ['documentId'];\n if (isLocalizedContentType(targetModel)) {\n fields.push('locale');\n }\n populateAcc[attributeName] = {\n fields,\n filters: { [PUBLISHED_AT_ATTRIBUTE]: { $null: true } },\n };\n hasRelations = true;\n }\n break;\n }\n case 'component': {\n const { populate, hasRelations: childHasRelations } = getDeepPopulateDraftCount(\n attribute.component\n );\n if (childHasRelations) {\n populateAcc[attributeName] = {\n populate,\n };\n hasRelations = true;\n }\n break;\n }\n case 'dynamiczone': {\n const dzPopulateFragment = attribute.components?.reduce((acc, componentUID) => {\n const { populate: componentPopulate, hasRelations: componentHasRelations } =\n getDeepPopulateDraftCount(componentUID);\n\n if (componentHasRelations) {\n hasRelations = true;\n\n return { ...acc, [componentUID]: { populate: componentPopulate } };\n }\n\n return acc;\n }, {});\n\n if (!isEmpty(dzPopulateFragment)) {\n populateAcc[attributeName] = { on: dzPopulateFragment };\n }\n break;\n }\n default:\n }\n\n return populateAcc;\n }, {});\n\n const result = { populate, hasRelations };\n draftCountPopulateCache.set(uid, result);\n return result;\n};\n\n/**\n * Create a Strapi populate object which populates all attribute fields of a Strapi query.\n */\nconst getQueryPopulate = async (uid: UID.Schema, query: object): Promise<Populate> => {\n let populateQuery: Populate = {};\n\n await strapiUtils.traverse.traverseQueryFilters(\n /**\n *\n * @param {Object} param0\n * @param {string} param0.key - Attribute name\n * @param {Object} param0.attribute - Attribute definition\n * @param {string} param0.path - Content Type path to the attribute\n * @returns\n */\n ({ attribute, path }: any) => {\n // TODO: handle dynamic zones and morph relations\n if (!attribute || isDynamicZone(attribute) || isMorphToRelation(attribute)) {\n return;\n }\n\n // Populate all relations, components and media\n if (isRelation(attribute) || isMedia(attribute) || isComponent(attribute)) {\n const populatePath = path.attribute.replace(/\\./g, '.populate.');\n // @ts-expect-error - lodash doesn't resolve the Populate type correctly\n populateQuery = set(populatePath, {}, populateQuery);\n }\n },\n { schema: strapi.getModel(uid), getModel: strapi.getModel.bind(strapi) },\n query\n );\n\n return populateQuery;\n};\n\nconst deepPopulateCache = new Map<string, object>();\n\nconst buildDeepPopulate = async (uid: UID.CollectionType) => {\n const cached = deepPopulateCache.get(uid);\n if (cached) {\n return cached;\n }\n\n const result = await getService('populate-builder')(uid)\n .populateDeep(Infinity)\n .countRelations()\n .build();\n\n deepPopulateCache.set(uid, result);\n\n return result;\n};\n\n/**\n * Restrict localizations populate to only metadata fields for localized content types.\n * Returns an empty object for non-localized content types.\n *\n * By default, localizations are deeply populated which includes all relations and\n * components for every locale — this is expensive and unnecessary for CM responses.\n * The CM only needs these fields from localizations:\n * - locale: to identify which locales exist\n * - documentId: to link to the localized document\n * - publishedAt: to determine published/draft status\n * - updatedAt: to support the modified state indicator in the UI\n */\nconst getPopulateForLocalizations = (model: UID.Schema) => {\n const modelSchema = strapi.getModel(model);\n if (\n (modelSchema as unknown as { pluginOptions: { i18n: { localized?: boolean } } }).pluginOptions\n ?.i18n?.localized\n ) {\n return { localizations: { fields: ['locale', 'documentId', 'publishedAt', 'updatedAt'] } };\n }\n\n return {};\n};\n\nexport {\n getDeepPopulate,\n getDeepPopulateDraftCount,\n getPopulateForValidation,\n getQueryPopulate,\n buildDeepPopulate,\n getPopulateForLocalizations,\n};\n"],"names":["isVisibleAttribute","isScalarAttribute","getDoesAttributeRequireValidation","isPrivateAttribute","hasDraftAndPublish","strapiUtils","contentTypes","isAnyToMany","relations","PUBLISHED_AT_ATTRIBUTE","constants","isLocalizedContentType","model","pluginOptions","i18n","localized","isMorphToRelation","attribute","isRelation","relation","includes","isMedia","propEq","isComponent","isDynamicZone","getPopulateForRelation","attributeName","countMany","countOne","initialPopulate","isManyRelation","undefined","validationPopulate","getPopulateForValidation","uid","populate","count","getPopulateForDZ","options","level","populatedComponents","components","reduce","acc","componentUID","getDeepPopulate","on","getPopulateFor","attributes","type","component","folder","maxLevel","Infinity","strapi","getModel","Object","keys","populateAcc","merge","validationPopulateCache","Map","cached","get","result","entries","fields","push","componentResult","length","componentsResult","set","draftCountPopulateCache","getDeepPopulateDraftCount","hasRelations","isMorphRelation","toLowerCase","startsWith","targetModel","target","filters","$null","childHasRelations","dzPopulateFragment","componentPopulate","componentHasRelations","isEmpty","getQueryPopulate","query","populateQuery","traverse","traverseQueryFilters","path","populatePath","replace","schema","bind","deepPopulateCache","buildDeepPopulate","getService","populateDeep","countRelations","build","getPopulateForLocalizations","modelSchema","localizations"],"mappings":";;;;A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AA,CAAAA;AAAMqB,QAAAA,QAAAA,EAAUD,MAAAA,CAAOC,QAAQ,CAACyC,IAAI,CAAC1C,MAAAA;KAAQ,EACvEkC,KAAAA,CAAAA;IAGF,OAAOC,aAAAA;AACT;AAEA,MAAMQ,oBAAoB,IAAIpC,GAAAA,EAAAA;AAE9B,MAAMqC,oBAAoB,OAAOhE,GAAAA,GAAAA;IAC/B,MAAM4B,MAAAA,GAASmC,iBAAAA,CAAkBlC,GAAG,CAAC7B,GAAAA,CAAAA;AACrC,IAAA,IAAI4B,MAAAA,EAAQ;QACV,OAAOA,MAAAA;AACT,IAAA;IAEA,MAAME,MAAAA,GAAS,MAAMmC,UAAAA,CAAW,kBAAA,CAAA,CAAoBjE,GAAAA,CAAAA,CACjDkE,YAAY,CAAC/C,QAAAA,CAAAA,CACbgD,cAAc,EAAA,CACdC,KAAK,EAAA;IAERL,iBAAAA,CAAkB1B,GAAG,CAACrC,GAAAA,EAAK8B,MAAAA,CAAAA;IAE3B,OAAOA,MAAAA;AACT;AAEA;;;;;;;;;;;IAYA,MAAMuC,8BAA8B,CAAC3F,KAAAA,GAAAA;IACnC,MAAM4F,WAAAA,GAAclD,MAAAA,CAAOC,QAAQ,CAAC3C,KAAAA,CAAAA;AACpC,IAAA,IACE,WAAC4F,CAAgF3F,aAAa,EAC1FC,MAAMC,SAAAA,EACV;QACA,OAAO;YAAE0F,aAAAA,EAAe;gBAAEvC,MAAAA,EAAQ;AAAC,oBAAA,QAAA;AAAU,oBAAA,YAAA;AAAc,oBAAA,aAAA;AAAe,oBAAA;AAAY;AAAC;AAAE,SAAA;AAC3F,IAAA;AAEA,IAAA,OAAO,EAAC;AACV;;;;"}
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
var _ = require('lodash');
|
|
4
4
|
|
|
5
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
6
|
+
|
|
7
|
+
var ___default = /*#__PURE__*/_interopDefault(_);
|
|
8
|
+
|
|
5
9
|
const keys = {
|
|
6
10
|
CONFIGURATION: 'configuration'
|
|
7
11
|
};
|
|
@@ -23,7 +27,7 @@ const getModelConfiguration = async (key)=>{
|
|
|
23
27
|
const config = await getStore().get({
|
|
24
28
|
key: configurationKey(key)
|
|
25
29
|
});
|
|
26
|
-
return
|
|
30
|
+
return ___default.default.merge({}, EMPTY_CONFIG, config);
|
|
27
31
|
};
|
|
28
32
|
/**
|
|
29
33
|
* Batch load multiple model configurations in a single query.
|
|
@@ -47,7 +51,7 @@ const getModelConfiguration = async (key)=>{
|
|
|
47
51
|
const originalKey = result.key.replace(`${STORE_KEY_PREFIX}configuration_`, '');
|
|
48
52
|
try {
|
|
49
53
|
const value = typeof result.value === 'string' ? JSON.parse(result.value) : result.value;
|
|
50
|
-
configMap[originalKey] =
|
|
54
|
+
configMap[originalKey] = ___default.default.merge({}, EMPTY_CONFIG, value);
|
|
51
55
|
} catch {
|
|
52
56
|
strapi.log.warn(`Malformed JSON in core-store key "${result.key}", using default config`);
|
|
53
57
|
}
|
|
@@ -55,7 +59,7 @@ const getModelConfiguration = async (key)=>{
|
|
|
55
59
|
// Default missing keys to empty config
|
|
56
60
|
for (const key of keys){
|
|
57
61
|
if (!configMap[key]) {
|
|
58
|
-
configMap[key] =
|
|
62
|
+
configMap[key] = ___default.default.merge({}, EMPTY_CONFIG);
|
|
59
63
|
}
|
|
60
64
|
}
|
|
61
65
|
return configMap;
|
|
@@ -69,10 +73,10 @@ const setModelConfiguration = async (key, value)=>{
|
|
|
69
73
|
};
|
|
70
74
|
Object.keys(value).forEach((key)=>{
|
|
71
75
|
if (value[key] !== null && value[key] !== undefined) {
|
|
72
|
-
|
|
76
|
+
___default.default.set(currentConfig, key, value[key]);
|
|
73
77
|
}
|
|
74
78
|
});
|
|
75
|
-
if (!
|
|
79
|
+
if (!___default.default.isEqual(currentConfig, storedConfig)) {
|
|
76
80
|
return getStore().set({
|
|
77
81
|
key: configurationKey(key),
|
|
78
82
|
value: currentConfig
|