@strapi/content-manager 5.57.0 → 5.59.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/ConfigurationForm/Fields.js +4 -3
- package/dist/admin/components/ConfigurationForm/Fields.js.map +1 -1
- package/dist/admin/components/ConfigurationForm/Fields.mjs +4 -3
- package/dist/admin/components/ConfigurationForm/Fields.mjs.map +1 -1
- package/dist/admin/components/RelativeTime.js +2 -1
- package/dist/admin/components/RelativeTime.js.map +1 -1
- package/dist/admin/components/RelativeTime.mjs +2 -1
- package/dist/admin/components/RelativeTime.mjs.map +1 -1
- package/dist/admin/content-manager.js.map +1 -1
- package/dist/admin/content-manager.mjs.map +1 -1
- package/dist/admin/history/components/VersionContent.js +8 -8
- package/dist/admin/history/components/VersionContent.js.map +1 -1
- package/dist/admin/history/components/VersionContent.mjs +8 -8
- package/dist/admin/history/components/VersionContent.mjs.map +1 -1
- package/dist/admin/hooks/useDocumentActions.js.map +1 -1
- package/dist/admin/hooks/useDocumentActions.mjs.map +1 -1
- package/dist/admin/hooks/useDocumentLayout.js.map +1 -1
- package/dist/admin/hooks/useDocumentLayout.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksEditor.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksEditor.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Component/Input.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Component/Input.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Component/NonRepeatable.js +2 -2
- package/dist/admin/pages/EditView/components/FormInputs/Component/NonRepeatable.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Component/NonRepeatable.mjs +2 -2
- package/dist/admin/pages/EditView/components/FormInputs/Component/NonRepeatable.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Component/Repeatable.js +7 -6
- package/dist/admin/pages/EditView/components/FormInputs/Component/Repeatable.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Component/Repeatable.mjs +7 -6
- package/dist/admin/pages/EditView/components/FormInputs/Component/Repeatable.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/ComponentCategory.js +2 -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/ComponentPicker.js +2 -1
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/ComponentPicker.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/ComponentPicker.mjs +2 -1
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/ComponentPicker.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/DynamicComponent.js +4 -3
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/DynamicComponent.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/DynamicComponent.mjs +4 -3
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/DynamicComponent.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/Field.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/Field.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Relations/Relations.js +31 -11
- package/dist/admin/pages/EditView/components/FormInputs/Relations/Relations.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Relations/Relations.mjs +32 -12
- package/dist/admin/pages/EditView/components/FormInputs/Relations/Relations.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/UID.js +2 -1
- package/dist/admin/pages/EditView/components/FormInputs/UID.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/UID.mjs +2 -1
- package/dist/admin/pages/EditView/components/FormInputs/UID.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Wysiwyg/Editor.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Wysiwyg/Editor.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormLayout.js +4 -4
- package/dist/admin/pages/EditView/components/FormLayout.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormLayout.mjs +4 -4
- package/dist/admin/pages/EditView/components/FormLayout.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/Panels.js.map +1 -1
- package/dist/admin/pages/EditView/components/Panels.mjs.map +1 -1
- package/dist/admin/pages/EditView/utils/data.js +3 -3
- package/dist/admin/pages/EditView/utils/data.js.map +1 -1
- package/dist/admin/pages/EditView/utils/data.mjs +3 -3
- package/dist/admin/pages/EditView/utils/data.mjs.map +1 -1
- package/dist/admin/pages/ListConfiguration/components/Settings.js +3 -3
- package/dist/admin/pages/ListConfiguration/components/Settings.js.map +1 -1
- package/dist/admin/pages/ListConfiguration/components/Settings.mjs +3 -3
- package/dist/admin/pages/ListConfiguration/components/Settings.mjs.map +1 -1
- package/dist/admin/pages/ListConfiguration/components/SortDisplayedFields.js +2 -2
- package/dist/admin/pages/ListConfiguration/components/SortDisplayedFields.js.map +1 -1
- package/dist/admin/pages/ListConfiguration/components/SortDisplayedFields.mjs +2 -2
- package/dist/admin/pages/ListConfiguration/components/SortDisplayedFields.mjs.map +1 -1
- package/dist/admin/pages/ListView/ListViewPage.js +73 -13
- package/dist/admin/pages/ListView/ListViewPage.js.map +1 -1
- package/dist/admin/pages/ListView/ListViewPage.mjs +74 -14
- package/dist/admin/pages/ListView/ListViewPage.mjs.map +1 -1
- package/dist/admin/pages/ListView/components/AutoCloneFailureModal.js +1 -1
- package/dist/admin/pages/ListView/components/AutoCloneFailureModal.js.map +1 -1
- package/dist/admin/pages/ListView/components/AutoCloneFailureModal.mjs +1 -1
- package/dist/admin/pages/ListView/components/AutoCloneFailureModal.mjs.map +1 -1
- package/dist/admin/pages/ListView/components/BulkActions/ConfirmBulkActionDialog.js.map +1 -1
- package/dist/admin/pages/ListView/components/BulkActions/ConfirmBulkActionDialog.mjs.map +1 -1
- package/dist/admin/pages/ListView/components/BulkActions/PublishAction.js +4 -1
- package/dist/admin/pages/ListView/components/BulkActions/PublishAction.js.map +1 -1
- package/dist/admin/pages/ListView/components/BulkActions/PublishAction.mjs +4 -1
- package/dist/admin/pages/ListView/components/BulkActions/PublishAction.mjs.map +1 -1
- package/dist/admin/pages/ListView/components/Filters.js +12 -10
- package/dist/admin/pages/ListView/components/Filters.js.map +1 -1
- package/dist/admin/pages/ListView/components/Filters.mjs +12 -10
- package/dist/admin/pages/ListView/components/Filters.mjs.map +1 -1
- package/dist/admin/pages/ListView/components/TableCells/Relations.js.map +1 -1
- package/dist/admin/pages/ListView/components/TableCells/Relations.mjs.map +1 -1
- package/dist/admin/pages/ListView/components/ViewSettingsMenu.js +2 -1
- package/dist/admin/pages/ListView/components/ViewSettingsMenu.js.map +1 -1
- package/dist/admin/pages/ListView/components/ViewSettingsMenu.mjs +2 -1
- package/dist/admin/pages/ListView/components/ViewSettingsMenu.mjs.map +1 -1
- package/dist/admin/pages/ListView/utils/applyAttributeRenames.js +68 -0
- package/dist/admin/pages/ListView/utils/applyAttributeRenames.js.map +1 -0
- package/dist/admin/pages/ListView/utils/applyAttributeRenames.mjs +64 -0
- package/dist/admin/pages/ListView/utils/applyAttributeRenames.mjs.map +1 -0
- package/dist/admin/preview/components/PreviewHeader.js +3 -1
- package/dist/admin/preview/components/PreviewHeader.js.map +1 -1
- package/dist/admin/preview/components/PreviewHeader.mjs +3 -1
- package/dist/admin/preview/components/PreviewHeader.mjs.map +1 -1
- package/dist/admin/services/relations.js +5 -2
- package/dist/admin/services/relations.js.map +1 -1
- package/dist/admin/services/relations.mjs +5 -2
- package/dist/admin/services/relations.mjs.map +1 -1
- package/dist/admin/src/components/ConfigurationForm/Fields.d.ts +1 -1
- package/dist/admin/src/pages/ListView/utils/applyAttributeRenames.d.ts +12 -0
- package/dist/admin/translations/eu.json.js +3 -3
- package/dist/admin/translations/eu.json.mjs +3 -3
- package/dist/admin/translations/gu.json.js +4 -4
- package/dist/admin/translations/gu.json.mjs +4 -4
- package/dist/admin/translations/hi.json.js +9 -9
- package/dist/admin/translations/hi.json.mjs +9 -9
- package/dist/admin/translations/ml.json.js +6 -6
- package/dist/admin/translations/ml.json.mjs +6 -6
- package/dist/admin/translations/sa.json.js +10 -10
- package/dist/admin/translations/sa.json.mjs +10 -10
- package/dist/server/history/entitlements.js +26 -0
- package/dist/server/history/entitlements.js.map +1 -0
- package/dist/server/history/entitlements.mjs +24 -0
- package/dist/server/history/entitlements.mjs.map +1 -0
- package/dist/server/history/index.js +3 -0
- package/dist/server/history/index.js.map +1 -1
- package/dist/server/history/index.mjs +3 -0
- package/dist/server/history/index.mjs.map +1 -1
- package/dist/server/history/services/utils.js +19 -8
- package/dist/server/history/services/utils.js.map +1 -1
- package/dist/server/history/services/utils.mjs +18 -9
- package/dist/server/history/services/utils.mjs.map +1 -1
- package/dist/server/homepage/services/homepage.js.map +1 -1
- package/dist/server/homepage/services/homepage.mjs.map +1 -1
- package/dist/server/preview/services/preview-config.js.map +1 -1
- package/dist/server/preview/services/preview-config.mjs.map +1 -1
- package/dist/server/register.js +6 -0
- package/dist/server/register.js.map +1 -1
- package/dist/server/register.mjs +6 -0
- package/dist/server/register.mjs.map +1 -1
- package/dist/server/services/components.js.map +1 -1
- package/dist/server/services/components.mjs.map +1 -1
- package/dist/server/services/configuration/rename-fields.js +68 -0
- package/dist/server/services/configuration/rename-fields.js.map +1 -0
- package/dist/server/services/configuration/rename-fields.mjs +66 -0
- package/dist/server/services/configuration/rename-fields.mjs.map +1 -0
- package/dist/server/services/utils/configuration/attribute-renames.js +164 -0
- package/dist/server/services/utils/configuration/attribute-renames.js.map +1 -0
- package/dist/server/services/utils/configuration/attribute-renames.mjs +161 -0
- package/dist/server/services/utils/configuration/attribute-renames.mjs.map +1 -0
- package/dist/server/services/utils/configuration/attributes.js +12 -12
- package/dist/server/services/utils/configuration/attributes.js.map +1 -1
- package/dist/server/services/utils/configuration/attributes.mjs +12 -12
- package/dist/server/services/utils/configuration/attributes.mjs.map +1 -1
- package/dist/server/src/history/entitlements.d.ts +9 -0
- package/dist/server/src/history/entitlements.d.ts.map +1 -0
- package/dist/server/src/history/index.d.ts.map +1 -1
- package/dist/server/src/history/services/utils.d.ts +6 -0
- package/dist/server/src/history/services/utils.d.ts.map +1 -1
- package/dist/server/src/homepage/services/homepage.d.ts.map +1 -1
- package/dist/server/src/index.d.ts +2 -0
- package/dist/server/src/index.d.ts.map +1 -1
- package/dist/server/src/preview/services/index.d.ts.map +1 -1
- package/dist/server/src/preview/services/preview-config.d.ts.map +1 -1
- package/dist/server/src/register.d.ts.map +1 -1
- package/dist/server/src/services/components.d.ts +2 -0
- package/dist/server/src/services/components.d.ts.map +1 -1
- package/dist/server/src/services/configuration/rename-fields.d.ts +15 -0
- package/dist/server/src/services/configuration/rename-fields.d.ts.map +1 -0
- package/dist/server/src/services/index.d.ts +2 -0
- package/dist/server/src/services/index.d.ts.map +1 -1
- package/dist/server/src/services/utils/configuration/attribute-renames.d.ts +57 -0
- package/dist/server/src/services/utils/configuration/attribute-renames.d.ts.map +1 -0
- package/dist/shared/contracts/content-types.d.ts +5 -0
- package/dist/shared/contracts/content-types.d.ts.map +1 -1
- package/dist/shared/contracts/relations.d.ts +1 -0
- package/dist/shared/contracts/relations.d.ts.map +1 -1
- package/package.json +7 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"homepage.mjs","sources":["../../../../server/src/homepage/services/homepage.ts"],"sourcesContent":["/* eslint-disable func-names */\nimport type { Core, Modules, Schema } from '@strapi/types';\nimport { contentTypes } from '@strapi/utils';\n\nimport type {\n GetCountDocuments,\n GetRecentDocuments,\n RecentDocument,\n} from '../../../../shared/contracts/homepage';\n\nimport {\n buildHomepageQueryFields,\n compactSanitizedFields,\n resolveReadableMainField,\n resolveTitleField,\n} from './homepage-query-utils';\n\nconst createHomepageService = ({ strapi }: { strapi: Core.Strapi }) => {\n const MAX_DOCUMENTS = 4;\n\n const metadataService = strapi.plugin('content-manager').service('document-metadata');\n const permissionService = strapi.admin.services.permission;\n\n const getRegisteredContentType = (uid: RecentDocument['contentTypeUid']) => {\n const contentType = strapi.contentTypes[uid];\n\n if (contentType === undefined) {\n strapi.log.warn(\n `Skipping homepage content type \"${uid}\" because it is no longer registered.`\n );\n return undefined;\n }\n\n return contentType;\n };\n\n type ContentTypeConfiguration = {\n uid: RecentDocument['contentTypeUid'];\n settings: { mainField: string };\n };\n const getConfiguration = async (\n contentTypeUids: RecentDocument['contentTypeUid'][]\n ): Promise<ContentTypeConfiguration[]> => {\n /**\n * Don't use the strapi.store util because we need to make\n * more precise queries than exact key matches, in order to make as few queries as possible.\n */\n const coreStore = strapi.db.query('strapi::core-store');\n const rawConfigurations = await coreStore.findMany({\n where: {\n key: {\n $in: contentTypeUids.map(\n (contentType) => `plugin_content_manager_configuration_content_types::${contentType}`\n ),\n },\n },\n });\n\n return rawConfigurations.map((rawConfiguration) => {\n return JSON.parse(rawConfiguration.value);\n });\n };\n\n const getPermittedContentTypes = async () => {\n const readPermissions: Modules.Permissions.PermissionRule[] = await permissionService.findMany({\n where: {\n role: { users: { id: strapi.requestContext.get()?.state?.user.id } },\n action: 'plugin::content-manager.explorer.read',\n },\n });\n\n // Deduplicate subjects using a Set: the JOIN across permission -> role -> users produces one row\n // per role the user belongs to, so a multi-role user gets duplicate subjects.\n // Using a Set collapses them to unique content type UID.\n return [\n ...new Set(\n readPermissions\n .map((permission) => permission.subject)\n .filter((subject): subject is RecentDocument['contentTypeUid'] => {\n if (!subject) {\n return false;\n }\n\n const contentType = strapi.contentTypes[subject as keyof typeof strapi.contentTypes];\n const contentTypeOptions = contentType?.pluginOptions?.['content-manager'] as\n | { visible?: boolean }\n | undefined;\n\n return contentTypeOptions?.visible !== false;\n })\n ),\n ];\n };\n\n type ContentTypeMeta = {\n fields: string[];\n mainField: string;\n contentType: Schema.ContentType;\n hasDraftAndPublish: boolean;\n uid: RecentDocument['contentTypeUid'];\n };\n\n const permissionCheckerService = strapi.plugin('content-manager').service('permission-checker');\n const getPermissionChecker = (uid: string) =>\n permissionCheckerService.create({\n userAbility: strapi.requestContext.get()?.state.userAbility,\n model: uid,\n });\n\n const getContentTypesMeta = (\n allowedContentTypeUids: RecentDocument['contentTypeUid'][],\n configurations: ContentTypeConfiguration[]\n ): ContentTypeMeta[] => {\n return allowedContentTypeUids.reduce<ContentTypeMeta[]>((acc, uid) => {\n const configuration = configurations.find((config) => config.uid === uid);\n const contentType = getRegisteredContentType(uid);\n\n if (contentType === undefined) {\n return acc;\n }\n\n const mainField = resolveReadableMainField(\n contentType,\n configuration,\n getPermissionChecker(uid)\n );\n const fields = buildHomepageQueryFields(contentType, mainField);\n const hasDraftAndPublish = contentTypes.hasDraftAndPublish(contentType);\n\n acc.push({\n fields,\n mainField,\n contentType,\n hasDraftAndPublish,\n uid,\n });\n\n return acc;\n }, []);\n };\n\n /**\n * Homepage widgets expect JSON-safe ISO strings. Returning `Date` objects can\n * serialize as `{}` after spread/clone (see https://github.com/strapi/strapi/issues/27013).\n */\n const toIsoDateString = (value: unknown): string | null => {\n if (value == null || value === '') {\n return null;\n }\n\n const date = value instanceof Date ? value : new Date(String(value));\n return Number.isNaN(date.getTime()) ? null : date.toISOString();\n };\n\n const formatDocuments = (\n documents: Modules.Documents.AnyDocument[],\n meta: ContentTypeMeta,\n populate?: string[]\n ) => {\n return documents.map((document) => {\n const additionalFields =\n populate?.reduce(\n (acc, key) => {\n acc[key] = document[key];\n return acc;\n },\n {} as Record<string, any>\n ) || {};\n return {\n documentId: document.documentId,\n locale: document.locale ?? null,\n title: document[meta.mainField ?? 'documentId'],\n contentTypeUid: meta.uid,\n contentTypeDisplayName: meta.contentType.info.displayName,\n kind: meta.contentType.kind,\n ...additionalFields,\n // Keep dates last so populate cannot overwrite with non-JSON-safe values\n updatedAt: toIsoDateString(document.updatedAt) ?? '',\n publishedAt:\n meta.hasDraftAndPublish && document.publishedAt\n ? toIsoDateString(document.publishedAt)\n : null,\n };\n });\n };\n\n const sanitizeHomepageQuery = async (\n meta: ContentTypeMeta,\n additionalQueryParams?: Record<string, unknown>\n ) => {\n const permissionQuery = await getPermissionChecker(meta.uid).sanitizedQuery.read({\n limit: MAX_DOCUMENTS,\n fields: meta.fields,\n ...additionalQueryParams,\n locale: '*',\n });\n\n const sanitizedFields = compactSanitizedFields(permissionQuery.fields);\n if (sanitizedFields !== undefined) {\n permissionQuery.fields = sanitizedFields;\n }\n\n return {\n permissionQuery,\n titleField: resolveTitleField(meta.mainField, sanitizedFields),\n };\n };\n\n return {\n async addStatusToDocuments(documents: RecentDocument[]): Promise<RecentDocument[]> {\n return Promise.all(\n documents.map(async (recentDocument) => {\n const hasDraftAndPublish = contentTypes.hasDraftAndPublish(\n strapi.contentType(recentDocument.contentTypeUid)\n );\n /**\n * Tries to query the other version of the document if draft and publish is enabled,\n * so that we know when to give the \"modified\" status.\n */\n const { availableStatus } = await metadataService.getMetadata(\n recentDocument.contentTypeUid,\n recentDocument,\n {\n availableStatus: hasDraftAndPublish,\n availableLocales: false,\n }\n );\n const status: RecentDocument['status'] = metadataService.getStatus(\n recentDocument,\n availableStatus\n );\n\n return {\n ...recentDocument,\n status: hasDraftAndPublish ? status : undefined,\n };\n })\n );\n },\n\n async queryLastDocuments(\n additionalQueryParams?: Record<string, unknown>,\n draftAndPublishOnly?: boolean\n ): Promise<RecentDocument[]> {\n const permittedContentTypes = await getPermittedContentTypes();\n const allowedContentTypeUids = draftAndPublishOnly\n ? permittedContentTypes.filter((uid) => {\n const contentType = getRegisteredContentType(uid);\n\n return contentType !== undefined && contentTypes.hasDraftAndPublish(contentType);\n })\n : permittedContentTypes;\n // Fetch the configuration for each content type in a single query\n const configurations = await getConfiguration(allowedContentTypeUids);\n // Get the necessary metadata for the documents\n const contentTypesMeta = getContentTypesMeta(allowedContentTypeUids, configurations);\n\n const recentDocuments = await Promise.all(\n contentTypesMeta.map(async (meta) => {\n const { permissionQuery, titleField } = await sanitizeHomepageQuery(\n meta,\n additionalQueryParams\n );\n\n const docs = await strapi.documents(meta.uid).findMany(permissionQuery);\n const populate = additionalQueryParams?.populate as string[];\n\n return formatDocuments(docs, { ...meta, mainField: titleField }, populate);\n })\n );\n\n return recentDocuments\n .flat()\n .sort((a, b) => {\n // ISO-8601 strings compare lexicographically in chronological order\n const compareIso = (left: string, right: string, direction: 1 | -1) => {\n if (left < right) return -1 * direction;\n if (left > right) return 1 * direction;\n return 0;\n };\n\n switch (additionalQueryParams?.sort) {\n case 'publishedAt:desc':\n if (!a.publishedAt || !b.publishedAt) return 0;\n return compareIso(a.publishedAt, b.publishedAt, -1);\n case 'publishedAt:asc':\n if (!a.publishedAt || !b.publishedAt) return 0;\n return compareIso(a.publishedAt, b.publishedAt, 1);\n case 'updatedAt:desc':\n if (!a.updatedAt || !b.updatedAt) return 0;\n return compareIso(a.updatedAt, b.updatedAt, -1);\n case 'updatedAt:asc':\n if (!a.updatedAt || !b.updatedAt) return 0;\n return compareIso(a.updatedAt, b.updatedAt, 1);\n default:\n return 0;\n }\n })\n .slice(0, MAX_DOCUMENTS);\n },\n\n async getRecentlyPublishedDocuments(): Promise<GetRecentDocuments.Response['data']> {\n const recentlyPublishedDocuments = await this.queryLastDocuments(\n {\n sort: 'publishedAt:desc',\n status: 'published',\n },\n true\n );\n\n return this.addStatusToDocuments(recentlyPublishedDocuments);\n },\n\n async getRecentlyUpdatedDocuments(): Promise<GetRecentDocuments.Response['data']> {\n const recentlyUpdatedDocuments = await this.queryLastDocuments({\n sort: 'updatedAt:desc',\n });\n\n return this.addStatusToDocuments(recentlyUpdatedDocuments);\n },\n\n async getCountDocuments(): Promise<GetCountDocuments.Response['data']> {\n const permittedContentTypes = await getPermittedContentTypes();\n // Fetch the configuration for each content type in a single query\n const configurations = await getConfiguration(permittedContentTypes);\n // Get the necessary metadata for the documents\n const contentTypesMeta = getContentTypesMeta(permittedContentTypes, configurations);\n\n const countDocuments = {\n draft: 0,\n published: 0,\n modified: 0,\n };\n\n await Promise.all(\n contentTypesMeta.map(async (meta) => {\n const strapiDBConnection = strapi.db.connection;\n const tableName = strapi.contentType(meta.uid).collectionName;\n if (!tableName) return;\n\n if (!meta.hasDraftAndPublish) {\n const publishedDocuments = await strapiDBConnection(tableName)\n .countDistinct('document_id as count')\n .first();\n countDocuments.published += Number(publishedDocuments?.count) || 0;\n return;\n }\n\n // Classify each document_id into a single bucket (draft / published / modified)\n // in one pass. Replaces three separate self-join queries that scaled poorly on\n // large tables — see https://github.com/strapi/strapi/issues/25200.\n const classified = strapiDBConnection(tableName)\n .select('document_id')\n .select(\n strapiDBConnection.raw(\n `CASE\n WHEN MAX(CASE WHEN published_at IS NOT NULL THEN 1 ELSE 0 END) = 0\n THEN 'draft'\n WHEN MAX(CASE WHEN published_at IS NULL THEN updated_at END) =\n MAX(CASE WHEN published_at IS NOT NULL THEN updated_at END)\n THEN 'published'\n ELSE 'modified'\n END AS bucket`\n )\n )\n .groupBy('document_id');\n\n const counts = await strapiDBConnection\n .from(classified.as('classified'))\n .select(\n strapiDBConnection.raw(\n `COUNT(CASE WHEN bucket = 'draft' THEN 1 END) AS draft,\n COUNT(CASE WHEN bucket = 'published' THEN 1 END) AS published,\n COUNT(CASE WHEN bucket = 'modified' THEN 1 END) AS modified`\n )\n )\n .first();\n\n countDocuments.draft += Number(counts?.draft) || 0;\n countDocuments.published += Number(counts?.published) || 0;\n countDocuments.modified += Number(counts?.modified) || 0;\n })\n );\n\n return countDocuments;\n },\n };\n};\n\nexport { createHomepageService };\n"],"names":["createHomepageService","strapi","MAX_DOCUMENTS","metadataService","plugin","service","permissionService","admin","services","permission","getRegisteredContentType","uid","contentType","contentTypes","undefined","log","warn","getConfiguration","contentTypeUids","coreStore","db","query","rawConfigurations","findMany","where","key","$in","map","rawConfiguration","JSON","parse","value","getPermittedContentTypes","readPermissions","role","users","id","requestContext","get","state","user","action","Set","subject","filter","contentTypeOptions","pluginOptions","visible","permissionCheckerService","getPermissionChecker","create","userAbility","model","getContentTypesMeta","allowedContentTypeUids","configurations","reduce","acc","configuration","find","config","mainField","resolveReadableMainField","fields","buildHomepageQueryFields","hasDraftAndPublish","push","toIsoDateString","date","Date","String","Number","isNaN","getTime","toISOString","formatDocuments","documents","meta","populate","document","additionalFields","documentId","locale","title","contentTypeUid","contentTypeDisplayName","info","displayName","kind","updatedAt","publishedAt","sanitizeHomepageQuery","additionalQueryParams","permissionQuery","sanitizedQuery","read","limit","sanitizedFields","compactSanitizedFields","titleField","resolveTitleField","addStatusToDocuments","Promise","all","recentDocument","availableStatus","getMetadata","availableLocales","status","getStatus","queryLastDocuments","draftAndPublishOnly","permittedContentTypes","contentTypesMeta","recentDocuments","docs","flat","sort","a","b","compareIso","left","right","direction","slice","getRecentlyPublishedDocuments","recentlyPublishedDocuments","getRecentlyUpdatedDocuments","recentlyUpdatedDocuments","getCountDocuments","countDocuments","draft","published","modified","strapiDBConnection","connection","tableName","collectionName","publishedDocuments","countDistinct","first","count","classified","select","raw","groupBy","counts","from","as"],"mappings":";;;AAiBA,MAAMA,qBAAAA,GAAwB,CAAC,EAAEC,MAAM,EAA2B,GAAA;AAChE,IAAA,MAAMC,aAAAA,GAAgB,CAAA;AAEtB,IAAA,MAAMC,kBAAkBF,MAAAA,CAAOG,MAAM,CAAC,iBAAA,CAAA,CAAmBC,OAAO,CAAC,mBAAA,CAAA;AACjE,IAAA,MAAMC,oBAAoBL,MAAAA,CAAOM,KAAK,CAACC,QAAQ,CAACC,UAAU;AAE1D,IAAA,MAAMC,2BAA2B,CAACC,GAAAA,GAAAA;AAChC,QAAA,MAAMC,WAAAA,GAAcX,MAAAA,CAAOY,YAAY,CAACF,GAAAA,CAAI;AAE5C,QAAA,IAAIC,gBAAgBE,SAAAA,EAAW;YAC7B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G,CACpB,CAAC;;AAE2D,4EAAA,CAAC,GAGhEJ,KAAK,EAAA;AAERV,gBAAAA,cAAAA,CAAeC,KAAK,IAAI5D,MAAAA,CAAO2E,MAAAA,EAAQf,KAAAA,CAAAA,IAAU,CAAA;AACjDD,gBAAAA,cAAAA,CAAeE,SAAS,IAAI7D,MAAAA,CAAO2E,MAAAA,EAAQd,SAAAA,CAAAA,IAAc,CAAA;AACzDF,gBAAAA,cAAAA,CAAeG,QAAQ,IAAI9D,MAAAA,CAAO2E,MAAAA,EAAQb,QAAAA,CAAAA,IAAa,CAAA;AACzD,YAAA,CAAA,CAAA,CAAA;YAGF,OAAOH,cAAAA;AACT,QAAA;AACF,KAAA;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"homepage.mjs","sources":["../../../../server/src/homepage/services/homepage.ts"],"sourcesContent":["/* eslint-disable func-names */\nimport type { Core, Modules, Schema } from '@strapi/types';\nimport { contentTypes } from '@strapi/utils';\n\nimport type {\n GetCountDocuments,\n GetRecentDocuments,\n RecentDocument,\n} from '../../../../shared/contracts/homepage';\n\nimport {\n buildHomepageQueryFields,\n compactSanitizedFields,\n resolveReadableMainField,\n resolveTitleField,\n} from './homepage-query-utils';\n\nconst createHomepageService = ({ strapi }: { strapi: Core.Strapi }) => {\n const MAX_DOCUMENTS = 4;\n\n const metadataService = strapi.plugin('content-manager').service('document-metadata');\n const permissionService = strapi.admin.services.permission;\n\n const getRegisteredContentType = (uid: RecentDocument['contentTypeUid']) => {\n const contentType = strapi.contentTypes[uid];\n\n if (contentType === undefined) {\n strapi.log.warn(\n `Skipping homepage content type \"${uid}\" because it is no longer registered.`\n );\n return undefined;\n }\n\n return contentType;\n };\n\n type ContentTypeConfiguration = {\n uid: RecentDocument['contentTypeUid'];\n settings: { mainField: string };\n };\n const getConfiguration = async (\n contentTypeUids: RecentDocument['contentTypeUid'][]\n ): Promise<ContentTypeConfiguration[]> => {\n /**\n * Don't use the strapi.store util because we need to make\n * more precise queries than exact key matches, in order to make as few queries as possible.\n */\n const coreStore = strapi.db.query('strapi::core-store');\n const rawConfigurations = await coreStore.findMany({\n where: {\n key: {\n $in: contentTypeUids.map(\n (contentType) => `plugin_content_manager_configuration_content_types::${contentType}`\n ),\n },\n },\n });\n\n return rawConfigurations.map((rawConfiguration) => {\n return JSON.parse(rawConfiguration.value);\n });\n };\n\n const getPermittedContentTypes = async () => {\n const readPermissions: Modules.Permissions.PermissionRule[] = await permissionService.findMany({\n where: {\n role: { users: { id: strapi.requestContext.get()?.state?.user.id } },\n action: 'plugin::content-manager.explorer.read',\n },\n });\n\n // Deduplicate subjects using a Set: the JOIN across permission -> role -> users produces one row\n // per role the user belongs to, so a multi-role user gets duplicate subjects.\n // Using a Set collapses them to unique content type UID.\n return [\n ...new Set(\n readPermissions\n .map((permission) => permission.subject)\n .filter((subject): subject is RecentDocument['contentTypeUid'] => {\n if (!subject) {\n return false;\n }\n\n const contentType = strapi.contentTypes[subject as keyof typeof strapi.contentTypes];\n const contentTypeOptions = contentType?.pluginOptions?.['content-manager'] as\n { visible?: boolean } | undefined;\n\n return contentTypeOptions?.visible !== false;\n })\n ),\n ];\n };\n\n type ContentTypeMeta = {\n fields: string[];\n mainField: string;\n contentType: Schema.ContentType;\n hasDraftAndPublish: boolean;\n uid: RecentDocument['contentTypeUid'];\n };\n\n const permissionCheckerService = strapi.plugin('content-manager').service('permission-checker');\n const getPermissionChecker = (uid: string) =>\n permissionCheckerService.create({\n userAbility: strapi.requestContext.get()?.state.userAbility,\n model: uid,\n });\n\n const getContentTypesMeta = (\n allowedContentTypeUids: RecentDocument['contentTypeUid'][],\n configurations: ContentTypeConfiguration[]\n ): ContentTypeMeta[] => {\n return allowedContentTypeUids.reduce<ContentTypeMeta[]>((acc, uid) => {\n const configuration = configurations.find((config) => config.uid === uid);\n const contentType = getRegisteredContentType(uid);\n\n if (contentType === undefined) {\n return acc;\n }\n\n const mainField = resolveReadableMainField(\n contentType,\n configuration,\n getPermissionChecker(uid)\n );\n const fields = buildHomepageQueryFields(contentType, mainField);\n const hasDraftAndPublish = contentTypes.hasDraftAndPublish(contentType);\n\n acc.push({\n fields,\n mainField,\n contentType,\n hasDraftAndPublish,\n uid,\n });\n\n return acc;\n }, []);\n };\n\n /**\n * Homepage widgets expect JSON-safe ISO strings. Returning `Date` objects can\n * serialize as `{}` after spread/clone (see https://github.com/strapi/strapi/issues/27013).\n */\n const toIsoDateString = (value: unknown): string | null => {\n if (value == null || value === '') {\n return null;\n }\n\n const date = value instanceof Date ? value : new Date(String(value));\n return Number.isNaN(date.getTime()) ? null : date.toISOString();\n };\n\n const formatDocuments = (\n documents: Modules.Documents.AnyDocument[],\n meta: ContentTypeMeta,\n populate?: string[]\n ) => {\n return documents.map((document) => {\n const additionalFields =\n populate?.reduce(\n (acc, key) => {\n acc[key] = document[key];\n return acc;\n },\n {} as Record<string, any>\n ) || {};\n return {\n documentId: document.documentId,\n locale: document.locale ?? null,\n title: document[meta.mainField ?? 'documentId'],\n contentTypeUid: meta.uid,\n contentTypeDisplayName: meta.contentType.info.displayName,\n kind: meta.contentType.kind,\n ...additionalFields,\n // Keep dates last so populate cannot overwrite with non-JSON-safe values\n updatedAt: toIsoDateString(document.updatedAt) ?? '',\n publishedAt:\n meta.hasDraftAndPublish && document.publishedAt\n ? toIsoDateString(document.publishedAt)\n : null,\n };\n });\n };\n\n const sanitizeHomepageQuery = async (\n meta: ContentTypeMeta,\n additionalQueryParams?: Record<string, unknown>\n ) => {\n const permissionQuery = await getPermissionChecker(meta.uid).sanitizedQuery.read({\n limit: MAX_DOCUMENTS,\n fields: meta.fields,\n ...additionalQueryParams,\n locale: '*',\n });\n\n const sanitizedFields = compactSanitizedFields(permissionQuery.fields);\n if (sanitizedFields !== undefined) {\n permissionQuery.fields = sanitizedFields;\n }\n\n return {\n permissionQuery,\n titleField: resolveTitleField(meta.mainField, sanitizedFields),\n };\n };\n\n return {\n async addStatusToDocuments(documents: RecentDocument[]): Promise<RecentDocument[]> {\n return Promise.all(\n documents.map(async (recentDocument) => {\n const hasDraftAndPublish = contentTypes.hasDraftAndPublish(\n strapi.contentType(recentDocument.contentTypeUid)\n );\n /**\n * Tries to query the other version of the document if draft and publish is enabled,\n * so that we know when to give the \"modified\" status.\n */\n const { availableStatus } = await metadataService.getMetadata(\n recentDocument.contentTypeUid,\n recentDocument,\n {\n availableStatus: hasDraftAndPublish,\n availableLocales: false,\n }\n );\n const status: RecentDocument['status'] = metadataService.getStatus(\n recentDocument,\n availableStatus\n );\n\n return {\n ...recentDocument,\n status: hasDraftAndPublish ? status : undefined,\n };\n })\n );\n },\n\n async queryLastDocuments(\n additionalQueryParams?: Record<string, unknown>,\n draftAndPublishOnly?: boolean\n ): Promise<RecentDocument[]> {\n const permittedContentTypes = await getPermittedContentTypes();\n const allowedContentTypeUids = draftAndPublishOnly\n ? permittedContentTypes.filter((uid) => {\n const contentType = getRegisteredContentType(uid);\n\n return contentType !== undefined && contentTypes.hasDraftAndPublish(contentType);\n })\n : permittedContentTypes;\n // Fetch the configuration for each content type in a single query\n const configurations = await getConfiguration(allowedContentTypeUids);\n // Get the necessary metadata for the documents\n const contentTypesMeta = getContentTypesMeta(allowedContentTypeUids, configurations);\n\n const recentDocuments = await Promise.all(\n contentTypesMeta.map(async (meta) => {\n const { permissionQuery, titleField } = await sanitizeHomepageQuery(\n meta,\n additionalQueryParams\n );\n\n const docs = await strapi.documents(meta.uid).findMany(permissionQuery);\n const populate = additionalQueryParams?.populate as string[];\n\n return formatDocuments(docs, { ...meta, mainField: titleField }, populate);\n })\n );\n\n return recentDocuments\n .flat()\n .sort((a, b) => {\n // ISO-8601 strings compare lexicographically in chronological order\n const compareIso = (left: string, right: string, direction: 1 | -1) => {\n if (left < right) return -1 * direction;\n if (left > right) return 1 * direction;\n return 0;\n };\n\n switch (additionalQueryParams?.sort) {\n case 'publishedAt:desc':\n if (!a.publishedAt || !b.publishedAt) return 0;\n return compareIso(a.publishedAt, b.publishedAt, -1);\n case 'publishedAt:asc':\n if (!a.publishedAt || !b.publishedAt) return 0;\n return compareIso(a.publishedAt, b.publishedAt, 1);\n case 'updatedAt:desc':\n if (!a.updatedAt || !b.updatedAt) return 0;\n return compareIso(a.updatedAt, b.updatedAt, -1);\n case 'updatedAt:asc':\n if (!a.updatedAt || !b.updatedAt) return 0;\n return compareIso(a.updatedAt, b.updatedAt, 1);\n default:\n return 0;\n }\n })\n .slice(0, MAX_DOCUMENTS);\n },\n\n async getRecentlyPublishedDocuments(): Promise<GetRecentDocuments.Response['data']> {\n const recentlyPublishedDocuments = await this.queryLastDocuments(\n {\n sort: 'publishedAt:desc',\n status: 'published',\n },\n true\n );\n\n return this.addStatusToDocuments(recentlyPublishedDocuments);\n },\n\n async getRecentlyUpdatedDocuments(): Promise<GetRecentDocuments.Response['data']> {\n const recentlyUpdatedDocuments = await this.queryLastDocuments({\n sort: 'updatedAt:desc',\n });\n\n return this.addStatusToDocuments(recentlyUpdatedDocuments);\n },\n\n async getCountDocuments(): Promise<GetCountDocuments.Response['data']> {\n const permittedContentTypes = await getPermittedContentTypes();\n // Fetch the configuration for each content type in a single query\n const configurations = await getConfiguration(permittedContentTypes);\n // Get the necessary metadata for the documents\n const contentTypesMeta = getContentTypesMeta(permittedContentTypes, configurations);\n\n const countDocuments = {\n draft: 0,\n published: 0,\n modified: 0,\n };\n\n await Promise.all(\n contentTypesMeta.map(async (meta) => {\n const strapiDBConnection = strapi.db.connection;\n const tableName = strapi.contentType(meta.uid).collectionName;\n if (!tableName) return;\n\n if (!meta.hasDraftAndPublish) {\n const publishedDocuments = await strapiDBConnection(tableName)\n .countDistinct('document_id as count')\n .first();\n countDocuments.published += Number(publishedDocuments?.count) || 0;\n return;\n }\n\n // Classify each document_id into a single bucket (draft / published / modified)\n // in one pass. Replaces three separate self-join queries that scaled poorly on\n // large tables — see https://github.com/strapi/strapi/issues/25200.\n const classified = strapiDBConnection(tableName)\n .select('document_id')\n .select(\n strapiDBConnection.raw(\n `CASE\n WHEN MAX(CASE WHEN published_at IS NOT NULL THEN 1 ELSE 0 END) = 0\n THEN 'draft'\n WHEN MAX(CASE WHEN published_at IS NULL THEN updated_at END) =\n MAX(CASE WHEN published_at IS NOT NULL THEN updated_at END)\n THEN 'published'\n ELSE 'modified'\n END AS bucket`\n )\n )\n .groupBy('document_id');\n\n const counts = await strapiDBConnection\n .from(classified.as('classified'))\n .select(\n strapiDBConnection.raw(\n `COUNT(CASE WHEN bucket = 'draft' THEN 1 END) AS draft,\n COUNT(CASE WHEN bucket = 'published' THEN 1 END) AS published,\n COUNT(CASE WHEN bucket = 'modified' THEN 1 END) AS modified`\n )\n )\n .first();\n\n countDocuments.draft += Number(counts?.draft) || 0;\n countDocuments.published += Number(counts?.published) || 0;\n countDocuments.modified += Number(counts?.modified) || 0;\n })\n );\n\n return countDocuments;\n },\n };\n};\n\nexport { createHomepageService };\n"],"names":["createHomepageService","strapi","MAX_DOCUMENTS","metadataService","plugin","service","permissionService","admin","services","permission","getRegisteredContentType","uid","contentType","contentTypes","undefined","log","warn","getConfiguration","contentTypeUids","coreStore","db","query","rawConfigurations","findMany","where","key","$in","map","rawConfiguration","JSON","parse","value","getPermittedContentTypes","readPermissions","role","users","id","requestContext","get","state","user","action","Set","subject","filter","contentTypeOptions","pluginOptions","visible","permissionCheckerService","getPermissionChecker","create","userAbility","model","getContentTypesMeta","allowedContentTypeUids","configurations","reduce","acc","configuration","find","config","mainField","resolveReadableMainField","fields","buildHomepageQueryFields","hasDraftAndPublish","push","toIsoDateString","date","Date","String","Number","isNaN","getTime","toISOString","formatDocuments","documents","meta","populate","document","additionalFields","documentId","locale","title","contentTypeUid","contentTypeDisplayName","info","displayName","kind","updatedAt","publishedAt","sanitizeHomepageQuery","additionalQueryParams","permissionQuery","sanitizedQuery","read","limit","sanitizedFields","compactSanitizedFields","titleField","resolveTitleField","addStatusToDocuments","Promise","all","recentDocument","availableStatus","getMetadata","availableLocales","status","getStatus","queryLastDocuments","draftAndPublishOnly","permittedContentTypes","contentTypesMeta","recentDocuments","docs","flat","sort","a","b","compareIso","left","right","direction","slice","getRecentlyPublishedDocuments","recentlyPublishedDocuments","getRecentlyUpdatedDocuments","recentlyUpdatedDocuments","getCountDocuments","countDocuments","draft","published","modified","strapiDBConnection","connection","tableName","collectionName","publishedDocuments","countDistinct","first","count","classified","select","raw","groupBy","counts","from","as"],"mappings":";;;AAiBA,MAAMA,qBAAAA,GAAwB,CAAC,EAAEC,MAAM,EAA2B,GAAA;AAChE,IAAA,MAAMC,aAAAA,GAAgB,CAAA;AAEtB,IAAA,MAAMC,kBAAkBF,MAAAA,CAAOG,MAAM,CAAC,iBAAA,CAAA,CAAmBC,OAAO,CAAC,mBAAA,CAAA;AACjE,IAAA,MAAMC,oBAAoBL,MAAAA,CAAOM,KAAK,CAACC,QAAQ,CAACC,UAAU;AAE1D,IAAA,MAAMC,2BAA2B,CAACC,GAAAA,GAAAA;AAChC,QAAA,MAAMC,WAAAA,GAAcX,MAAAA,CAAOY,YAAY,CAACF,GAAAA,CAAI;AAE5C,QAAA,IAAIC,gBAAgBE,SAAAA,EAAW;YAC7Bb,MAAAA,CAAOc,GAAG,CAACC,IAAI,CACb,CAAC,gCAAgC,EAAEL,GAAAA,CAAI,qCAAqC,CAAC,CAAA;YAE/E,OAAOG,SAAAA;AACT,QAAA;QAEA,OAAOF,WAAAA;AACT,IAAA,CAAA;AAMA,IAAA,MAAMK,mBAAmB,OACvBC,eAAAA,GAAAA;AAEA;;;AAGC,QACD,MAAMC,SAAAA,GAAYlB,MAAAA,CAAOmB,EAAE,CAACC,KAAK,CAAC,oBAAA,CAAA;AAClC,QAAA,MAAMC,iBAAAA,GAAoB,MAAMH,SAAAA,CAAUI,QAAQ,CAAC;YACjDC,KAAAA,EAAO;gBACLC,GAAAA,EAAK;oBACHC,GAAAA,EAAKR,eAAAA,CAAgBS,GAAG,CACtB,CAACf,cAAgB,CAAC,oDAAoD,EAAEA,WAAAA,CAAAA,CAAa;AAEzF;AACF;AACF,SAAA,CAAA;QAEA,OAAOU,iBA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CAACD,SAAAA,EAAW;gBAEhB,IAAI,CAAC3D,IAAAA,CAAKZ,kBAAkB,EAAE;AAC5B,oBAAA,MAAMyE,qBAAqB,MAAMJ,kBAAAA,CAAmBE,WACjDG,aAAa,CAAC,wBACdC,KAAK,EAAA;AACRV,oBAAAA,cAAAA,CAAeE,SAAS,IAAI7D,MAAAA,CAAOmE,kBAAAA,EAAoBG,KAAAA,CAAAA,IAAU,CAAA;AACjE,oBAAA;AACF,gBAAA;;;;gBAKA,MAAMC,UAAAA,GAAaR,kBAAAA,CAAmBE,SAAAA,CAAAA,CACnCO,MAAM,CAAC,aAAA,CAAA,CACPA,MAAM,CACLT,kBAAAA,CAAmBU,GAAG,CACpB,CAAC;;;;;;;6BAOY,CAAC,CAAA,CAAA,CAGjBC,OAAO,CAAC,aAAA,CAAA;AAEX,gBAAA,MAAMC,MAAAA,GAAS,MAAMZ,kBAAAA,CAClBa,IAAI,CAACL,UAAAA,CAAWM,EAAE,CAAC,YAAA,CAAA,CAAA,CACnBL,MAAM,CACLT,kBAAAA,CAAmBU,GAAG,CACpB,CAAC;;AAE2D,4EAAA,CAAC,GAGhEJ,KAAK,EAAA;AAERV,gBAAAA,cAAAA,CAAeC,KAAK,IAAI5D,MAAAA,CAAO2E,MAAAA,EAAQf,KAAAA,CAAAA,IAAU,CAAA;AACjDD,gBAAAA,cAAAA,CAAeE,SAAS,IAAI7D,MAAAA,CAAO2E,MAAAA,EAAQd,SAAAA,CAAAA,IAAc,CAAA;AACzDF,gBAAAA,cAAAA,CAAeG,QAAQ,IAAI9D,MAAAA,CAAO2E,MAAAA,EAAQb,QAAAA,CAAAA,IAAa,CAAA;AACzD,YAAA,CAAA,CAAA,CAAA;YAGF,OAAOH,cAAAA;AACT,QAAA;AACF,KAAA;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preview-config.js","sources":["../../../../server/src/preview/services/preview-config.ts"],"sourcesContent":["import type { Core } from '@strapi/types';\nimport { errors, extendMiddlewareConfiguration } from '@strapi/utils';\n\nexport type HandlerParams = {\n documentId: string;\n locale: string;\n status: 'published' | 'draft';\n};\n\n/**\n * @deprecated Use Core.Config.Admin['preview'] from @strapi/types instead\n * Keeping for backward compatibility\n */\nexport type PreviewConfig = NonNullable<Core.Config.Admin['preview']>;\n\n/**\n * Read configuration for static preview\n */\nconst createPreviewConfigService = ({ strapi }: { strapi: Core.Strapi }) => {\n return {\n register() {\n if (!this.isEnabled()) {\n return;\n }\n\n const config = strapi.config.get('admin.preview') as PreviewConfig;\n\n /**\n * Register the allowed origins for CSP, so the preview URL can be displayed\n */\n if (config.config?.allowedOrigins) {\n const middlewares = strapi.config.get('middlewares') as (\n
|
|
1
|
+
{"version":3,"file":"preview-config.js","sources":["../../../../server/src/preview/services/preview-config.ts"],"sourcesContent":["import type { Core } from '@strapi/types';\nimport { errors, extendMiddlewareConfiguration } from '@strapi/utils';\n\nexport type HandlerParams = {\n documentId: string;\n locale: string;\n status: 'published' | 'draft';\n};\n\n/**\n * @deprecated Use Core.Config.Admin['preview'] from @strapi/types instead\n * Keeping for backward compatibility\n */\nexport type PreviewConfig = NonNullable<Core.Config.Admin['preview']>;\n\n/**\n * Read configuration for static preview\n */\nconst createPreviewConfigService = ({ strapi }: { strapi: Core.Strapi }) => {\n return {\n register() {\n if (!this.isEnabled()) {\n return;\n }\n\n const config = strapi.config.get('admin.preview') as PreviewConfig;\n\n /**\n * Register the allowed origins for CSP, so the preview URL can be displayed\n */\n if (config.config?.allowedOrigins) {\n const middlewares = strapi.config.get('middlewares') as (\n string | { name?: string; config?: any }\n )[];\n\n const configuredMiddlewares = extendMiddlewareConfiguration(middlewares, {\n name: 'strapi::security',\n config: {\n contentSecurityPolicy: {\n directives: {\n 'frame-src': config.config.allowedOrigins,\n },\n },\n },\n });\n\n strapi.config.set('middlewares', configuredMiddlewares);\n }\n },\n\n isConfigured() {\n const config = strapi.config.get('admin.preview') as PreviewConfig;\n return config?.enabled === false || config?.config?.handler != null;\n },\n\n isEnabled() {\n const config = strapi.config.get('admin.preview') as PreviewConfig;\n\n if (!config) {\n return false;\n }\n\n return config?.enabled ?? true;\n },\n\n /**\n * Validate if the configuration is valid\n */\n validate() {\n if (!this.isEnabled()) {\n return;\n }\n\n const handler = this.getPreviewHandler();\n\n // Handler must be a function\n if (typeof handler !== 'function') {\n throw new errors.ValidationError(\n 'Preview configuration is invalid. Handler must be a function'\n );\n }\n },\n\n /**\n * Utility to get the preview handler from the configuration\n */\n getPreviewHandler(): NonNullable<Core.Config.Admin['preview']>['config']['handler'] {\n const emptyHandler = () => {\n return undefined;\n };\n\n if (!this.isEnabled()) {\n return emptyHandler;\n }\n\n const config = strapi.config.get('admin.preview') as PreviewConfig;\n\n return config?.config?.handler || emptyHandler;\n },\n };\n};\n\nexport { createPreviewConfigService };\n"],"names":["createPreviewConfigService","strapi","register","isEnabled","config","get","allowedOrigins","middlewares","configuredMiddlewares","extendMiddlewareConfiguration","name","contentSecurityPolicy","directives","set","isConfigured","enabled","handler","validate","getPreviewHandler","errors","ValidationError","emptyHandler","undefined"],"mappings":";;;;AAeA;;AAEC,IACD,MAAMA,0BAAAA,GAA6B,CAAC,EAAEC,MAAM,EAA2B,GAAA;IACrE,OAAO;AACLC,QAAAA,QAAAA,CAAAA,GAAAA;AACE,YAAA,IAAI,CAAC,IAAI,CAACC,SAAS,EAAA,EAAI;AACrB,gBAAA;AACF,YAAA;AAEA,YAAA,MAAMC,MAAAA,GAASH,MAAAA,CAAOG,MAAM,CAACC,GAAG,CAAC,eAAA,CAAA;AAEjC;;AAEC,UACD,IAAID,MAAAA,CAAOA,MAAM,EAAEE,cAAAA,EAAgB;AACjC,gBAAA,MAAMC,WAAAA,GAAcN,MAAAA,CAAOG,MAAM,CAACC,GAAG,CAAC,aAAA,CAAA;gBAItC,MAAMG,qBAAAA,GAAwBC,0CAA8BF,WAAAA,EAAa;oBACvEG,IAAAA,EAAM,kBAAA;oBACNN,MAAAA,EAAQ;wBACNO,qBAAAA,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AAA,GAASH,MAAAA,CAAOG,MAAM,CAACC,GAAG,CAAC,eAAA,CAAA;YAEjC,OAAOD,MAAAA,EAAQA,QAAQY,OAAAA,IAAWK,YAAAA;AACpC,QAAA;AACF,KAAA;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preview-config.mjs","sources":["../../../../server/src/preview/services/preview-config.ts"],"sourcesContent":["import type { Core } from '@strapi/types';\nimport { errors, extendMiddlewareConfiguration } from '@strapi/utils';\n\nexport type HandlerParams = {\n documentId: string;\n locale: string;\n status: 'published' | 'draft';\n};\n\n/**\n * @deprecated Use Core.Config.Admin['preview'] from @strapi/types instead\n * Keeping for backward compatibility\n */\nexport type PreviewConfig = NonNullable<Core.Config.Admin['preview']>;\n\n/**\n * Read configuration for static preview\n */\nconst createPreviewConfigService = ({ strapi }: { strapi: Core.Strapi }) => {\n return {\n register() {\n if (!this.isEnabled()) {\n return;\n }\n\n const config = strapi.config.get('admin.preview') as PreviewConfig;\n\n /**\n * Register the allowed origins for CSP, so the preview URL can be displayed\n */\n if (config.config?.allowedOrigins) {\n const middlewares = strapi.config.get('middlewares') as (\n
|
|
1
|
+
{"version":3,"file":"preview-config.mjs","sources":["../../../../server/src/preview/services/preview-config.ts"],"sourcesContent":["import type { Core } from '@strapi/types';\nimport { errors, extendMiddlewareConfiguration } from '@strapi/utils';\n\nexport type HandlerParams = {\n documentId: string;\n locale: string;\n status: 'published' | 'draft';\n};\n\n/**\n * @deprecated Use Core.Config.Admin['preview'] from @strapi/types instead\n * Keeping for backward compatibility\n */\nexport type PreviewConfig = NonNullable<Core.Config.Admin['preview']>;\n\n/**\n * Read configuration for static preview\n */\nconst createPreviewConfigService = ({ strapi }: { strapi: Core.Strapi }) => {\n return {\n register() {\n if (!this.isEnabled()) {\n return;\n }\n\n const config = strapi.config.get('admin.preview') as PreviewConfig;\n\n /**\n * Register the allowed origins for CSP, so the preview URL can be displayed\n */\n if (config.config?.allowedOrigins) {\n const middlewares = strapi.config.get('middlewares') as (\n string | { name?: string; config?: any }\n )[];\n\n const configuredMiddlewares = extendMiddlewareConfiguration(middlewares, {\n name: 'strapi::security',\n config: {\n contentSecurityPolicy: {\n directives: {\n 'frame-src': config.config.allowedOrigins,\n },\n },\n },\n });\n\n strapi.config.set('middlewares', configuredMiddlewares);\n }\n },\n\n isConfigured() {\n const config = strapi.config.get('admin.preview') as PreviewConfig;\n return config?.enabled === false || config?.config?.handler != null;\n },\n\n isEnabled() {\n const config = strapi.config.get('admin.preview') as PreviewConfig;\n\n if (!config) {\n return false;\n }\n\n return config?.enabled ?? true;\n },\n\n /**\n * Validate if the configuration is valid\n */\n validate() {\n if (!this.isEnabled()) {\n return;\n }\n\n const handler = this.getPreviewHandler();\n\n // Handler must be a function\n if (typeof handler !== 'function') {\n throw new errors.ValidationError(\n 'Preview configuration is invalid. Handler must be a function'\n );\n }\n },\n\n /**\n * Utility to get the preview handler from the configuration\n */\n getPreviewHandler(): NonNullable<Core.Config.Admin['preview']>['config']['handler'] {\n const emptyHandler = () => {\n return undefined;\n };\n\n if (!this.isEnabled()) {\n return emptyHandler;\n }\n\n const config = strapi.config.get('admin.preview') as PreviewConfig;\n\n return config?.config?.handler || emptyHandler;\n },\n };\n};\n\nexport { createPreviewConfigService };\n"],"names":["createPreviewConfigService","strapi","register","isEnabled","config","get","allowedOrigins","middlewares","configuredMiddlewares","extendMiddlewareConfiguration","name","contentSecurityPolicy","directives","set","isConfigured","enabled","handler","validate","getPreviewHandler","errors","ValidationError","emptyHandler","undefined"],"mappings":";;AAeA;;AAEC,IACD,MAAMA,0BAAAA,GAA6B,CAAC,EAAEC,MAAM,EAA2B,GAAA;IACrE,OAAO;AACLC,QAAAA,QAAAA,CAAAA,GAAAA;AACE,YAAA,IAAI,CAAC,IAAI,CAACC,SAAS,EAAA,EAAI;AACrB,gBAAA;AACF,YAAA;AAEA,YAAA,MAAMC,MAAAA,GAASH,MAAAA,CAAOG,MAAM,CAACC,GAAG,CAAC,eAA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AAe,CAC9B,8DAAA,CAAA;AAEJ,YAAA;AACF,QAAA,CAAA;AAEA;;QAGAF,iBAAAA,CAAAA,GAAAA;AACE,YAAA,MAAMG,YAAAA,GAAe,IAAA;gBACnB,OAAOC,SAAAA;AACT,YAAA,CAAA;AAEA,YAAA,IAAI,CAAC,IAAI,CAACnB,SAAS,EAAA,EAAI;gBACrB,OAAOkB,YAAAA;AACT,YAAA;AAEA,YAAA,MAAMjB,MAAAA,GAASH,MAAAA,CAAOG,MAAM,CAACC,GAAG,CAAC,eAAA,CAAA;YAEjC,OAAOD,MAAAA,EAAQA,QAAQY,OAAAA,IAAWK,YAAAA;AACpC,QAAA;AACF,KAAA;AACF;;;;"}
|
package/dist/server/register.js
CHANGED
|
@@ -2,8 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
var index = require('./history/index.js');
|
|
4
4
|
var index$1 = require('./preview/index.js');
|
|
5
|
+
var renameFields = require('./services/configuration/rename-fields.js');
|
|
5
6
|
|
|
6
7
|
const register = async ({ strapi })=>{
|
|
8
|
+
// Before user migrations run, so a generated rename migration can rewrite the
|
|
9
|
+
// saved layouts and leave the old-to-new map for each admin's browser.
|
|
10
|
+
strapi.db.schema.registerAttributeRenameHandler(renameFields.createContentManagerConfigurationRenamer({
|
|
11
|
+
strapi
|
|
12
|
+
}));
|
|
7
13
|
await index.register?.({
|
|
8
14
|
strapi
|
|
9
15
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register.js","sources":["../../server/src/register.ts"],"sourcesContent":["import type { Plugin } from '@strapi/types';\nimport history from './history';\nimport preview from './preview';\n\nconst register: Plugin.LoadedPlugin['register'] = async ({ strapi }) => {\n await history.register?.({ strapi });\n await preview.register?.({ strapi });\n};\n\nexport default register;\n"],"names":["register","strapi","history","preview"],"mappings":"
|
|
1
|
+
{"version":3,"file":"register.js","sources":["../../server/src/register.ts"],"sourcesContent":["import type { Plugin } from '@strapi/types';\nimport history from './history';\nimport preview from './preview';\nimport { createContentManagerConfigurationRenamer } from './services/configuration/rename-fields';\n\nconst register: Plugin.LoadedPlugin['register'] = async ({ strapi }) => {\n // Before user migrations run, so a generated rename migration can rewrite the\n // saved layouts and leave the old-to-new map for each admin's browser.\n strapi.db.schema.registerAttributeRenameHandler(\n createContentManagerConfigurationRenamer({ strapi })\n );\n\n await history.register?.({ strapi });\n await preview.register?.({ strapi });\n};\n\nexport default register;\n"],"names":["register","strapi","db","schema","registerAttributeRenameHandler","createContentManagerConfigurationRenamer","history","preview"],"mappings":";;;;;;AAKA,MAAMA,QAAAA,GAA4C,OAAO,EAAEC,MAAM,EAAE,GAAA;;;AAGjEA,IAAAA,MAAAA,CAAOC,EAAE,CAACC,MAAM,CAACC,8BAA8B,CAC7CC,qDAAAA,CAAyC;AAAEJ,QAAAA;AAAO,KAAA,CAAA,CAAA;IAGpD,MAAMK,KAAAA,CAAQN,QAAQ,GAAG;AAAEC,QAAAA;AAAO,KAAA,CAAA;IAClC,MAAMM,OAAAA,CAAQP,QAAQ,GAAG;AAAEC,QAAAA;AAAO,KAAA,CAAA;AACpC;;;;"}
|
package/dist/server/register.mjs
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import history from './history/index.mjs';
|
|
2
2
|
import preview from './preview/index.mjs';
|
|
3
|
+
import { createContentManagerConfigurationRenamer } from './services/configuration/rename-fields.mjs';
|
|
3
4
|
|
|
4
5
|
const register = async ({ strapi })=>{
|
|
6
|
+
// Before user migrations run, so a generated rename migration can rewrite the
|
|
7
|
+
// saved layouts and leave the old-to-new map for each admin's browser.
|
|
8
|
+
strapi.db.schema.registerAttributeRenameHandler(createContentManagerConfigurationRenamer({
|
|
9
|
+
strapi
|
|
10
|
+
}));
|
|
5
11
|
await history.register?.({
|
|
6
12
|
strapi
|
|
7
13
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register.mjs","sources":["../../server/src/register.ts"],"sourcesContent":["import type { Plugin } from '@strapi/types';\nimport history from './history';\nimport preview from './preview';\n\nconst register: Plugin.LoadedPlugin['register'] = async ({ strapi }) => {\n await history.register?.({ strapi });\n await preview.register?.({ strapi });\n};\n\nexport default register;\n"],"names":["register","strapi","history","preview"],"mappings":"
|
|
1
|
+
{"version":3,"file":"register.mjs","sources":["../../server/src/register.ts"],"sourcesContent":["import type { Plugin } from '@strapi/types';\nimport history from './history';\nimport preview from './preview';\nimport { createContentManagerConfigurationRenamer } from './services/configuration/rename-fields';\n\nconst register: Plugin.LoadedPlugin['register'] = async ({ strapi }) => {\n // Before user migrations run, so a generated rename migration can rewrite the\n // saved layouts and leave the old-to-new map for each admin's browser.\n strapi.db.schema.registerAttributeRenameHandler(\n createContentManagerConfigurationRenamer({ strapi })\n );\n\n await history.register?.({ strapi });\n await preview.register?.({ strapi });\n};\n\nexport default register;\n"],"names":["register","strapi","db","schema","registerAttributeRenameHandler","createContentManagerConfigurationRenamer","history","preview"],"mappings":";;;;AAKA,MAAMA,QAAAA,GAA4C,OAAO,EAAEC,MAAM,EAAE,GAAA;;;AAGjEA,IAAAA,MAAAA,CAAOC,EAAE,CAACC,MAAM,CAACC,8BAA8B,CAC7CC,wCAAAA,CAAyC;AAAEJ,QAAAA;AAAO,KAAA,CAAA,CAAA;IAGpD,MAAMK,OAAAA,CAAQN,QAAQ,GAAG;AAAEC,QAAAA;AAAO,KAAA,CAAA;IAClC,MAAMM,OAAAA,CAAQP,QAAQ,GAAG;AAAEC,QAAAA;AAAO,KAAA,CAAA;AACpC;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"components.js","sources":["../../../server/src/services/components.ts"],"sourcesContent":["import { mapValues } from 'lodash';\n\nimport type { UID, Struct, Core } from '@strapi/types';\nimport type { Configuration } from '../../../shared/contracts/content-types';\nimport type { ConfigurationUpdate } from './configuration';\n\nimport { getService } from '../utils';\nimport storeUtils from './utils/store';\nimport createConfigurationService from './configuration';\n\nconst STORE_KEY_PREFIX = 'components';\n\nconst configurationService = createConfigurationService({\n storeUtils,\n isComponent: true,\n prefix: STORE_KEY_PREFIX,\n getModels() {\n const { toContentManagerModel } = getService('data-mapper');\n\n return mapValues(strapi.components, (value) => toContentManagerModel(value));\n },\n});\n\nexport default ({ strapi }: { strapi: Core.Strapi }) => ({\n findAllComponents() {\n const { toContentManagerModel } = getService('data-mapper');\n\n return Object.values(strapi.components).map(toContentManagerModel);\n },\n\n findComponent(uid: UID.Component) {\n const { toContentManagerModel } = getService('data-mapper');\n\n const component = strapi.components[uid];\n\n return component == null ? component : toContentManagerModel(component);\n },\n\n async findConfiguration(component: Struct.ComponentSchema) {\n const configuration: Configuration = await configurationService.getConfiguration(component.uid);\n\n return {\n uid: component.uid,\n category: component.category,\n ...configuration,\n };\n },\n\n async updateConfiguration(\n component: Struct.ComponentSchema,\n newConfiguration: ConfigurationUpdate\n ) {\n await configurationService.setConfiguration(component.uid, newConfiguration);\n\n return this.findConfiguration(component);\n },\n\n /**\n * Batch load component configurations.\n *\n * Collects all component UIDs upfront, then loads configurations in a single\n * batch query instead of sequential queries per component.\n */\n async findComponentsConfigurations(model: Struct.ComponentSchema) {\n // Cache on request state so the same request can reuse configs\n const requestState = strapi.requestContext?.get?.()?.state as\n
|
|
1
|
+
{"version":3,"file":"components.js","sources":["../../../server/src/services/components.ts"],"sourcesContent":["import { mapValues } from 'lodash';\n\nimport type { UID, Struct, Core } from '@strapi/types';\nimport type { Configuration } from '../../../shared/contracts/content-types';\nimport type { ConfigurationUpdate } from './configuration';\n\nimport { getService } from '../utils';\nimport storeUtils from './utils/store';\nimport createConfigurationService from './configuration';\n\nconst STORE_KEY_PREFIX = 'components';\n\nconst configurationService = createConfigurationService({\n storeUtils,\n isComponent: true,\n prefix: STORE_KEY_PREFIX,\n getModels() {\n const { toContentManagerModel } = getService('data-mapper');\n\n return mapValues(strapi.components, (value) => toContentManagerModel(value));\n },\n});\n\nexport default ({ strapi }: { strapi: Core.Strapi }) => ({\n findAllComponents() {\n const { toContentManagerModel } = getService('data-mapper');\n\n return Object.values(strapi.components).map(toContentManagerModel);\n },\n\n findComponent(uid: UID.Component) {\n const { toContentManagerModel } = getService('data-mapper');\n\n const component = strapi.components[uid];\n\n return component == null ? component : toContentManagerModel(component);\n },\n\n async findConfiguration(component: Struct.ComponentSchema) {\n const configuration: Configuration = await configurationService.getConfiguration(component.uid);\n\n return {\n uid: component.uid,\n category: component.category,\n ...configuration,\n };\n },\n\n async updateConfiguration(\n component: Struct.ComponentSchema,\n newConfiguration: ConfigurationUpdate\n ) {\n await configurationService.setConfiguration(component.uid, newConfiguration);\n\n return this.findConfiguration(component);\n },\n\n /**\n * Batch load component configurations.\n *\n * Collects all component UIDs upfront, then loads configurations in a single\n * batch query instead of sequential queries per component.\n */\n async findComponentsConfigurations(model: Struct.ComponentSchema) {\n // Cache on request state so the same request can reuse configs\n const requestState = strapi.requestContext?.get?.()?.state as\n { __componentsConfigurationsCache?: Map<string, Record<string, Configuration>> } | undefined;\n const requestCache = requestState?.__componentsConfigurationsCache;\n\n const componentUids = new Set<UID.Component>();\n\n const collectComponentUids = (schema: Struct.ComponentSchema) => {\n for (const key of Object.keys(schema.attributes)) {\n const attribute = schema.attributes[key];\n\n if (attribute.type === 'component') {\n const uid = attribute.component;\n if (!componentUids.has(uid)) {\n componentUids.add(uid);\n const nestedComponent = this.findComponent(uid);\n if (nestedComponent) {\n collectComponentUids(nestedComponent);\n }\n }\n }\n\n if (attribute.type === 'dynamiczone') {\n for (const uid of attribute.components) {\n if (!componentUids.has(uid)) {\n componentUids.add(uid);\n const nestedComponent = this.findComponent(uid);\n if (nestedComponent) {\n collectComponentUids(nestedComponent);\n }\n }\n }\n }\n }\n };\n\n collectComponentUids(model);\n\n if (componentUids.size === 0) {\n return {};\n }\n\n // Key format must match configuration.ts uidToStoreKey: `${prefix}::${uid}`\n const uidsArray = Array.from(componentUids);\n const prefixedKeys = uidsArray.map((uid) => `components::${uid}`);\n const cacheKey = prefixedKeys.slice().sort().join('|');\n if (requestCache?.has(cacheKey)) {\n return requestCache.get(cacheKey)! as Record<\n string,\n Configuration & { category: string; isComponent: boolean }\n >;\n }\n\n const configs = await storeUtils.getModelConfigurations(prefixedKeys);\n\n const componentsMap: Record<\n string,\n Configuration & { category: string; isComponent: boolean }\n > = {};\n\n for (const uid of uidsArray) {\n const component = this.findComponent(uid);\n const configKey = `components::${uid}`;\n // Fallback must include proper layouts structure for frontend compatibility\n const configuration = configs[configKey] || {\n settings: {},\n metadatas: {},\n layouts: { list: [], edit: [] },\n };\n\n componentsMap[uid] = {\n uid: component.uid,\n category: component.category,\n ...configuration,\n };\n }\n\n if (requestState) {\n if (!requestState.__componentsConfigurationsCache) {\n requestState.__componentsConfigurationsCache = new Map();\n }\n requestState.__componentsConfigurationsCache.set(cacheKey, componentsMap);\n }\n\n return componentsMap;\n },\n\n syncConfigurations() {\n return configurationService.syncConfigurations();\n },\n});\n"],"names":["STORE_KEY_PREFIX","configurationService","createConfigurationService","storeUtils","isComponent","prefix","getModels","toContentManagerModel","getService","mapValues","strapi","components","value","findAllComponents","Object","values","map","findComponent","uid","component","findConfiguration","configuration","getConfiguration","category","updateConfiguration","newConfiguration","setConfiguration","findComponentsConfigurations","model","requestState","requestContext","get","state","requestCache","__componentsConfigurationsCache","componentUids","Set","collectComponentUids","schema","key","keys","attributes","attribute","type","has","add","nestedComponent","size","uidsArray","Array","from","prefixedKeys","cacheKey","slice","sort","join","configs","getModelConfigurations","componentsMap","configKey","settings","metadatas","layouts","list","edit","Map","set","syncConfigurations"],"mappings":";;;;;;;AAUA,MAAMA,gBAAAA,GAAmB,YAAA;AAEzB,MAAMC,uBAAuBC,aAAAA,CAA2B;AACtDC,gBAAAA,KAAAA;IACAC,WAAAA,EAAa,IAAA;IACbC,MAAAA,EAAQL,gBAAAA;AACRM,IAAAA,SAAAA,CAAAA,GAAAA;AACE,QAAA,MAAM,EAAEC,qBAAqB,EAAE,GAAGC,gBAAAA,CAAW,aAAA,CAAA;AAE7C,QAAA,OAAOC,YAAUC,MAAAA,CAA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CAACxC,IAAI,GAAG;AACnBA,oBAAAA,GAAAA,EAAKC,UAAUD,GAAG;AAClBK,oBAAAA,QAAAA,EAAUJ,UAAUI,QAAQ;AAC5B,oBAAA,GAAGF;AACL,iBAAA;AACF,YAAA;AAEA,YAAA,IAAIQ,YAAAA,EAAc;gBAChB,IAAI,CAACA,YAAAA,CAAaK,+BAA+B,EAAE;oBACjDL,YAAAA,CAAaK,+BAA+B,GAAG,IAAI+B,GAAAA,EAAAA;AACrD,gBAAA;AACApC,gBAAAA,YAAAA,CAAaK,+BAA+B,CAACgC,GAAG,CAACd,QAAAA,EAAUM,aAAAA,CAAAA;AAC7D,YAAA;YAEA,OAAOA,aAAAA;AACT,QAAA,CAAA;AAEAS,QAAAA,kBAAAA,CAAAA,GAAAA;AACE,YAAA,OAAOlE,qBAAqBkE,kBAAkB,EAAA;AAChD,QAAA;AACF,KAAA,CAAC;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"components.mjs","sources":["../../../server/src/services/components.ts"],"sourcesContent":["import { mapValues } from 'lodash';\n\nimport type { UID, Struct, Core } from '@strapi/types';\nimport type { Configuration } from '../../../shared/contracts/content-types';\nimport type { ConfigurationUpdate } from './configuration';\n\nimport { getService } from '../utils';\nimport storeUtils from './utils/store';\nimport createConfigurationService from './configuration';\n\nconst STORE_KEY_PREFIX = 'components';\n\nconst configurationService = createConfigurationService({\n storeUtils,\n isComponent: true,\n prefix: STORE_KEY_PREFIX,\n getModels() {\n const { toContentManagerModel } = getService('data-mapper');\n\n return mapValues(strapi.components, (value) => toContentManagerModel(value));\n },\n});\n\nexport default ({ strapi }: { strapi: Core.Strapi }) => ({\n findAllComponents() {\n const { toContentManagerModel } = getService('data-mapper');\n\n return Object.values(strapi.components).map(toContentManagerModel);\n },\n\n findComponent(uid: UID.Component) {\n const { toContentManagerModel } = getService('data-mapper');\n\n const component = strapi.components[uid];\n\n return component == null ? component : toContentManagerModel(component);\n },\n\n async findConfiguration(component: Struct.ComponentSchema) {\n const configuration: Configuration = await configurationService.getConfiguration(component.uid);\n\n return {\n uid: component.uid,\n category: component.category,\n ...configuration,\n };\n },\n\n async updateConfiguration(\n component: Struct.ComponentSchema,\n newConfiguration: ConfigurationUpdate\n ) {\n await configurationService.setConfiguration(component.uid, newConfiguration);\n\n return this.findConfiguration(component);\n },\n\n /**\n * Batch load component configurations.\n *\n * Collects all component UIDs upfront, then loads configurations in a single\n * batch query instead of sequential queries per component.\n */\n async findComponentsConfigurations(model: Struct.ComponentSchema) {\n // Cache on request state so the same request can reuse configs\n const requestState = strapi.requestContext?.get?.()?.state as\n
|
|
1
|
+
{"version":3,"file":"components.mjs","sources":["../../../server/src/services/components.ts"],"sourcesContent":["import { mapValues } from 'lodash';\n\nimport type { UID, Struct, Core } from '@strapi/types';\nimport type { Configuration } from '../../../shared/contracts/content-types';\nimport type { ConfigurationUpdate } from './configuration';\n\nimport { getService } from '../utils';\nimport storeUtils from './utils/store';\nimport createConfigurationService from './configuration';\n\nconst STORE_KEY_PREFIX = 'components';\n\nconst configurationService = createConfigurationService({\n storeUtils,\n isComponent: true,\n prefix: STORE_KEY_PREFIX,\n getModels() {\n const { toContentManagerModel } = getService('data-mapper');\n\n return mapValues(strapi.components, (value) => toContentManagerModel(value));\n },\n});\n\nexport default ({ strapi }: { strapi: Core.Strapi }) => ({\n findAllComponents() {\n const { toContentManagerModel } = getService('data-mapper');\n\n return Object.values(strapi.components).map(toContentManagerModel);\n },\n\n findComponent(uid: UID.Component) {\n const { toContentManagerModel } = getService('data-mapper');\n\n const component = strapi.components[uid];\n\n return component == null ? component : toContentManagerModel(component);\n },\n\n async findConfiguration(component: Struct.ComponentSchema) {\n const configuration: Configuration = await configurationService.getConfiguration(component.uid);\n\n return {\n uid: component.uid,\n category: component.category,\n ...configuration,\n };\n },\n\n async updateConfiguration(\n component: Struct.ComponentSchema,\n newConfiguration: ConfigurationUpdate\n ) {\n await configurationService.setConfiguration(component.uid, newConfiguration);\n\n return this.findConfiguration(component);\n },\n\n /**\n * Batch load component configurations.\n *\n * Collects all component UIDs upfront, then loads configurations in a single\n * batch query instead of sequential queries per component.\n */\n async findComponentsConfigurations(model: Struct.ComponentSchema) {\n // Cache on request state so the same request can reuse configs\n const requestState = strapi.requestContext?.get?.()?.state as\n { __componentsConfigurationsCache?: Map<string, Record<string, Configuration>> } | undefined;\n const requestCache = requestState?.__componentsConfigurationsCache;\n\n const componentUids = new Set<UID.Component>();\n\n const collectComponentUids = (schema: Struct.ComponentSchema) => {\n for (const key of Object.keys(schema.attributes)) {\n const attribute = schema.attributes[key];\n\n if (attribute.type === 'component') {\n const uid = attribute.component;\n if (!componentUids.has(uid)) {\n componentUids.add(uid);\n const nestedComponent = this.findComponent(uid);\n if (nestedComponent) {\n collectComponentUids(nestedComponent);\n }\n }\n }\n\n if (attribute.type === 'dynamiczone') {\n for (const uid of attribute.components) {\n if (!componentUids.has(uid)) {\n componentUids.add(uid);\n const nestedComponent = this.findComponent(uid);\n if (nestedComponent) {\n collectComponentUids(nestedComponent);\n }\n }\n }\n }\n }\n };\n\n collectComponentUids(model);\n\n if (componentUids.size === 0) {\n return {};\n }\n\n // Key format must match configuration.ts uidToStoreKey: `${prefix}::${uid}`\n const uidsArray = Array.from(componentUids);\n const prefixedKeys = uidsArray.map((uid) => `components::${uid}`);\n const cacheKey = prefixedKeys.slice().sort().join('|');\n if (requestCache?.has(cacheKey)) {\n return requestCache.get(cacheKey)! as Record<\n string,\n Configuration & { category: string; isComponent: boolean }\n >;\n }\n\n const configs = await storeUtils.getModelConfigurations(prefixedKeys);\n\n const componentsMap: Record<\n string,\n Configuration & { category: string; isComponent: boolean }\n > = {};\n\n for (const uid of uidsArray) {\n const component = this.findComponent(uid);\n const configKey = `components::${uid}`;\n // Fallback must include proper layouts structure for frontend compatibility\n const configuration = configs[configKey] || {\n settings: {},\n metadatas: {},\n layouts: { list: [], edit: [] },\n };\n\n componentsMap[uid] = {\n uid: component.uid,\n category: component.category,\n ...configuration,\n };\n }\n\n if (requestState) {\n if (!requestState.__componentsConfigurationsCache) {\n requestState.__componentsConfigurationsCache = new Map();\n }\n requestState.__componentsConfigurationsCache.set(cacheKey, componentsMap);\n }\n\n return componentsMap;\n },\n\n syncConfigurations() {\n return configurationService.syncConfigurations();\n },\n});\n"],"names":["STORE_KEY_PREFIX","configurationService","createConfigurationService","storeUtils","isComponent","prefix","getModels","toContentManagerModel","getService","mapValues","strapi","components","value","findAllComponents","Object","values","map","findComponent","uid","component","findConfiguration","configuration","getConfiguration","category","updateConfiguration","newConfiguration","setConfiguration","findComponentsConfigurations","model","requestState","requestContext","get","state","requestCache","__componentsConfigurationsCache","componentUids","Set","collectComponentUids","schema","key","keys","attributes","attribute","type","has","add","nestedComponent","size","uidsArray","Array","from","prefixedKeys","cacheKey","slice","sort","join","configs","getModelConfigurations","componentsMap","configKey","settings","metadatas","layouts","list","edit","Map","set","syncConfigurations"],"mappings":";;;;;AAUA,MAAMA,gBAAAA,GAAmB,YAAA;AAEzB,MAAMC,uBAAuBC,0BAAAA,CAA2B;AACtDC,IAAAA,UAAAA;IACAC,WAAAA,EAAa,IAAA;IACbC,MAAAA,EAAQL,gBAAAA;AACRM,IAAAA,SAAAA,CAAAA,GAAAA;AACE,QAAA,MAAM,EAAEC,qBAAqB,EAAE,GAAGC,UAAAA,CAAW,aAAA,CAAA;AAE7C,QAAA,OAAOC,UAAUC,MAAAA,CAAOC,UAAU,EAAE,CAACC,QAAUL,qBAAAA,CAAsBK,KAAAA,CAAAA,CAAAA;AACvE,IAAA;AACF,CAAA,CAAA;AAEA,iBAAe,CAAA,CAAC,EAAEF,QAAAA,OAAM,EAA2B,IAAM;AACvDG,QAAAA,iBAAAA,CAAAA,GAAAA;AACE,YAAA,MAAM,EAAEN,qBAAqB,EAAE,GAAGC,UAAAA,CAAW,aAAA,CAAA;AAE7C,YAAA,OAAOM,OAAOC,MAAM,CAACL,QAAOC,UAAU,CAAA,CAAEK,GAAG,CAACT,qBAAAA,CAAAA;AAC9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QAAAA,EAAUM,aAAAA,CAAAA;AAC7D,YAAA;YAEA,OAAOA,aAAAA;AACT,QAAA,CAAA;AAEAS,QAAAA,kBAAAA,CAAAA,GAAAA;AACE,YAAA,OAAOlE,qBAAqBkE,kBAAkB,EAAA;AAChD,QAAA;AACF,KAAA,CAAC;;;;"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _ = require('lodash');
|
|
4
|
+
var attributeRenames = require('../utils/configuration/attribute-renames.js');
|
|
5
|
+
|
|
6
|
+
const configurationKey = (prefix, uid)=>`configuration_${prefix}::${uid}`;
|
|
7
|
+
const isStoredConfiguration = (value)=>{
|
|
8
|
+
return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Carries attribute renames into the Content Manager configuration and records
|
|
12
|
+
* the old-to-new map for browsers that saved a column list under the old name.
|
|
13
|
+
*
|
|
14
|
+
* The list view stores its selected columns in localStorage. The server cannot
|
|
15
|
+
* edit that. The map is returned with the configuration, and the list view
|
|
16
|
+
* applies it before dropping a name the schema no longer has.
|
|
17
|
+
*/ const createContentManagerConfigurationRenamer = ({ strapi })=>{
|
|
18
|
+
return async (trx, renames)=>{
|
|
19
|
+
if (Object.keys(renames).length === 0) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
// Fresh database: the table is created by schema sync after the migrations.
|
|
23
|
+
if (!await strapi.db.getSchemaConnection(trx).hasTable('strapi_core_store_settings')) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const store = strapi.store({
|
|
27
|
+
type: 'plugin',
|
|
28
|
+
name: 'content_manager'
|
|
29
|
+
});
|
|
30
|
+
const models = [
|
|
31
|
+
...Object.entries(strapi.contentTypes).map(([uid, schema])=>({
|
|
32
|
+
uid,
|
|
33
|
+
prefix: 'content_types',
|
|
34
|
+
attributes: schema.attributes
|
|
35
|
+
})),
|
|
36
|
+
...Object.entries(strapi.components).map(([uid, schema])=>({
|
|
37
|
+
uid,
|
|
38
|
+
prefix: 'components',
|
|
39
|
+
attributes: schema.attributes
|
|
40
|
+
}))
|
|
41
|
+
];
|
|
42
|
+
for (const model of models){
|
|
43
|
+
const key = configurationKey(model.prefix, model.uid);
|
|
44
|
+
const current = await store.get({
|
|
45
|
+
key
|
|
46
|
+
});
|
|
47
|
+
const stored = isStoredConfiguration(current) ? current : null;
|
|
48
|
+
const next = attributeRenames.rewriteContentManagerConfiguration(stored, {
|
|
49
|
+
attributes: model.attributes,
|
|
50
|
+
ownRenames: renames[model.uid],
|
|
51
|
+
allRenames: renames
|
|
52
|
+
});
|
|
53
|
+
if (next && !next.uid) {
|
|
54
|
+
next.uid = model.uid;
|
|
55
|
+
}
|
|
56
|
+
if (!next || _.isEqual(next, current)) {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
await store.set({
|
|
60
|
+
key,
|
|
61
|
+
value: next
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
exports.createContentManagerConfigurationRenamer = createContentManagerConfigurationRenamer;
|
|
68
|
+
//# sourceMappingURL=rename-fields.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rename-fields.js","sources":["../../../../server/src/services/configuration/rename-fields.ts"],"sourcesContent":["import { isEqual } from 'lodash';\nimport type { Core, Struct } from '@strapi/types';\n\nimport {\n rewriteContentManagerConfiguration,\n type StoredConfiguration,\n} from '../utils/configuration/attribute-renames';\n\ntype AttributeRenameHandler = Parameters<\n Core.Strapi['db']['schema']['registerAttributeRenameHandler']\n>[0];\n\ntype AttributeRenames = Parameters<AttributeRenameHandler>[1];\n\nconst configurationKey = (prefix: 'content_types' | 'components', uid: string) =>\n `configuration_${prefix}::${uid}`;\n\nconst isStoredConfiguration = (value: unknown): value is StoredConfiguration => {\n return Boolean(value) && typeof value === 'object' && !Array.isArray(value);\n};\n\n/**\n * Carries attribute renames into the Content Manager configuration and records\n * the old-to-new map for browsers that saved a column list under the old name.\n *\n * The list view stores its selected columns in localStorage. The server cannot\n * edit that. The map is returned with the configuration, and the list view\n * applies it before dropping a name the schema no longer has.\n */\nconst createContentManagerConfigurationRenamer = ({\n strapi,\n}: {\n strapi: Core.Strapi;\n}): AttributeRenameHandler => {\n return async (trx, renames: AttributeRenames) => {\n if (Object.keys(renames).length === 0) {\n return;\n }\n\n // Fresh database: the table is created by schema sync after the migrations.\n if (!(await strapi.db.getSchemaConnection(trx).hasTable('strapi_core_store_settings'))) {\n return;\n }\n\n const store = strapi.store({ type: 'plugin', name: 'content_manager' });\n const models: Array<{\n uid: string;\n prefix: 'content_types' | 'components';\n attributes?: Struct.SchemaAttributes;\n }> = [\n ...Object.entries(strapi.contentTypes).map(([uid, schema]) => ({\n uid,\n prefix: 'content_types' as const,\n attributes: schema.attributes,\n })),\n ...Object.entries(strapi.components).map(([uid, schema]) => ({\n uid,\n prefix: 'components' as const,\n attributes: schema.attributes,\n })),\n ];\n\n for (const model of models) {\n const key = configurationKey(model.prefix, model.uid);\n const current = await store.get({ key });\n const stored = isStoredConfiguration(current) ? current : null;\n const next = rewriteContentManagerConfiguration(stored, {\n attributes: model.attributes as Record<string, { type?: string; target?: string }>,\n ownRenames: renames[model.uid],\n allRenames: renames,\n });\n\n if (next && !next.uid) {\n next.uid = model.uid;\n }\n\n if (!next || isEqual(next, current)) {\n continue;\n }\n\n await store.set({ key, value: next });\n }\n };\n};\n\nexport { createContentManagerConfigurationRenamer };\n"],"names":["configurationKey","prefix","uid","isStoredConfiguration","value","Boolean","Array","isArray","createContentManagerConfigurationRenamer","strapi","trx","renames","Object","keys","length","db","getSchemaConnection","hasTable","store","type","name","models","entries","contentTypes","map","schema","attributes","components","model","key","current","get","stored","next","rewriteContentManagerConfiguration","ownRenames","allRenames","isEqual","set"],"mappings":";;;;;AAcA,MAAMA,gBAAAA,GAAmB,CAACC,MAAAA,EAAwCC,GA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,UAAAA,EAAYD,OAAOC;iBACrB,CAAA;AACD,SAAA;QAED,KAAK,MAAME,SAASP,MAAAA,CAAQ;AAC1B,YAAA,MAAMQ,MAAM7B,gBAAAA,CAAiB4B,KAAAA,CAAM3B,MAAM,EAAE2B,MAAM1B,GAAG,CAAA;AACpD,YAAA,MAAM4B,OAAAA,GAAU,MAAMZ,KAAAA,CAAMa,GAAG,CAAC;AAAEF,gBAAAA;AAAI,aAAA,CAAA;YACtC,MAAMG,MAAAA,GAAS7B,qBAAAA,CAAsB2B,OAAAA,CAAAA,GAAWA,OAAAA,GAAU,IAAA;YAC1D,MAAMG,IAAAA,GAAOC,oDAAmCF,MAAAA,EAAQ;AACtDN,gBAAAA,UAAAA,EAAYE,MAAMF,UAAU;AAC5BS,gBAAAA,UAAAA,EAAYxB,OAAO,CAACiB,KAAAA,CAAM1B,GAAG,CAAC;gBAC9BkC,UAAAA,EAAYzB;AACd,aAAA,CAAA;AAEA,YAAA,IAAIsB,IAAAA,IAAQ,CAACA,IAAAA,CAAK/B,GAAG,EAAE;gBACrB+B,IAAAA,CAAK/B,GAAG,GAAG0B,KAAAA,CAAM1B,GAAG;AACtB,YAAA;AAEA,YAAA,IAAI,CAAC+B,IAAAA,IAAQI,SAAAA,CAAQJ,IAAAA,EAAMH,OAAAA,CAAAA,EAAU;AACnC,gBAAA;AACF,YAAA;YAEA,MAAMZ,KAAAA,CAAMoB,GAAG,CAAC;AAAET,gBAAAA,GAAAA;gBAAKzB,KAAAA,EAAO6B;AAAK,aAAA,CAAA;AACrC,QAAA;AACF,IAAA,CAAA;AACF;;;;"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { isEqual } from 'lodash';
|
|
2
|
+
import { rewriteContentManagerConfiguration } from '../utils/configuration/attribute-renames.mjs';
|
|
3
|
+
|
|
4
|
+
const configurationKey = (prefix, uid)=>`configuration_${prefix}::${uid}`;
|
|
5
|
+
const isStoredConfiguration = (value)=>{
|
|
6
|
+
return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Carries attribute renames into the Content Manager configuration and records
|
|
10
|
+
* the old-to-new map for browsers that saved a column list under the old name.
|
|
11
|
+
*
|
|
12
|
+
* The list view stores its selected columns in localStorage. The server cannot
|
|
13
|
+
* edit that. The map is returned with the configuration, and the list view
|
|
14
|
+
* applies it before dropping a name the schema no longer has.
|
|
15
|
+
*/ const createContentManagerConfigurationRenamer = ({ strapi })=>{
|
|
16
|
+
return async (trx, renames)=>{
|
|
17
|
+
if (Object.keys(renames).length === 0) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
// Fresh database: the table is created by schema sync after the migrations.
|
|
21
|
+
if (!await strapi.db.getSchemaConnection(trx).hasTable('strapi_core_store_settings')) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const store = strapi.store({
|
|
25
|
+
type: 'plugin',
|
|
26
|
+
name: 'content_manager'
|
|
27
|
+
});
|
|
28
|
+
const models = [
|
|
29
|
+
...Object.entries(strapi.contentTypes).map(([uid, schema])=>({
|
|
30
|
+
uid,
|
|
31
|
+
prefix: 'content_types',
|
|
32
|
+
attributes: schema.attributes
|
|
33
|
+
})),
|
|
34
|
+
...Object.entries(strapi.components).map(([uid, schema])=>({
|
|
35
|
+
uid,
|
|
36
|
+
prefix: 'components',
|
|
37
|
+
attributes: schema.attributes
|
|
38
|
+
}))
|
|
39
|
+
];
|
|
40
|
+
for (const model of models){
|
|
41
|
+
const key = configurationKey(model.prefix, model.uid);
|
|
42
|
+
const current = await store.get({
|
|
43
|
+
key
|
|
44
|
+
});
|
|
45
|
+
const stored = isStoredConfiguration(current) ? current : null;
|
|
46
|
+
const next = rewriteContentManagerConfiguration(stored, {
|
|
47
|
+
attributes: model.attributes,
|
|
48
|
+
ownRenames: renames[model.uid],
|
|
49
|
+
allRenames: renames
|
|
50
|
+
});
|
|
51
|
+
if (next && !next.uid) {
|
|
52
|
+
next.uid = model.uid;
|
|
53
|
+
}
|
|
54
|
+
if (!next || isEqual(next, current)) {
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
await store.set({
|
|
58
|
+
key,
|
|
59
|
+
value: next
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export { createContentManagerConfigurationRenamer };
|
|
66
|
+
//# sourceMappingURL=rename-fields.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rename-fields.mjs","sources":["../../../../server/src/services/configuration/rename-fields.ts"],"sourcesContent":["import { isEqual } from 'lodash';\nimport type { Core, Struct } from '@strapi/types';\n\nimport {\n rewriteContentManagerConfiguration,\n type StoredConfiguration,\n} from '../utils/configuration/attribute-renames';\n\ntype AttributeRenameHandler = Parameters<\n Core.Strapi['db']['schema']['registerAttributeRenameHandler']\n>[0];\n\ntype AttributeRenames = Parameters<AttributeRenameHandler>[1];\n\nconst configurationKey = (prefix: 'content_types' | 'components', uid: string) =>\n `configuration_${prefix}::${uid}`;\n\nconst isStoredConfiguration = (value: unknown): value is StoredConfiguration => {\n return Boolean(value) && typeof value === 'object' && !Array.isArray(value);\n};\n\n/**\n * Carries attribute renames into the Content Manager configuration and records\n * the old-to-new map for browsers that saved a column list under the old name.\n *\n * The list view stores its selected columns in localStorage. The server cannot\n * edit that. The map is returned with the configuration, and the list view\n * applies it before dropping a name the schema no longer has.\n */\nconst createContentManagerConfigurationRenamer = ({\n strapi,\n}: {\n strapi: Core.Strapi;\n}): AttributeRenameHandler => {\n return async (trx, renames: AttributeRenames) => {\n if (Object.keys(renames).length === 0) {\n return;\n }\n\n // Fresh database: the table is created by schema sync after the migrations.\n if (!(await strapi.db.getSchemaConnection(trx).hasTable('strapi_core_store_settings'))) {\n return;\n }\n\n const store = strapi.store({ type: 'plugin', name: 'content_manager' });\n const models: Array<{\n uid: string;\n prefix: 'content_types' | 'components';\n attributes?: Struct.SchemaAttributes;\n }> = [\n ...Object.entries(strapi.contentTypes).map(([uid, schema]) => ({\n uid,\n prefix: 'content_types' as const,\n attributes: schema.attributes,\n })),\n ...Object.entries(strapi.components).map(([uid, schema]) => ({\n uid,\n prefix: 'components' as const,\n attributes: schema.attributes,\n })),\n ];\n\n for (const model of models) {\n const key = configurationKey(model.prefix, model.uid);\n const current = await store.get({ key });\n const stored = isStoredConfiguration(current) ? current : null;\n const next = rewriteContentManagerConfiguration(stored, {\n attributes: model.attributes as Record<string, { type?: string; target?: string }>,\n ownRenames: renames[model.uid],\n allRenames: renames,\n });\n\n if (next && !next.uid) {\n next.uid = model.uid;\n }\n\n if (!next || isEqual(next, current)) {\n continue;\n }\n\n await store.set({ key, value: next });\n }\n };\n};\n\nexport { createContentManagerConfigurationRenamer };\n"],"names":["configurationKey","prefix","uid","isStoredConfiguration","value","Boolean","Array","isArray","createContentManagerConfigurationRenamer","strapi","trx","renames","Object","keys","length","db","getSchemaConnection","hasTable","store","type","name","models","entries","contentTypes","map","schema","attributes","components","model","key","current","get","stored","next","rewriteContentManagerConfiguration","ownRenames","allRenames","isEqual","set"],"mappings":";;;AAcA,MAAMA,gBAAAA,GAAmB,CAACC,MAAAA,EAAwCC,GAAAA,GAChE,CAAC,cAAc,EAAED,MAAAA,CAAO,EAAE,EAAEC,GAAAA,CAAAA,CAAK;AAEnC,MAAMC,wBAAwB,CAACC,KAAAA,GAAAA;IAC7B,OAAOC,OAAAA,CAAQD,UAAU,OAAOA,KAAAA,KAAU,YAAY,CAACE,KAAAA,CAAMC,OAAO,CAACH,KAAAA,CAAAA;AACvE,CAAA;AAEA;;;;;;;AAOC,IACD,MAAMI,wCAAAA,GAA2C,CAAC,EAChDC,MAAM,EAGP,GAAA;AACC,IAAA,OAAO,OAAOC,GAAAA,EAAKC,OAAAA,GAAAA;AACjB,QAAA,IAAIC,OAAOC,IAAI,CAACF,OAAAA,CAAAA,CAASG,MAAM,KAAK,CAAA,EAAG;AACrC,YAAA;AACF,QAAA;;QA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