@strapi/content-manager 5.58.0 → 5.60.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/history/components/VersionInputRenderer.js +2 -1
- package/dist/admin/history/components/VersionInputRenderer.js.map +1 -1
- package/dist/admin/history/components/VersionInputRenderer.mjs +2 -1
- package/dist/admin/history/components/VersionInputRenderer.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 +3 -2
- package/dist/admin/pages/EditView/components/FormInputs/Component/NonRepeatable.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Component/NonRepeatable.mjs +3 -2
- package/dist/admin/pages/EditView/components/FormInputs/Component/NonRepeatable.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Component/Repeatable.js +8 -6
- package/dist/admin/pages/EditView/components/FormInputs/Component/Repeatable.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Component/Repeatable.mjs +8 -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 +6 -3
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/DynamicComponent.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/DynamicComponent.mjs +6 -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 +4 -4
- package/dist/admin/pages/EditView/components/FormInputs/Relations/Relations.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Relations/Relations.mjs +4 -4
- 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 +5 -4
- package/dist/admin/pages/EditView/components/FormLayout.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormLayout.mjs +5 -4
- package/dist/admin/pages/EditView/components/FormLayout.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/InputRenderer.js +3 -1
- package/dist/admin/pages/EditView/components/InputRenderer.js.map +1 -1
- package/dist/admin/pages/EditView/components/InputRenderer.mjs +3 -1
- package/dist/admin/pages/EditView/components/InputRenderer.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/preview/components/PreviewSidePanel.js +2 -1
- package/dist/admin/preview/components/PreviewSidePanel.js.map +1 -1
- package/dist/admin/preview/components/PreviewSidePanel.mjs +2 -1
- package/dist/admin/preview/components/PreviewSidePanel.mjs.map +1 -1
- package/dist/admin/preview/utils/getPreviewUrlStatus.js +17 -0
- package/dist/admin/preview/utils/getPreviewUrlStatus.js.map +1 -0
- package/dist/admin/preview/utils/getPreviewUrlStatus.mjs +15 -0
- package/dist/admin/preview/utils/getPreviewUrlStatus.mjs.map +1 -0
- package/dist/admin/services/relations.js +2 -2
- package/dist/admin/services/relations.js.map +1 -1
- package/dist/admin/services/relations.mjs +2 -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/history/components/VersionInputRenderer.d.ts +3 -1
- package/dist/admin/src/pages/EditView/components/InputRenderer.d.ts +2 -0
- package/dist/admin/src/pages/ListView/utils/applyAttributeRenames.d.ts +12 -0
- package/dist/admin/src/preview/utils/getPreviewUrlStatus.d.ts +6 -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/controllers/relations.js +48 -16
- package/dist/server/controllers/relations.js.map +1 -1
- package/dist/server/controllers/relations.mjs +49 -17
- package/dist/server/controllers/relations.mjs.map +1 -1
- package/dist/server/history/services/history.js +1 -1
- package/dist/server/history/services/history.js.map +1 -1
- package/dist/server/history/services/history.mjs +1 -1
- package/dist/server/history/services/history.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/mcp/schemas/filters-schema.js +10 -2
- package/dist/server/mcp/schemas/filters-schema.js.map +1 -1
- package/dist/server/mcp/schemas/filters-schema.mjs +10 -2
- package/dist/server/mcp/schemas/filters-schema.mjs.map +1 -1
- package/dist/server/preview/controllers/validation/preview.js +1 -1
- package/dist/server/preview/controllers/validation/preview.js.map +1 -1
- package/dist/server/preview/controllers/validation/preview.mjs +2 -2
- package/dist/server/preview/controllers/validation/preview.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/document-metadata.js +1 -1
- package/dist/server/services/document-metadata.js.map +1 -1
- package/dist/server/services/document-metadata.mjs +1 -1
- package/dist/server/services/document-metadata.mjs.map +1 -1
- 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/controllers/relations.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/mcp/schemas/filters-schema.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/package.json +7 -7
|
@@ -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,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;;QAGA,IAAI,CAAE,MAAML,MAAAA,CAAOM,EAAE,CAACC,mBAAmB,CAACN,GAAAA,CAAAA,CAAKO,QAAQ,CAAC,4BAAA,CAAA,EAAgC;AACtF,YAAA;AACF,QAAA;QAEA,MAAMC,KAAAA,GAAQT,MAAAA,CAAOS,KAAK,CAAC;YAAEC,IAAAA,EAAM,QAAA;YAAUC,IAAAA,EAAM;AAAkB,SAA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,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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AAA;AACRyB,oBAAAA,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,mCAAmCF,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,OAAAA,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;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"document-metadata.js","sources":["../../../server/src/services/document-metadata.ts"],"sourcesContent":["import { groupBy, pick } from 'lodash';\n\nimport { async, contentTypes } from '@strapi/utils';\nimport type { Core, UID, Modules } from '@strapi/types';\n\nimport type { DocumentMetadata } from '../../../shared/contracts/collection-types';\n\nconst { getScalarAttributes, getMediaAttributes } = contentTypes;\n\nexport interface DocumentVersion {\n id: string | number;\n documentId: Modules.Documents.ID;\n locale?: string;\n localizations?: DocumentVersion[];\n updatedAt?: string | null | Date;\n publishedAt?: string | null | Date;\n}\n\n// Scalar fields that can be used in a DB `select`\nconst AVAILABLE_STATUS_SCALAR_FIELDS = [\n 'id',\n 'documentId',\n 'locale',\n 'updatedAt',\n 'createdAt',\n 'publishedAt',\n];\n// Relation populate shared by both the fast path and the full path\nconst AVAILABLE_STATUS_POPULATE = {\n createdBy: { select: ['id', 'firstname', 'lastname', 'email'] },\n updatedBy: { select: ['id', 'firstname', 'lastname', 'email'] },\n};\n// All fields to pick from a hydrated result (scalars + populated relations + virtual)\nconst AVAILABLE_STATUS_FIELDS = [\n ...AVAILABLE_STATUS_SCALAR_FIELDS,\n 'createdBy',\n 'updatedBy',\n 'status',\n];\nconst AVAILABLE_LOCALES_FIELDS = [\n 'id',\n 'documentId',\n 'locale',\n 'updatedAt',\n 'createdAt',\n 'publishedAt',\n];\n\n/** Returns a DB filter that matches the opposite publish status. */\nconst oppositePublishStatus = (publishedAt: unknown) =>\n publishedAt !== null ? { $null: true } : { $notNull: true };\n\nconst CONTENT_MANAGER_STATUS = {\n PUBLISHED: 'published',\n DRAFT: 'draft',\n MODIFIED: 'modified',\n};\n\n/**\n * Controls the metadata properties to be returned\n *\n * If `availableLocales` is set to `true` (default), the returned metadata will include\n * the available locales of the document for its current status.\n *\n * If `availableStatus` is set to `true` (default), the returned metadata will include\n * the available status of the document for its current locale.\n */\nexport interface GetMetadataOptions {\n availableLocales?: boolean;\n availableStatus?: boolean;\n}\n\n/**\n * Checks if the provided document version has been modified after all other versions.\n */\nconst getIsVersionLatestModification = (\n version?: DocumentVersion,\n otherVersion?: DocumentVersion\n): boolean => {\n if (!version || !version.updatedAt) {\n return false;\n }\n\n const versionUpdatedAt = version?.updatedAt ? new Date(version.updatedAt).getTime() : 0;\n\n const otherUpdatedAt = otherVersion?.updatedAt ? new Date(otherVersion.updatedAt).getTime() : 0;\n\n return versionUpdatedAt > otherUpdatedAt;\n};\n\nexport default ({ strapi }: { strapi: Core.Strapi }) => ({\n /**\n * Returns available locales of a document for the current status.\n *\n * The result is sorted with the default locale (as defined by the i18n plugin)\n * at index 0 when present. This is the canonical-source invariant relied on by\n * `useDocument.getInitialFormValues` in the admin: when creating a new locale\n * draft, non-localized scalar/media values are inherited from\n * `availableLocales[0]`. Putting the default locale first means inheritance\n * stays predictable when sibling locales have drifted on non-localized fields\n * (which can happen because the server only syncs non-localized fields at\n * locale-creation time, not on subsequent updates — see\n * `copyNonLocalizedFields` in document-service/internationalization.ts).\n */\n async getAvailableLocales(\n uid: UID.ContentType,\n version: DocumentVersion,\n allVersions: DocumentVersion[]\n ) {\n // Group all versions by locale\n const versionsByLocale = groupBy(allVersions, 'locale');\n\n // Delete the current locale\n if (version.locale) {\n delete versionsByLocale[version.locale];\n }\n\n // For each locale, get the ones with the same status\n // There will not be a draft and a version counterpart if the content\n // type does not have draft and publish\n const model = strapi.getModel(uid);\n\n const mappingResult = await async.map(\n Object.values(versionsByLocale),\n async (localeVersions: DocumentVersion[]) => {\n if (!contentTypes.hasDraftAndPublish(model)) {\n return localeVersions[0];\n }\n\n const draftVersion = localeVersions.find((v) => v.publishedAt === null);\n const otherVersions = localeVersions.filter((v) => v.id !== draftVersion?.id);\n\n if (!draftVersion) {\n return;\n }\n\n return {\n ...draftVersion,\n status: this.getStatus(draftVersion, otherVersions as any),\n };\n }\n );\n\n const filtered = mappingResult.filter(Boolean) as unknown as NonNullable<\n DocumentMetadata['availableLocales']\n >;\n\n // Sort the default locale first so `availableLocales[0]` is the canonical\n // source for non-localized field inheritance in the admin. Without a\n // localization provider there is no default locale and the order is kept.\n let defaultLocaleCode: string | null | undefined = null;\n try {\n defaultLocaleCode = await strapi.localization.getDefaultLocale();\n } catch {\n // The provider (e.g. its locale store lookup) errored — leave order untouched.\n }\n\n // The provider may resolve `undefined` at runtime when no default locale is stored\n if (defaultLocaleCode === null || defaultLocaleCode === undefined || defaultLocaleCode === '') {\n return filtered as DocumentMetadata['availableLocales'];\n }\n\n // Stable partition: move the default locale entry to the front, keep the\n // rest of the order intact.\n const defaultEntries = filtered.filter((entry) => entry.locale === defaultLocaleCode);\n const otherEntries = filtered.filter((entry) => entry.locale !== defaultLocaleCode);\n\n return [...defaultEntries, ...otherEntries] as DocumentMetadata['availableLocales'];\n },\n\n /**\n * Returns available status of a document for the current locale\n */\n getAvailableStatus(version: DocumentVersion, allVersions: DocumentVersion[]) {\n // Find the other status of the document\n const status =\n version.publishedAt !== null\n ? CONTENT_MANAGER_STATUS.DRAFT\n : CONTENT_MANAGER_STATUS.PUBLISHED;\n\n // Get version that match the current locale and not match the current status\n const availableStatus = allVersions.find((v) => {\n const matchLocale = v.locale === version.locale;\n const matchStatus = status === 'published' ? v.publishedAt !== null : v.publishedAt === null;\n return matchLocale && matchStatus;\n });\n\n if (!availableStatus) return availableStatus;\n\n // Pick status fields (at fields, status, by fields), use lodash\n return pick(availableStatus, AVAILABLE_STATUS_FIELDS);\n },\n\n /**\n * Get the available status of many documents, useful for batch operations\n * @param uid\n * @param documents\n * @returns\n */\n async getManyAvailableStatus(uid: UID.ContentType, documents: DocumentVersion[]) {\n if (!documents.length) return [];\n\n // The status and locale of all documents should be the same\n const status = documents[0].publishedAt !== null ? 'published' : 'draft';\n const locales = documents.map((d) => d.locale).filter(Boolean);\n\n const where: Record<string, any> = {\n documentId: { $in: documents.map((d) => d.documentId).filter(Boolean) },\n publishedAt: { $null: status === 'published' },\n };\n\n // If there is any locale to filter (if i18n is enabled)\n if (locales.length === documents.length) {\n where.locale = { $in: locales };\n } else if (locales.length) {\n /*\n * The batch mixes localized and non-localized versions, which happens when a\n * content type holds rows with a locale while others have none — for instance\n * after i18n is disabled on it, or when a locale is sent to a non-localized\n * content type through the API.\n *\n * `locales` only holds the locales that are actually set, so filtering on it\n * alone would drop the counterparts of every version whose locale is null, and\n * those versions would be reported as drafts even though they are published.\n */\n where.$or = [{ locale: { $in: locales } }, { locale: { $null: true } }];\n }\n\n return strapi.query(uid).findMany({\n where,\n select: AVAILABLE_STATUS_SCALAR_FIELDS,\n });\n },\n\n getStatus(version: DocumentVersion, otherDocumentStatuses?: DocumentMetadata['availableStatus']) {\n let draftVersion: DocumentVersion | undefined;\n let publishedVersion: DocumentVersion | undefined;\n\n if (version.publishedAt) {\n publishedVersion = version;\n } else {\n draftVersion = version;\n }\n\n const otherVersion = otherDocumentStatuses?.at(0);\n if (otherVersion?.publishedAt) {\n publishedVersion = otherVersion;\n } else if (otherVersion) {\n draftVersion = otherVersion;\n }\n\n if (!draftVersion) return CONTENT_MANAGER_STATUS.PUBLISHED;\n if (!publishedVersion) return CONTENT_MANAGER_STATUS.DRAFT;\n\n /*\n * The document is modified if the draft version has been updated more\n * recently than the published version.\n */\n const isDraftModified = getIsVersionLatestModification(draftVersion, publishedVersion);\n return isDraftModified ? CONTENT_MANAGER_STATUS.MODIFIED : CONTENT_MANAGER_STATUS.PUBLISHED;\n },\n\n // TODO is it necessary to return metadata on every page of the CM\n // We could refactor this so the locales are only loaded when they're\n // needed. e.g. in the bulk locale action modal.\n async getMetadata(\n uid: UID.ContentType,\n version: DocumentVersion,\n { availableLocales = true, availableStatus = true }: GetMetadataOptions = {}\n ) {\n const model = strapi.getModel(uid);\n const hasDnP = contentTypes.hasDraftAndPublish(model);\n const isLocalized = strapi.localization.isLocalizedContentType(model);\n\n if (!availableLocales && !availableStatus) {\n // Nothing to compute.\n return { availableLocales: [], availableStatus: [], versions: [] as DocumentVersion[] };\n }\n if (!isLocalized && !hasDnP) {\n // If there are no locales and no draft/publish, there's only ever 1 version of any document.\n return { availableLocales: [], availableStatus: [], versions: [] as DocumentVersion[] };\n }\n\n const onlyStatusIsRelevant = hasDnP && (!isLocalized || !availableLocales);\n if (onlyStatusIsRelevant) {\n const otherVersion = availableStatus\n ? await strapi.db.query(uid).findOne({\n where: {\n documentId: version.documentId,\n ...(version.locale ? { locale: version.locale } : {}),\n publishedAt: oppositePublishStatus(version.publishedAt),\n },\n select: AVAILABLE_STATUS_SCALAR_FIELDS,\n populate: AVAILABLE_STATUS_POPULATE,\n })\n : null;\n return {\n availableLocales: [],\n availableStatus: otherVersion ? [pick(otherVersion, AVAILABLE_STATUS_FIELDS)] : [],\n versions: [] as DocumentVersion[],\n };\n }\n\n // Full path for localized content types\n // TODO: Ignore publishedAt if availableStatus=false, and ignore locale if\n // i18n is disabled\n\n // Include non-translatable scalar and media fields in availableLocales for i18n prefilling\n let nonLocalizedFields: string[] = [];\n let nonLocalizedMediaFields: string[] = [];\n // Without a localization provider there are no non-localized attributes.\n try {\n if (model?.attributes !== undefined) {\n const allNonLocalized = strapi.localization.getNonLocalizedAttributes(model);\n // Get scalar and media attributes separately\n const scalarAttrs = getScalarAttributes(model);\n const mediaAttrs = getMediaAttributes(model);\n\n // Separate scalar fields (can be in fields array) from media fields (need to be populated)\n nonLocalizedFields = allNonLocalized.filter(\n (field) => field in model.attributes && scalarAttrs.includes(field)\n );\n nonLocalizedMediaFields = allNonLocalized.filter(\n (field) => field in model.attributes && mediaAttrs.includes(field)\n );\n }\n } catch {\n // The provider errored — fall back to no prefilled non-localized fields\n }\n\n // Build populate object for non-localized media fields\n const mediaPopulate = nonLocalizedMediaFields.reduce(\n (acc, field) => {\n acc[field] = {\n populate: {\n folder: true,\n },\n };\n return acc;\n },\n {} as Record<string, { populate: { folder: boolean } }>\n );\n\n const params = {\n populate: {\n ...mediaPopulate,\n ...AVAILABLE_STATUS_POPULATE,\n },\n fields: [...new Set([...AVAILABLE_LOCALES_FIELDS, ...nonLocalizedFields])],\n filters: {\n documentId: version.documentId,\n },\n };\n\n const dbParams = strapi.get('query-params').transform(uid, params);\n const versions = await strapi.db.query(uid).findMany(dbParams);\n\n // TODO: Remove use of available locales and use localizations instead\n const availableLocalesResult = availableLocales\n ? await this.getAvailableLocales(uid, version, versions)\n : [];\n\n const availableStatusResult = availableStatus\n ? this.getAvailableStatus(version, versions)\n : null;\n\n return {\n availableLocales: availableLocalesResult,\n availableStatus: availableStatusResult ? [availableStatusResult] : [],\n versions,\n };\n },\n\n /**\n * Returns associated metadata of a document:\n * - Available locales of the document for the current status\n * - Available status of the document for the current locale\n */\n async formatDocumentWithMetadata(\n uid: UID.ContentType,\n document: DocumentVersion,\n opts: GetMetadataOptions = {}\n ) {\n if (!document) {\n return {\n data: document,\n meta: {\n availableLocales: [],\n availableStatus: [],\n },\n };\n }\n\n const hasDraftAndPublish = contentTypes.hasDraftAndPublish(strapi.getModel(uid));\n\n // Ignore available status if the content type does not have draft and publish\n if (!hasDraftAndPublish) {\n opts.availableStatus = false;\n }\n\n const { versions, ...meta } = await this.getMetadata(uid, document, opts);\n\n // Populate localization statuses\n if (document.localizations?.length) {\n document.localizations = document.localizations.map((d) => {\n // Find the counterpart version (same documentId + locale, opposite publishedAt) from\n // the already-fetched versions array, avoiding an extra DB query.\n const counterpart = versions.find(\n (v) =>\n v.documentId === d.documentId &&\n v.locale === d.locale &&\n (d.publishedAt === null) !== (v.publishedAt === null)\n );\n return {\n ...d,\n status: this.getStatus(d, counterpart ? [counterpart] : []),\n };\n });\n }\n\n return {\n data: {\n ...document,\n // Add status to the document only if draft and publish is enabled\n status: hasDraftAndPublish\n ? this.getStatus(document, meta.availableStatus as any)\n : undefined,\n },\n meta,\n };\n },\n});\n"],"names":["getScalarAttributes","getMediaAttributes","contentTypes","AVAILABLE_STATUS_SCALAR_FIELDS","AVAILABLE_STATUS_POPULATE","createdBy","select","updatedBy","AVAILABLE_STATUS_FIELDS","AVAILABLE_LOCALES_FIELDS","oppositePublishStatus","publishedAt","$null","$notNull","CONTENT_MANAGER_STATUS","PUBLISHED","DRAFT","MODIFIED","getIsVersionLatestModification","version","otherVersion","updatedAt","versionUpdatedAt","Date","getTime","otherUpdatedAt","strapi","getAvailableLocales","uid","allVersions","versionsByLocale","groupBy","locale","model","getModel","mappingResult","async","map","Object","values","localeVersions","hasDraftAndPublish","draftVersion","find","v","otherVersions","filter","id","status","getStatus","filtered","Boolean","defaultLocaleCode","localization","getDefaultLocale","undefined","defaultEntries","entry","otherEntries","getAvailableStatus","availableStatus","matchLocale","matchStatus","pick","getManyAvailableStatus","documents","length","locales","d","where","documentId","$in","$or","query","findMany","otherDocumentStatuses","publishedVersion","at","isDraftModified","getMetadata","availableLocales","hasDnP","isLocalized","isLocalizedContentType","versions","onlyStatusIsRelevant","db","findOne","populate","nonLocalizedFields","nonLocalizedMediaFields","attributes","allNonLocalized","getNonLocalizedAttributes","scalarAttrs","mediaAttrs","field","includes","mediaPopulate","reduce","acc","folder","params","fields","Set","filters","dbParams","get","transform","availableLocalesResult","availableStatusResult","formatDocumentWithMetadata","document","opts","data","meta","localizations","counterpart"],"mappings":";;;;;AAOA,MAAM,EAAEA,mBAAmB,EAAEC,kBAAkB,EAAE,GAAGC,wBAAAA;AAWpD;AACA,MAAMC,8BAAAA,GAAiC;AACrC,IAAA,IAAA;AACA,IAAA,YAAA;AACA,IAAA,QAAA;AACA,IAAA,WAAA;AACA,IAAA,WAAA;AACA,IAAA;AACD,CAAA;AACD;AACA,MAAMC,yBAAAA,GAA4B;IAChCC,SAAAA,EAAW;QAAEC,MAAAA,EAAQ;AAAC,YAAA,IAAA;AAAM,YAAA,WAAA;AAAa,YAAA,UAAA;AAAY,YAAA;AAAQ;AAAC,KAAA;IAC9DC,SAAAA,EAAW;QAAED,MAAAA,EAAQ;AAAC,YAAA,IAAA;AAAM,YAAA,WAAA;AAAa,YAAA,UAAA;AAAY,YAAA;AAAQ;AAAC;AAChE,CAAA;AACA;AACA,MAAME,uBAAAA,GAA0B;AAC3BL,IAAAA,GAAAA,8BAAAA;AACH,IAAA,WAAA;AACA,IAAA,WAAA;AACA,IAAA;AACD,CAAA;AACD,MAAMM,wBAAAA,GAA2B;AAC/B,IAAA,IAAA;AACA,IAAA,YAAA;AACA,IAAA,QAAA;AACA,IAAA,WAAA;AACA,IAAA,WAAA;AACA,IAAA;AACD,CA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CAAEE,UAAU,IAC7B1B,CAAAA,CAAEZ,MAAM,KAAKoC,CAAAA,CAAEpC,MAAM,IACpBoC,CAAAA,CAAEzD,WAAW,KAAK,IAAA,MAAWiC,CAAAA,CAAEjC,WAAW,KAAK,IAAG,CAAA,CAAA;oBAEvD,OAAO;AACL,wBAAA,GAAGyD,CAAC;AACJpB,wBAAAA,MAAAA,EAAQ,IAAI,CAACC,SAAS,CAACmB,GAAGiD,WAAAA,GAAc;AAACA,4BAAAA;AAAY,yBAAA,GAAG,EAAE;AAC5D,qBAAA;AACF,gBAAA,CAAA,CAAA;AACF,YAAA;YAEA,OAAO;gBACLH,IAAAA,EAAM;AACJ,oBAAA,GAAGF,QAAQ;;oBAEXhE,MAAAA,EAAQP,kBAAAA,GACJ,IAAI,CAACQ,SAAS,CAAC+D,QAAAA,EAAUG,IAAAA,CAAKvD,eAAe,CAAA,GAC7CL;AACN,iBAAA;AACA4D,gBAAAA;AACF,aAAA;AACF,QAAA;AACF,KAAA,CAAC;;;;"}
|
|
1
|
+
{"version":3,"file":"document-metadata.js","sources":["../../../server/src/services/document-metadata.ts"],"sourcesContent":["import { groupBy, pick } from 'lodash';\n\nimport { async, contentTypes } from '@strapi/utils';\nimport type { Core, UID, Modules } from '@strapi/types';\n\nimport type { DocumentMetadata } from '../../../shared/contracts/collection-types';\n\nconst { getScalarAttributes, getMediaAttributes } = contentTypes;\n\nexport interface DocumentVersion {\n id: string | number;\n documentId: Modules.Documents.ID;\n locale?: string;\n localizations?: DocumentVersion[];\n updatedAt?: string | null | Date;\n publishedAt?: string | null | Date;\n}\n\n// Scalar fields that can be used in a DB `select`\nconst AVAILABLE_STATUS_SCALAR_FIELDS = [\n 'id',\n 'documentId',\n 'locale',\n 'updatedAt',\n 'createdAt',\n 'publishedAt',\n];\n// Relation populate shared by both the fast path and the full path\nconst AVAILABLE_STATUS_POPULATE = {\n createdBy: { select: ['id', 'firstname', 'lastname', 'email'] },\n updatedBy: { select: ['id', 'firstname', 'lastname', 'email'] },\n};\n// All fields to pick from a hydrated result (scalars + populated relations + virtual)\nconst AVAILABLE_STATUS_FIELDS = [\n ...AVAILABLE_STATUS_SCALAR_FIELDS,\n 'createdBy',\n 'updatedBy',\n 'status',\n];\nconst AVAILABLE_LOCALES_FIELDS = [\n 'id',\n 'documentId',\n 'locale',\n 'updatedAt',\n 'createdAt',\n 'publishedAt',\n];\n\n/** Returns a DB filter that matches the opposite publish status. */\nconst oppositePublishStatus = (publishedAt: unknown) =>\n publishedAt !== null ? { $null: true } : { $notNull: true };\n\nconst CONTENT_MANAGER_STATUS = {\n PUBLISHED: 'published',\n DRAFT: 'draft',\n MODIFIED: 'modified',\n};\n\n/**\n * Controls the metadata properties to be returned\n *\n * If `availableLocales` is set to `true` (default), the returned metadata will include\n * the available locales of the document for its current status.\n *\n * If `availableStatus` is set to `true` (default), the returned metadata will include\n * the available status of the document for its current locale.\n */\nexport interface GetMetadataOptions {\n availableLocales?: boolean;\n availableStatus?: boolean;\n}\n\n/**\n * Checks if the provided document version has been modified after all other versions.\n */\nconst getIsVersionLatestModification = (\n version?: DocumentVersion,\n otherVersion?: DocumentVersion\n): boolean => {\n if (!version || !version.updatedAt) {\n return false;\n }\n\n const versionUpdatedAt = version?.updatedAt ? new Date(version.updatedAt).getTime() : 0;\n\n const otherUpdatedAt = otherVersion?.updatedAt ? new Date(otherVersion.updatedAt).getTime() : 0;\n\n return versionUpdatedAt > otherUpdatedAt;\n};\n\nexport default ({ strapi }: { strapi: Core.Strapi }) => ({\n /**\n * Returns available locales of a document for the current status.\n *\n * The result is sorted with the default locale (as defined by the i18n plugin)\n * at index 0 when present. This is the canonical-source invariant relied on by\n * `useDocument.getInitialFormValues` in the admin: when creating a new locale\n * draft, non-localized scalar/media values are inherited from\n * `availableLocales[0]`. Putting the default locale first means inheritance\n * stays predictable when sibling locales have drifted on non-localized fields\n * (which can happen because the server only syncs non-localized fields at\n * locale-creation time, not on subsequent updates — see\n * `copyNonLocalizedFields` in document-service/internationalization.ts).\n */\n async getAvailableLocales(\n uid: UID.ContentType,\n version: DocumentVersion,\n allVersions: DocumentVersion[]\n ) {\n // Group all versions by locale\n const versionsByLocale = groupBy(allVersions, 'locale');\n\n // Delete the current locale\n if (version.locale) {\n delete versionsByLocale[version.locale];\n }\n\n // For each locale, get the ones with the same status\n // There will not be a draft and a version counterpart if the content\n // type does not have draft and publish\n const model = strapi.getModel(uid);\n\n const mappingResult = await async.map(\n Object.values(versionsByLocale),\n async (localeVersions: DocumentVersion[]) => {\n if (!contentTypes.hasDraftAndPublish(model)) {\n return localeVersions[0];\n }\n\n const draftVersion = localeVersions.find((v) => v.publishedAt === null);\n const otherVersions = localeVersions.filter((v) => v.id !== draftVersion?.id);\n\n if (!draftVersion) {\n return;\n }\n\n return {\n ...draftVersion,\n status: this.getStatus(draftVersion, otherVersions as any),\n };\n }\n );\n\n const filtered = mappingResult.filter(Boolean) as unknown as NonNullable<\n DocumentMetadata['availableLocales']\n >;\n\n // Sort the default locale first so `availableLocales[0]` is the canonical\n // source for non-localized field inheritance in the admin. Without a\n // localization provider there is no default locale and the order is kept.\n let defaultLocaleCode: string | null | undefined = null;\n try {\n defaultLocaleCode = await strapi.localization.getDefaultLocale();\n } catch {\n // The provider (e.g. its locale store lookup) errored — leave order untouched.\n }\n\n // The provider may resolve `undefined` at runtime when no default locale is stored\n if (defaultLocaleCode === null || defaultLocaleCode === undefined || defaultLocaleCode === '') {\n return filtered as DocumentMetadata['availableLocales'];\n }\n\n // Stable partition: move the default locale entry to the front, keep the\n // rest of the order intact.\n const defaultEntries = filtered.filter((entry) => entry.locale === defaultLocaleCode);\n const otherEntries = filtered.filter((entry) => entry.locale !== defaultLocaleCode);\n\n return [...defaultEntries, ...otherEntries] as DocumentMetadata['availableLocales'];\n },\n\n /**\n * Returns available status of a document for the current locale\n */\n getAvailableStatus(version: DocumentVersion, allVersions: DocumentVersion[]) {\n // Find the other status of the document\n const status =\n version.publishedAt !== null\n ? CONTENT_MANAGER_STATUS.DRAFT\n : CONTENT_MANAGER_STATUS.PUBLISHED;\n\n // Get version that match the current locale and not match the current status\n const availableStatus = allVersions.find((v) => {\n const matchLocale = v.locale === version.locale;\n const matchStatus = status === 'published' ? v.publishedAt !== null : v.publishedAt === null;\n return matchLocale && matchStatus;\n });\n\n if (!availableStatus) return availableStatus;\n\n // Pick status fields (at fields, status, by fields), use lodash\n return pick(availableStatus, AVAILABLE_STATUS_FIELDS);\n },\n\n /**\n * Get the available status of many documents, useful for batch operations\n * @param uid\n * @param documents\n * @returns\n */\n async getManyAvailableStatus(uid: UID.ContentType, documents: DocumentVersion[]) {\n if (!documents.length) return [];\n\n // The status and locale of all documents should be the same\n const status = documents[0].publishedAt !== null ? 'published' : 'draft';\n const locales = documents.map((d) => d.locale).filter(Boolean);\n\n const where: Record<string, any> = {\n documentId: { $in: documents.map((d) => d.documentId).filter(Boolean) },\n publishedAt: { $null: status === 'published' },\n };\n\n // If there is any locale to filter (if i18n is enabled)\n if (locales.length === documents.length) {\n where.locale = { $in: locales };\n } else if (locales.length) {\n /*\n * The batch mixes localized and non-localized versions, which happens when a\n * content type holds rows with a locale while others have none — for instance\n * after i18n is disabled on it, or when a locale is sent to a non-localized\n * content type through the API.\n *\n * `locales` only holds the locales that are actually set, so filtering on it\n * alone would drop the counterparts of every version whose locale is null, and\n * those versions would be reported as drafts even though they are published.\n */\n where.$or = [{ locale: { $in: locales } }, { locale: { $null: true } }];\n }\n\n return strapi.db.query(uid).findMany({\n where,\n select: AVAILABLE_STATUS_SCALAR_FIELDS,\n });\n },\n\n getStatus(version: DocumentVersion, otherDocumentStatuses?: DocumentMetadata['availableStatus']) {\n let draftVersion: DocumentVersion | undefined;\n let publishedVersion: DocumentVersion | undefined;\n\n if (version.publishedAt) {\n publishedVersion = version;\n } else {\n draftVersion = version;\n }\n\n const otherVersion = otherDocumentStatuses?.at(0);\n if (otherVersion?.publishedAt) {\n publishedVersion = otherVersion;\n } else if (otherVersion) {\n draftVersion = otherVersion;\n }\n\n if (!draftVersion) return CONTENT_MANAGER_STATUS.PUBLISHED;\n if (!publishedVersion) return CONTENT_MANAGER_STATUS.DRAFT;\n\n /*\n * The document is modified if the draft version has been updated more\n * recently than the published version.\n */\n const isDraftModified = getIsVersionLatestModification(draftVersion, publishedVersion);\n return isDraftModified ? CONTENT_MANAGER_STATUS.MODIFIED : CONTENT_MANAGER_STATUS.PUBLISHED;\n },\n\n // TODO is it necessary to return metadata on every page of the CM\n // We could refactor this so the locales are only loaded when they're\n // needed. e.g. in the bulk locale action modal.\n async getMetadata(\n uid: UID.ContentType,\n version: DocumentVersion,\n { availableLocales = true, availableStatus = true }: GetMetadataOptions = {}\n ) {\n const model = strapi.getModel(uid);\n const hasDnP = contentTypes.hasDraftAndPublish(model);\n const isLocalized = strapi.localization.isLocalizedContentType(model);\n\n if (!availableLocales && !availableStatus) {\n // Nothing to compute.\n return { availableLocales: [], availableStatus: [], versions: [] as DocumentVersion[] };\n }\n if (!isLocalized && !hasDnP) {\n // If there are no locales and no draft/publish, there's only ever 1 version of any document.\n return { availableLocales: [], availableStatus: [], versions: [] as DocumentVersion[] };\n }\n\n const onlyStatusIsRelevant = hasDnP && (!isLocalized || !availableLocales);\n if (onlyStatusIsRelevant) {\n const otherVersion = availableStatus\n ? await strapi.db.query(uid).findOne({\n where: {\n documentId: version.documentId,\n ...(version.locale ? { locale: version.locale } : {}),\n publishedAt: oppositePublishStatus(version.publishedAt),\n },\n select: AVAILABLE_STATUS_SCALAR_FIELDS,\n populate: AVAILABLE_STATUS_POPULATE,\n })\n : null;\n return {\n availableLocales: [],\n availableStatus: otherVersion ? [pick(otherVersion, AVAILABLE_STATUS_FIELDS)] : [],\n versions: [] as DocumentVersion[],\n };\n }\n\n // Full path for localized content types\n // TODO: Ignore publishedAt if availableStatus=false, and ignore locale if\n // i18n is disabled\n\n // Include non-translatable scalar and media fields in availableLocales for i18n prefilling\n let nonLocalizedFields: string[] = [];\n let nonLocalizedMediaFields: string[] = [];\n // Without a localization provider there are no non-localized attributes.\n try {\n if (model?.attributes !== undefined) {\n const allNonLocalized = strapi.localization.getNonLocalizedAttributes(model);\n // Get scalar and media attributes separately\n const scalarAttrs = getScalarAttributes(model);\n const mediaAttrs = getMediaAttributes(model);\n\n // Separate scalar fields (can be in fields array) from media fields (need to be populated)\n nonLocalizedFields = allNonLocalized.filter(\n (field) => field in model.attributes && scalarAttrs.includes(field)\n );\n nonLocalizedMediaFields = allNonLocalized.filter(\n (field) => field in model.attributes && mediaAttrs.includes(field)\n );\n }\n } catch {\n // The provider errored — fall back to no prefilled non-localized fields\n }\n\n // Build populate object for non-localized media fields\n const mediaPopulate = nonLocalizedMediaFields.reduce(\n (acc, field) => {\n acc[field] = {\n populate: {\n folder: true,\n },\n };\n return acc;\n },\n {} as Record<string, { populate: { folder: boolean } }>\n );\n\n const params = {\n populate: {\n ...mediaPopulate,\n ...AVAILABLE_STATUS_POPULATE,\n },\n fields: [...new Set([...AVAILABLE_LOCALES_FIELDS, ...nonLocalizedFields])],\n filters: {\n documentId: version.documentId,\n },\n };\n\n const dbParams = strapi.get('query-params').transform(uid, params);\n const versions = await strapi.db.query(uid).findMany(dbParams);\n\n // TODO: Remove use of available locales and use localizations instead\n const availableLocalesResult = availableLocales\n ? await this.getAvailableLocales(uid, version, versions)\n : [];\n\n const availableStatusResult = availableStatus\n ? this.getAvailableStatus(version, versions)\n : null;\n\n return {\n availableLocales: availableLocalesResult,\n availableStatus: availableStatusResult ? [availableStatusResult] : [],\n versions,\n };\n },\n\n /**\n * Returns associated metadata of a document:\n * - Available locales of the document for the current status\n * - Available status of the document for the current locale\n */\n async formatDocumentWithMetadata(\n uid: UID.ContentType,\n document: DocumentVersion,\n opts: GetMetadataOptions = {}\n ) {\n if (!document) {\n return {\n data: document,\n meta: {\n availableLocales: [],\n availableStatus: [],\n },\n };\n }\n\n const hasDraftAndPublish = contentTypes.hasDraftAndPublish(strapi.getModel(uid));\n\n // Ignore available status if the content type does not have draft and publish\n if (!hasDraftAndPublish) {\n opts.availableStatus = false;\n }\n\n const { versions, ...meta } = await this.getMetadata(uid, document, opts);\n\n // Populate localization statuses\n if (document.localizations?.length) {\n document.localizations = document.localizations.map((d) => {\n // Find the counterpart version (same documentId + locale, opposite publishedAt) from\n // the already-fetched versions array, avoiding an extra DB query.\n const counterpart = versions.find(\n (v) =>\n v.documentId === d.documentId &&\n v.locale === d.locale &&\n (d.publishedAt === null) !== (v.publishedAt === null)\n );\n return {\n ...d,\n status: this.getStatus(d, counterpart ? [counterpart] : []),\n };\n });\n }\n\n return {\n data: {\n ...document,\n // Add status to the document only if draft and publish is enabled\n status: hasDraftAndPublish\n ? this.getStatus(document, meta.availableStatus as any)\n : undefined,\n },\n meta,\n };\n },\n});\n"],"names":["getScalarAttributes","getMediaAttributes","contentTypes","AVAILABLE_STATUS_SCALAR_FIELDS","AVAILABLE_STATUS_POPULATE","createdBy","select","updatedBy","AVAILABLE_STATUS_FIELDS","AVAILABLE_LOCALES_FIELDS","oppositePublishStatus","publishedAt","$null","$notNull","CONTENT_MANAGER_STATUS","PUBLISHED","DRAFT","MODIFIED","getIsVersionLatestModification","version","otherVersion","updatedAt","versionUpdatedAt","Date","getTime","otherUpdatedAt","strapi","getAvailableLocales","uid","allVersions","versionsByLocale","groupBy","locale","model","getModel","mappingResult","async","map","Object","values","localeVersions","hasDraftAndPublish","draftVersion","find","v","otherVersions","filter","id","status","getStatus","filtered","Boolean","defaultLocaleCode","localization","getDefaultLocale","undefined","defaultEntries","entry","otherEntries","getAvailableStatus","availableStatus","matchLocale","matchStatus","pick","getManyAvailableStatus","documents","length","locales","d","where","documentId","$in","$or","db","query","findMany","otherDocumentStatuses","publishedVersion","at","isDraftModified","getMetadata","availableLocales","hasDnP","isLocalized","isLocalizedContentType","versions","onlyStatusIsRelevant","findOne","populate","nonLocalizedFields","nonLocalizedMediaFields","attributes","allNonLocalized","getNonLocalizedAttributes","scalarAttrs","mediaAttrs","field","includes","mediaPopulate","reduce","acc","folder","params","fields","Set","filters","dbParams","get","transform","availableLocalesResult","availableStatusResult","formatDocumentWithMetadata","document","opts","data","meta","localizations","counterpart"],"mappings":";;;;;AAOA,MAAM,EAAEA,mBAAmB,EAAEC,kBAAkB,EAAE,GAAGC,wBAAAA;AAWpD;AACA,MAAMC,8BAAAA,GAAiC;AACrC,IAAA,IAAA;AACA,IAAA,YAAA;AACA,IAAA,QAAA;AACA,IAAA,WAAA;AACA,IAAA,WAAA;AACA,IAAA;AACD,CAAA;AACD;AACA,MAAMC,yBAAAA,GAA4B;IAChCC,SAAAA,EAAW;QAAEC,MAAAA,EAAQ;AAAC,YAAA,IAAA;AAAM,YAAA,WAAA;AAAa,YAAA,UAAA;AAAY,YAAA;AAAQ;AAAC,KAAA;IAC9DC,SAAAA,EAAW;QAAED,MAAAA,EAAQ;AAAC,YAAA,IAAA;AAAM,YAAA,WAAA;AAAa,YAAA,UAAA;AAAY,YAAA;AAAQ;AAAC;AAChE,CAAA;AACA;AACA,MAAME,uBAAAA,GAA0B;AAC3BL,IAAAA,GAAAA,8BAAAA;AACH,IAAA,WAAA;AACA,IAAA,WAAA;AACA,IAAA;AACD,CAAA;AACD,MAAMM,wBAAAA,GAA2B;AAC/B,IAAA,IAAA;AACA,IAAA,YAAA;AACA,IAAA,QAAA;AACA,IAAA,WAAA;AACA,IAAA,WAAA;AACA,IAAA;AACD,CAAA;AAED,qEACA,MAAMC,qBAAAA,GAAwB,CAACC,WAAAA,GAC7BA,gBAAgB,IAAA,GAAO;QAAEC,KAAAA,EAAO;KAAK,GAAI;QAAEC,QAAAA,EAAU;AAAK,KAAA;AAE5D,MAAMC,sBAAAA,GAAyB;IAC7BC,SAAAA,EAAW,WAAA;IACXC,KAAAA,EAAO,OAAA;IACPC,QAAAA,EAAU;AACZ,CAAA;AAgBA;;IAGA,MAAMC,8BAAAA,GAAiC,CACrCC,OAAAA,EACAC,YAAAA,GAAAA;AAEA,IAAA,IAAI,CAACD,OAAAA,IAAW,CAACA,OAAAA,CAAQE,SAAS,EAAE;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EAAM;AACJ,oBAAA,GAAGF,QAAQ;;oBAEXhE,MAAAA,EAAQP,kBAAAA,GACJ,IAAI,CAACQ,SAAS,CAAC+D,QAAAA,EAAUG,IAAAA,CAAKvD,eAAe,CAAA,GAC7CL;AACN,iBAAA;AACA4D,gBAAAA;AACF,aAAA;AACF,QAAA;AACF,KAAA,CAAC;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"document-metadata.mjs","sources":["../../../server/src/services/document-metadata.ts"],"sourcesContent":["import { groupBy, pick } from 'lodash';\n\nimport { async, contentTypes } from '@strapi/utils';\nimport type { Core, UID, Modules } from '@strapi/types';\n\nimport type { DocumentMetadata } from '../../../shared/contracts/collection-types';\n\nconst { getScalarAttributes, getMediaAttributes } = contentTypes;\n\nexport interface DocumentVersion {\n id: string | number;\n documentId: Modules.Documents.ID;\n locale?: string;\n localizations?: DocumentVersion[];\n updatedAt?: string | null | Date;\n publishedAt?: string | null | Date;\n}\n\n// Scalar fields that can be used in a DB `select`\nconst AVAILABLE_STATUS_SCALAR_FIELDS = [\n 'id',\n 'documentId',\n 'locale',\n 'updatedAt',\n 'createdAt',\n 'publishedAt',\n];\n// Relation populate shared by both the fast path and the full path\nconst AVAILABLE_STATUS_POPULATE = {\n createdBy: { select: ['id', 'firstname', 'lastname', 'email'] },\n updatedBy: { select: ['id', 'firstname', 'lastname', 'email'] },\n};\n// All fields to pick from a hydrated result (scalars + populated relations + virtual)\nconst AVAILABLE_STATUS_FIELDS = [\n ...AVAILABLE_STATUS_SCALAR_FIELDS,\n 'createdBy',\n 'updatedBy',\n 'status',\n];\nconst AVAILABLE_LOCALES_FIELDS = [\n 'id',\n 'documentId',\n 'locale',\n 'updatedAt',\n 'createdAt',\n 'publishedAt',\n];\n\n/** Returns a DB filter that matches the opposite publish status. */\nconst oppositePublishStatus = (publishedAt: unknown) =>\n publishedAt !== null ? { $null: true } : { $notNull: true };\n\nconst CONTENT_MANAGER_STATUS = {\n PUBLISHED: 'published',\n DRAFT: 'draft',\n MODIFIED: 'modified',\n};\n\n/**\n * Controls the metadata properties to be returned\n *\n * If `availableLocales` is set to `true` (default), the returned metadata will include\n * the available locales of the document for its current status.\n *\n * If `availableStatus` is set to `true` (default), the returned metadata will include\n * the available status of the document for its current locale.\n */\nexport interface GetMetadataOptions {\n availableLocales?: boolean;\n availableStatus?: boolean;\n}\n\n/**\n * Checks if the provided document version has been modified after all other versions.\n */\nconst getIsVersionLatestModification = (\n version?: DocumentVersion,\n otherVersion?: DocumentVersion\n): boolean => {\n if (!version || !version.updatedAt) {\n return false;\n }\n\n const versionUpdatedAt = version?.updatedAt ? new Date(version.updatedAt).getTime() : 0;\n\n const otherUpdatedAt = otherVersion?.updatedAt ? new Date(otherVersion.updatedAt).getTime() : 0;\n\n return versionUpdatedAt > otherUpdatedAt;\n};\n\nexport default ({ strapi }: { strapi: Core.Strapi }) => ({\n /**\n * Returns available locales of a document for the current status.\n *\n * The result is sorted with the default locale (as defined by the i18n plugin)\n * at index 0 when present. This is the canonical-source invariant relied on by\n * `useDocument.getInitialFormValues` in the admin: when creating a new locale\n * draft, non-localized scalar/media values are inherited from\n * `availableLocales[0]`. Putting the default locale first means inheritance\n * stays predictable when sibling locales have drifted on non-localized fields\n * (which can happen because the server only syncs non-localized fields at\n * locale-creation time, not on subsequent updates — see\n * `copyNonLocalizedFields` in document-service/internationalization.ts).\n */\n async getAvailableLocales(\n uid: UID.ContentType,\n version: DocumentVersion,\n allVersions: DocumentVersion[]\n ) {\n // Group all versions by locale\n const versionsByLocale = groupBy(allVersions, 'locale');\n\n // Delete the current locale\n if (version.locale) {\n delete versionsByLocale[version.locale];\n }\n\n // For each locale, get the ones with the same status\n // There will not be a draft and a version counterpart if the content\n // type does not have draft and publish\n const model = strapi.getModel(uid);\n\n const mappingResult = await async.map(\n Object.values(versionsByLocale),\n async (localeVersions: DocumentVersion[]) => {\n if (!contentTypes.hasDraftAndPublish(model)) {\n return localeVersions[0];\n }\n\n const draftVersion = localeVersions.find((v) => v.publishedAt === null);\n const otherVersions = localeVersions.filter((v) => v.id !== draftVersion?.id);\n\n if (!draftVersion) {\n return;\n }\n\n return {\n ...draftVersion,\n status: this.getStatus(draftVersion, otherVersions as any),\n };\n }\n );\n\n const filtered = mappingResult.filter(Boolean) as unknown as NonNullable<\n DocumentMetadata['availableLocales']\n >;\n\n // Sort the default locale first so `availableLocales[0]` is the canonical\n // source for non-localized field inheritance in the admin. Without a\n // localization provider there is no default locale and the order is kept.\n let defaultLocaleCode: string | null | undefined = null;\n try {\n defaultLocaleCode = await strapi.localization.getDefaultLocale();\n } catch {\n // The provider (e.g. its locale store lookup) errored — leave order untouched.\n }\n\n // The provider may resolve `undefined` at runtime when no default locale is stored\n if (defaultLocaleCode === null || defaultLocaleCode === undefined || defaultLocaleCode === '') {\n return filtered as DocumentMetadata['availableLocales'];\n }\n\n // Stable partition: move the default locale entry to the front, keep the\n // rest of the order intact.\n const defaultEntries = filtered.filter((entry) => entry.locale === defaultLocaleCode);\n const otherEntries = filtered.filter((entry) => entry.locale !== defaultLocaleCode);\n\n return [...defaultEntries, ...otherEntries] as DocumentMetadata['availableLocales'];\n },\n\n /**\n * Returns available status of a document for the current locale\n */\n getAvailableStatus(version: DocumentVersion, allVersions: DocumentVersion[]) {\n // Find the other status of the document\n const status =\n version.publishedAt !== null\n ? CONTENT_MANAGER_STATUS.DRAFT\n : CONTENT_MANAGER_STATUS.PUBLISHED;\n\n // Get version that match the current locale and not match the current status\n const availableStatus = allVersions.find((v) => {\n const matchLocale = v.locale === version.locale;\n const matchStatus = status === 'published' ? v.publishedAt !== null : v.publishedAt === null;\n return matchLocale && matchStatus;\n });\n\n if (!availableStatus) return availableStatus;\n\n // Pick status fields (at fields, status, by fields), use lodash\n return pick(availableStatus, AVAILABLE_STATUS_FIELDS);\n },\n\n /**\n * Get the available status of many documents, useful for batch operations\n * @param uid\n * @param documents\n * @returns\n */\n async getManyAvailableStatus(uid: UID.ContentType, documents: DocumentVersion[]) {\n if (!documents.length) return [];\n\n // The status and locale of all documents should be the same\n const status = documents[0].publishedAt !== null ? 'published' : 'draft';\n const locales = documents.map((d) => d.locale).filter(Boolean);\n\n const where: Record<string, any> = {\n documentId: { $in: documents.map((d) => d.documentId).filter(Boolean) },\n publishedAt: { $null: status === 'published' },\n };\n\n // If there is any locale to filter (if i18n is enabled)\n if (locales.length === documents.length) {\n where.locale = { $in: locales };\n } else if (locales.length) {\n /*\n * The batch mixes localized and non-localized versions, which happens when a\n * content type holds rows with a locale while others have none — for instance\n * after i18n is disabled on it, or when a locale is sent to a non-localized\n * content type through the API.\n *\n * `locales` only holds the locales that are actually set, so filtering on it\n * alone would drop the counterparts of every version whose locale is null, and\n * those versions would be reported as drafts even though they are published.\n */\n where.$or = [{ locale: { $in: locales } }, { locale: { $null: true } }];\n }\n\n return strapi.query(uid).findMany({\n where,\n select: AVAILABLE_STATUS_SCALAR_FIELDS,\n });\n },\n\n getStatus(version: DocumentVersion, otherDocumentStatuses?: DocumentMetadata['availableStatus']) {\n let draftVersion: DocumentVersion | undefined;\n let publishedVersion: DocumentVersion | undefined;\n\n if (version.publishedAt) {\n publishedVersion = version;\n } else {\n draftVersion = version;\n }\n\n const otherVersion = otherDocumentStatuses?.at(0);\n if (otherVersion?.publishedAt) {\n publishedVersion = otherVersion;\n } else if (otherVersion) {\n draftVersion = otherVersion;\n }\n\n if (!draftVersion) return CONTENT_MANAGER_STATUS.PUBLISHED;\n if (!publishedVersion) return CONTENT_MANAGER_STATUS.DRAFT;\n\n /*\n * The document is modified if the draft version has been updated more\n * recently than the published version.\n */\n const isDraftModified = getIsVersionLatestModification(draftVersion, publishedVersion);\n return isDraftModified ? CONTENT_MANAGER_STATUS.MODIFIED : CONTENT_MANAGER_STATUS.PUBLISHED;\n },\n\n // TODO is it necessary to return metadata on every page of the CM\n // We could refactor this so the locales are only loaded when they're\n // needed. e.g. in the bulk locale action modal.\n async getMetadata(\n uid: UID.ContentType,\n version: DocumentVersion,\n { availableLocales = true, availableStatus = true }: GetMetadataOptions = {}\n ) {\n const model = strapi.getModel(uid);\n const hasDnP = contentTypes.hasDraftAndPublish(model);\n const isLocalized = strapi.localization.isLocalizedContentType(model);\n\n if (!availableLocales && !availableStatus) {\n // Nothing to compute.\n return { availableLocales: [], availableStatus: [], versions: [] as DocumentVersion[] };\n }\n if (!isLocalized && !hasDnP) {\n // If there are no locales and no draft/publish, there's only ever 1 version of any document.\n return { availableLocales: [], availableStatus: [], versions: [] as DocumentVersion[] };\n }\n\n const onlyStatusIsRelevant = hasDnP && (!isLocalized || !availableLocales);\n if (onlyStatusIsRelevant) {\n const otherVersion = availableStatus\n ? await strapi.db.query(uid).findOne({\n where: {\n documentId: version.documentId,\n ...(version.locale ? { locale: version.locale } : {}),\n publishedAt: oppositePublishStatus(version.publishedAt),\n },\n select: AVAILABLE_STATUS_SCALAR_FIELDS,\n populate: AVAILABLE_STATUS_POPULATE,\n })\n : null;\n return {\n availableLocales: [],\n availableStatus: otherVersion ? [pick(otherVersion, AVAILABLE_STATUS_FIELDS)] : [],\n versions: [] as DocumentVersion[],\n };\n }\n\n // Full path for localized content types\n // TODO: Ignore publishedAt if availableStatus=false, and ignore locale if\n // i18n is disabled\n\n // Include non-translatable scalar and media fields in availableLocales for i18n prefilling\n let nonLocalizedFields: string[] = [];\n let nonLocalizedMediaFields: string[] = [];\n // Without a localization provider there are no non-localized attributes.\n try {\n if (model?.attributes !== undefined) {\n const allNonLocalized = strapi.localization.getNonLocalizedAttributes(model);\n // Get scalar and media attributes separately\n const scalarAttrs = getScalarAttributes(model);\n const mediaAttrs = getMediaAttributes(model);\n\n // Separate scalar fields (can be in fields array) from media fields (need to be populated)\n nonLocalizedFields = allNonLocalized.filter(\n (field) => field in model.attributes && scalarAttrs.includes(field)\n );\n nonLocalizedMediaFields = allNonLocalized.filter(\n (field) => field in model.attributes && mediaAttrs.includes(field)\n );\n }\n } catch {\n // The provider errored — fall back to no prefilled non-localized fields\n }\n\n // Build populate object for non-localized media fields\n const mediaPopulate = nonLocalizedMediaFields.reduce(\n (acc, field) => {\n acc[field] = {\n populate: {\n folder: true,\n },\n };\n return acc;\n },\n {} as Record<string, { populate: { folder: boolean } }>\n );\n\n const params = {\n populate: {\n ...mediaPopulate,\n ...AVAILABLE_STATUS_POPULATE,\n },\n fields: [...new Set([...AVAILABLE_LOCALES_FIELDS, ...nonLocalizedFields])],\n filters: {\n documentId: version.documentId,\n },\n };\n\n const dbParams = strapi.get('query-params').transform(uid, params);\n const versions = await strapi.db.query(uid).findMany(dbParams);\n\n // TODO: Remove use of available locales and use localizations instead\n const availableLocalesResult = availableLocales\n ? await this.getAvailableLocales(uid, version, versions)\n : [];\n\n const availableStatusResult = availableStatus\n ? this.getAvailableStatus(version, versions)\n : null;\n\n return {\n availableLocales: availableLocalesResult,\n availableStatus: availableStatusResult ? [availableStatusResult] : [],\n versions,\n };\n },\n\n /**\n * Returns associated metadata of a document:\n * - Available locales of the document for the current status\n * - Available status of the document for the current locale\n */\n async formatDocumentWithMetadata(\n uid: UID.ContentType,\n document: DocumentVersion,\n opts: GetMetadataOptions = {}\n ) {\n if (!document) {\n return {\n data: document,\n meta: {\n availableLocales: [],\n availableStatus: [],\n },\n };\n }\n\n const hasDraftAndPublish = contentTypes.hasDraftAndPublish(strapi.getModel(uid));\n\n // Ignore available status if the content type does not have draft and publish\n if (!hasDraftAndPublish) {\n opts.availableStatus = false;\n }\n\n const { versions, ...meta } = await this.getMetadata(uid, document, opts);\n\n // Populate localization statuses\n if (document.localizations?.length) {\n document.localizations = document.localizations.map((d) => {\n // Find the counterpart version (same documentId + locale, opposite publishedAt) from\n // the already-fetched versions array, avoiding an extra DB query.\n const counterpart = versions.find(\n (v) =>\n v.documentId === d.documentId &&\n v.locale === d.locale &&\n (d.publishedAt === null) !== (v.publishedAt === null)\n );\n return {\n ...d,\n status: this.getStatus(d, counterpart ? [counterpart] : []),\n };\n });\n }\n\n return {\n data: {\n ...document,\n // Add status to the document only if draft and publish is enabled\n status: hasDraftAndPublish\n ? this.getStatus(document, meta.availableStatus as any)\n : undefined,\n },\n meta,\n };\n },\n});\n"],"names":["getScalarAttributes","getMediaAttributes","contentTypes","AVAILABLE_STATUS_SCALAR_FIELDS","AVAILABLE_STATUS_POPULATE","createdBy","select","updatedBy","AVAILABLE_STATUS_FIELDS","AVAILABLE_LOCALES_FIELDS","oppositePublishStatus","publishedAt","$null","$notNull","CONTENT_MANAGER_STATUS","PUBLISHED","DRAFT","MODIFIED","getIsVersionLatestModification","version","otherVersion","updatedAt","versionUpdatedAt","Date","getTime","otherUpdatedAt","strapi","getAvailableLocales","uid","allVersions","versionsByLocale","groupBy","locale","model","getModel","mappingResult","async","map","Object","values","localeVersions","hasDraftAndPublish","draftVersion","find","v","otherVersions","filter","id","status","getStatus","filtered","Boolean","defaultLocaleCode","localization","getDefaultLocale","undefined","defaultEntries","entry","otherEntries","getAvailableStatus","availableStatus","matchLocale","matchStatus","pick","getManyAvailableStatus","documents","length","locales","d","where","documentId","$in","$or","query","findMany","otherDocumentStatuses","publishedVersion","at","isDraftModified","getMetadata","availableLocales","hasDnP","isLocalized","isLocalizedContentType","versions","onlyStatusIsRelevant","db","findOne","populate","nonLocalizedFields","nonLocalizedMediaFields","attributes","allNonLocalized","getNonLocalizedAttributes","scalarAttrs","mediaAttrs","field","includes","mediaPopulate","reduce","acc","folder","params","fields","Set","filters","dbParams","get","transform","availableLocalesResult","availableStatusResult","formatDocumentWithMetadata","document","opts","data","meta","localizations","counterpart"],"mappings":";;;AAOA,MAAM,EAAEA,mBAAmB,EAAEC,kBAAkB,EAAE,GAAGC,YAAAA;AAWpD;AACA,MAAMC,8BAAAA,GAAiC;AACrC,IAAA,IAAA;AACA,IAAA,YAAA;AACA,IAAA,QAAA;AACA,IAAA,WAAA;AACA,IAAA,WAAA;AACA,IAAA;AACD,CAAA;AACD;AACA,MAAMC,yBAAAA,GAA4B;IAChCC,SAAAA,EAAW;QAAEC,MAAAA,EAAQ;AAAC,YAAA,IAAA;AAAM,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AA;AACzB,YAAA;AAEA,YAAA,MAAM,EAAEwB,QAAQ,EAAE,GAAG+B,IAAAA,EAAM,GAAG,MAAM,IAAI,CAACpC,WAAW,CAACnD,GAAAA,EAAKoF,QAAAA,EAAUC,IAAAA,CAAAA;;YAGpE,IAAID,QAAAA,CAASI,aAAa,EAAElD,MAAAA,EAAQ;AAClC8C,gBAAAA,QAAAA,CAASI,aAAa,GAAGJ,QAAAA,CAASI,aAAa,CAAC/E,GAAG,CAAC,CAAC+B,CAAAA,GAAAA;;;oBAGnD,MAAMiD,WAAAA,GAAcjC,QAAAA,CAASzC,IAAI,CAC/B,CAACC,CAAAA,GACCA,CAAAA,CAAE0B,UAAU,KAAKF,CAAAA,CAAEE,UAAU,IAC7B1B,CAAAA,CAAEZ,MAAM,KAAKoC,CAAAA,CAAEpC,MAAM,IACpBoC,CAAAA,CAAEzD,WAAW,KAAK,IAAA,MAAWiC,CAAAA,CAAEjC,WAAW,KAAK,IAAG,CAAA,CAAA;oBAEvD,OAAO;AACL,wBAAA,GAAGyD,CAAC;AACJpB,wBAAAA,MAAAA,EAAQ,IAAI,CAACC,SAAS,CAACmB,GAAGiD,WAAAA,GAAc;AAACA,4BAAAA;AAAY,yBAAA,GAAG,EAAE;AAC5D,qBAAA;AACF,gBAAA,CAAA,CAAA;AACF,YAAA;YAEA,OAAO;gBACLH,IAAAA,EAAM;AACJ,oBAAA,GAAGF,QAAQ;;oBAEXhE,MAAAA,EAAQP,kBAAAA,GACJ,IAAI,CAACQ,SAAS,CAAC+D,QAAAA,EAAUG,IAAAA,CAAKvD,eAAe,CAAA,GAC7CL;AACN,iBAAA;AACA4D,gBAAAA;AACF,aAAA;AACF,QAAA;AACF,KAAA,CAAC;;;;"}
|
|
1
|
+
{"version":3,"file":"document-metadata.mjs","sources":["../../../server/src/services/document-metadata.ts"],"sourcesContent":["import { groupBy, pick } from 'lodash';\n\nimport { async, contentTypes } from '@strapi/utils';\nimport type { Core, UID, Modules } from '@strapi/types';\n\nimport type { DocumentMetadata } from '../../../shared/contracts/collection-types';\n\nconst { getScalarAttributes, getMediaAttributes } = contentTypes;\n\nexport interface DocumentVersion {\n id: string | number;\n documentId: Modules.Documents.ID;\n locale?: string;\n localizations?: DocumentVersion[];\n updatedAt?: string | null | Date;\n publishedAt?: string | null | Date;\n}\n\n// Scalar fields that can be used in a DB `select`\nconst AVAILABLE_STATUS_SCALAR_FIELDS = [\n 'id',\n 'documentId',\n 'locale',\n 'updatedAt',\n 'createdAt',\n 'publishedAt',\n];\n// Relation populate shared by both the fast path and the full path\nconst AVAILABLE_STATUS_POPULATE = {\n createdBy: { select: ['id', 'firstname', 'lastname', 'email'] },\n updatedBy: { select: ['id', 'firstname', 'lastname', 'email'] },\n};\n// All fields to pick from a hydrated result (scalars + populated relations + virtual)\nconst AVAILABLE_STATUS_FIELDS = [\n ...AVAILABLE_STATUS_SCALAR_FIELDS,\n 'createdBy',\n 'updatedBy',\n 'status',\n];\nconst AVAILABLE_LOCALES_FIELDS = [\n 'id',\n 'documentId',\n 'locale',\n 'updatedAt',\n 'createdAt',\n 'publishedAt',\n];\n\n/** Returns a DB filter that matches the opposite publish status. */\nconst oppositePublishStatus = (publishedAt: unknown) =>\n publishedAt !== null ? { $null: true } : { $notNull: true };\n\nconst CONTENT_MANAGER_STATUS = {\n PUBLISHED: 'published',\n DRAFT: 'draft',\n MODIFIED: 'modified',\n};\n\n/**\n * Controls the metadata properties to be returned\n *\n * If `availableLocales` is set to `true` (default), the returned metadata will include\n * the available locales of the document for its current status.\n *\n * If `availableStatus` is set to `true` (default), the returned metadata will include\n * the available status of the document for its current locale.\n */\nexport interface GetMetadataOptions {\n availableLocales?: boolean;\n availableStatus?: boolean;\n}\n\n/**\n * Checks if the provided document version has been modified after all other versions.\n */\nconst getIsVersionLatestModification = (\n version?: DocumentVersion,\n otherVersion?: DocumentVersion\n): boolean => {\n if (!version || !version.updatedAt) {\n return false;\n }\n\n const versionUpdatedAt = version?.updatedAt ? new Date(version.updatedAt).getTime() : 0;\n\n const otherUpdatedAt = otherVersion?.updatedAt ? new Date(otherVersion.updatedAt).getTime() : 0;\n\n return versionUpdatedAt > otherUpdatedAt;\n};\n\nexport default ({ strapi }: { strapi: Core.Strapi }) => ({\n /**\n * Returns available locales of a document for the current status.\n *\n * The result is sorted with the default locale (as defined by the i18n plugin)\n * at index 0 when present. This is the canonical-source invariant relied on by\n * `useDocument.getInitialFormValues` in the admin: when creating a new locale\n * draft, non-localized scalar/media values are inherited from\n * `availableLocales[0]`. Putting the default locale first means inheritance\n * stays predictable when sibling locales have drifted on non-localized fields\n * (which can happen because the server only syncs non-localized fields at\n * locale-creation time, not on subsequent updates — see\n * `copyNonLocalizedFields` in document-service/internationalization.ts).\n */\n async getAvailableLocales(\n uid: UID.ContentType,\n version: DocumentVersion,\n allVersions: DocumentVersion[]\n ) {\n // Group all versions by locale\n const versionsByLocale = groupBy(allVersions, 'locale');\n\n // Delete the current locale\n if (version.locale) {\n delete versionsByLocale[version.locale];\n }\n\n // For each locale, get the ones with the same status\n // There will not be a draft and a version counterpart if the content\n // type does not have draft and publish\n const model = strapi.getModel(uid);\n\n const mappingResult = await async.map(\n Object.values(versionsByLocale),\n async (localeVersions: DocumentVersion[]) => {\n if (!contentTypes.hasDraftAndPublish(model)) {\n return localeVersions[0];\n }\n\n const draftVersion = localeVersions.find((v) => v.publishedAt === null);\n const otherVersions = localeVersions.filter((v) => v.id !== draftVersion?.id);\n\n if (!draftVersion) {\n return;\n }\n\n return {\n ...draftVersion,\n status: this.getStatus(draftVersion, otherVersions as any),\n };\n }\n );\n\n const filtered = mappingResult.filter(Boolean) as unknown as NonNullable<\n DocumentMetadata['availableLocales']\n >;\n\n // Sort the default locale first so `availableLocales[0]` is the canonical\n // source for non-localized field inheritance in the admin. Without a\n // localization provider there is no default locale and the order is kept.\n let defaultLocaleCode: string | null | undefined = null;\n try {\n defaultLocaleCode = await strapi.localization.getDefaultLocale();\n } catch {\n // The provider (e.g. its locale store lookup) errored — leave order untouched.\n }\n\n // The provider may resolve `undefined` at runtime when no default locale is stored\n if (defaultLocaleCode === null || defaultLocaleCode === undefined || defaultLocaleCode === '') {\n return filtered as DocumentMetadata['availableLocales'];\n }\n\n // Stable partition: move the default locale entry to the front, keep the\n // rest of the order intact.\n const defaultEntries = filtered.filter((entry) => entry.locale === defaultLocaleCode);\n const otherEntries = filtered.filter((entry) => entry.locale !== defaultLocaleCode);\n\n return [...defaultEntries, ...otherEntries] as DocumentMetadata['availableLocales'];\n },\n\n /**\n * Returns available status of a document for the current locale\n */\n getAvailableStatus(version: DocumentVersion, allVersions: DocumentVersion[]) {\n // Find the other status of the document\n const status =\n version.publishedAt !== null\n ? CONTENT_MANAGER_STATUS.DRAFT\n : CONTENT_MANAGER_STATUS.PUBLISHED;\n\n // Get version that match the current locale and not match the current status\n const availableStatus = allVersions.find((v) => {\n const matchLocale = v.locale === version.locale;\n const matchStatus = status === 'published' ? v.publishedAt !== null : v.publishedAt === null;\n return matchLocale && matchStatus;\n });\n\n if (!availableStatus) return availableStatus;\n\n // Pick status fields (at fields, status, by fields), use lodash\n return pick(availableStatus, AVAILABLE_STATUS_FIELDS);\n },\n\n /**\n * Get the available status of many documents, useful for batch operations\n * @param uid\n * @param documents\n * @returns\n */\n async getManyAvailableStatus(uid: UID.ContentType, documents: DocumentVersion[]) {\n if (!documents.length) return [];\n\n // The status and locale of all documents should be the same\n const status = documents[0].publishedAt !== null ? 'published' : 'draft';\n const locales = documents.map((d) => d.locale).filter(Boolean);\n\n const where: Record<string, any> = {\n documentId: { $in: documents.map((d) => d.documentId).filter(Boolean) },\n publishedAt: { $null: status === 'published' },\n };\n\n // If there is any locale to filter (if i18n is enabled)\n if (locales.length === documents.length) {\n where.locale = { $in: locales };\n } else if (locales.length) {\n /*\n * The batch mixes localized and non-localized versions, which happens when a\n * content type holds rows with a locale while others have none — for instance\n * after i18n is disabled on it, or when a locale is sent to a non-localized\n * content type through the API.\n *\n * `locales` only holds the locales that are actually set, so filtering on it\n * alone would drop the counterparts of every version whose locale is null, and\n * those versions would be reported as drafts even though they are published.\n */\n where.$or = [{ locale: { $in: locales } }, { locale: { $null: true } }];\n }\n\n return strapi.db.query(uid).findMany({\n where,\n select: AVAILABLE_STATUS_SCALAR_FIELDS,\n });\n },\n\n getStatus(version: DocumentVersion, otherDocumentStatuses?: DocumentMetadata['availableStatus']) {\n let draftVersion: DocumentVersion | undefined;\n let publishedVersion: DocumentVersion | undefined;\n\n if (version.publishedAt) {\n publishedVersion = version;\n } else {\n draftVersion = version;\n }\n\n const otherVersion = otherDocumentStatuses?.at(0);\n if (otherVersion?.publishedAt) {\n publishedVersion = otherVersion;\n } else if (otherVersion) {\n draftVersion = otherVersion;\n }\n\n if (!draftVersion) return CONTENT_MANAGER_STATUS.PUBLISHED;\n if (!publishedVersion) return CONTENT_MANAGER_STATUS.DRAFT;\n\n /*\n * The document is modified if the draft version has been updated more\n * recently than the published version.\n */\n const isDraftModified = getIsVersionLatestModification(draftVersion, publishedVersion);\n return isDraftModified ? CONTENT_MANAGER_STATUS.MODIFIED : CONTENT_MANAGER_STATUS.PUBLISHED;\n },\n\n // TODO is it necessary to return metadata on every page of the CM\n // We could refactor this so the locales are only loaded when they're\n // needed. e.g. in the bulk locale action modal.\n async getMetadata(\n uid: UID.ContentType,\n version: DocumentVersion,\n { availableLocales = true, availableStatus = true }: GetMetadataOptions = {}\n ) {\n const model = strapi.getModel(uid);\n const hasDnP = contentTypes.hasDraftAndPublish(model);\n const isLocalized = strapi.localization.isLocalizedContentType(model);\n\n if (!availableLocales && !availableStatus) {\n // Nothing to compute.\n return { availableLocales: [], availableStatus: [], versions: [] as DocumentVersion[] };\n }\n if (!isLocalized && !hasDnP) {\n // If there are no locales and no draft/publish, there's only ever 1 version of any document.\n return { availableLocales: [], availableStatus: [], versions: [] as DocumentVersion[] };\n }\n\n const onlyStatusIsRelevant = hasDnP && (!isLocalized || !availableLocales);\n if (onlyStatusIsRelevant) {\n const otherVersion = availableStatus\n ? await strapi.db.query(uid).findOne({\n where: {\n documentId: version.documentId,\n ...(version.locale ? { locale: version.locale } : {}),\n publishedAt: oppositePublishStatus(version.publishedAt),\n },\n select: AVAILABLE_STATUS_SCALAR_FIELDS,\n populate: AVAILABLE_STATUS_POPULATE,\n })\n : null;\n return {\n availableLocales: [],\n availableStatus: otherVersion ? [pick(otherVersion, AVAILABLE_STATUS_FIELDS)] : [],\n versions: [] as DocumentVersion[],\n };\n }\n\n // Full path for localized content types\n // TODO: Ignore publishedAt if availableStatus=false, and ignore locale if\n // i18n is disabled\n\n // Include non-translatable scalar and media fields in availableLocales for i18n prefilling\n let nonLocalizedFields: string[] = [];\n let nonLocalizedMediaFields: string[] = [];\n // Without a localization provider there are no non-localized attributes.\n try {\n if (model?.attributes !== undefined) {\n const allNonLocalized = strapi.localization.getNonLocalizedAttributes(model);\n // Get scalar and media attributes separately\n const scalarAttrs = getScalarAttributes(model);\n const mediaAttrs = getMediaAttributes(model);\n\n // Separate scalar fields (can be in fields array) from media fields (need to be populated)\n nonLocalizedFields = allNonLocalized.filter(\n (field) => field in model.attributes && scalarAttrs.includes(field)\n );\n nonLocalizedMediaFields = allNonLocalized.filter(\n (field) => field in model.attributes && mediaAttrs.includes(field)\n );\n }\n } catch {\n // The provider errored — fall back to no prefilled non-localized fields\n }\n\n // Build populate object for non-localized media fields\n const mediaPopulate = nonLocalizedMediaFields.reduce(\n (acc, field) => {\n acc[field] = {\n populate: {\n folder: true,\n },\n };\n return acc;\n },\n {} as Record<string, { populate: { folder: boolean } }>\n );\n\n const params = {\n populate: {\n ...mediaPopulate,\n ...AVAILABLE_STATUS_POPULATE,\n },\n fields: [...new Set([...AVAILABLE_LOCALES_FIELDS, ...nonLocalizedFields])],\n filters: {\n documentId: version.documentId,\n },\n };\n\n const dbParams = strapi.get('query-params').transform(uid, params);\n const versions = await strapi.db.query(uid).findMany(dbParams);\n\n // TODO: Remove use of available locales and use localizations instead\n const availableLocalesResult = availableLocales\n ? await this.getAvailableLocales(uid, version, versions)\n : [];\n\n const availableStatusResult = availableStatus\n ? this.getAvailableStatus(version, versions)\n : null;\n\n return {\n availableLocales: availableLocalesResult,\n availableStatus: availableStatusResult ? [availableStatusResult] : [],\n versions,\n };\n },\n\n /**\n * Returns associated metadata of a document:\n * - Available locales of the document for the current status\n * - Available status of the document for the current locale\n */\n async formatDocumentWithMetadata(\n uid: UID.ContentType,\n document: DocumentVersion,\n opts: GetMetadataOptions = {}\n ) {\n if (!document) {\n return {\n data: document,\n meta: {\n availableLocales: [],\n availableStatus: [],\n },\n };\n }\n\n const hasDraftAndPublish = contentTypes.hasDraftAndPublish(strapi.getModel(uid));\n\n // Ignore available status if the content type does not have draft and publish\n if (!hasDraftAndPublish) {\n opts.availableStatus = false;\n }\n\n const { versions, ...meta } = await this.getMetadata(uid, document, opts);\n\n // Populate localization statuses\n if (document.localizations?.length) {\n document.localizations = document.localizations.map((d) => {\n // Find the counterpart version (same documentId + locale, opposite publishedAt) from\n // the already-fetched versions array, avoiding an extra DB query.\n const counterpart = versions.find(\n (v) =>\n v.documentId === d.documentId &&\n v.locale === d.locale &&\n (d.publishedAt === null) !== (v.publishedAt === null)\n );\n return {\n ...d,\n status: this.getStatus(d, counterpart ? [counterpart] : []),\n };\n });\n }\n\n return {\n data: {\n ...document,\n // Add status to the document only if draft and publish is enabled\n status: hasDraftAndPublish\n ? this.getStatus(document, meta.availableStatus as any)\n : undefined,\n },\n meta,\n };\n },\n});\n"],"names":["getScalarAttributes","getMediaAttributes","contentTypes","AVAILABLE_STATUS_SCALAR_FIELDS","AVAILABLE_STATUS_POPULATE","createdBy","select","updatedBy","AVAILABLE_STATUS_FIELDS","AVAILABLE_LOCALES_FIELDS","oppositePublishStatus","publishedAt","$null","$notNull","CONTENT_MANAGER_STATUS","PUBLISHED","DRAFT","MODIFIED","getIsVersionLatestModification","version","otherVersion","updatedAt","versionUpdatedAt","Date","getTime","otherUpdatedAt","strapi","getAvailableLocales","uid","allVersions","versionsByLocale","groupBy","locale","model","getModel","mappingResult","async","map","Object","values","localeVersions","hasDraftAndPublish","draftVersion","find","v","otherVersions","filter","id","status","getStatus","filtered","Boolean","defaultLocaleCode","localization","getDefaultLocale","undefined","defaultEntries","entry","otherEntries","getAvailableStatus","availableStatus","matchLocale","matchStatus","pick","getManyAvailableStatus","documents","length","locales","d","where","documentId","$in","$or","db","query","findMany","otherDocumentStatuses","publishedVersion","at","isDraftModified","getMetadata","availableLocales","hasDnP","isLocalized","isLocalizedContentType","versions","onlyStatusIsRelevant","findOne","populate","nonLocalizedFields","nonLocalizedMediaFields","attributes","allNonLocalized","getNonLocalizedAttributes","scalarAttrs","mediaAttrs","field","includes","mediaPopulate","reduce","acc","folder","params","fields","Set","filters","dbParams","get","transform","availableLocalesResult","availableStatusResult","formatDocumentWithMetadata","document","opts","data","meta","localizations","counterpart"],"mappings":";;;AAOA,MAAM,EAAEA,mBAAmB,EAAEC,kBAAkB,EAAE,GAAGC,YAAAA;AAWpD;AACA,MAAMC,8BAAAA,GAAiC;AACrC,IAAA,IAAA;AACA,IAAA,YAAA;AACA,IAAA,QAAA;AACA,IAAA,WAAA;AACA,IAAA,WAAA;AACA,IAAA;AACD,CAAA;AACD;AACA,MAAMC,yBAAAA,GAA4B;IAChCC,SAAAA,EAAW;QAAEC,MAAAA,EAAQ;AAAC,YAAA,IAAA;AAAM,YAAA,WAAA;AAAa,YAAA,UAAA;AAAY,YAAA;AAAQ;AAAC,KAAA;IAC9DC,SAAAA,EAAW;QAAED,MAAAA,EAAQ;AAAC,YAAA,IAAA;AAAM,YAAA,WAAA;AAAa,YAAA,UAAA;AAAY,YAAA;AAAQ;AAAC;AAChE,CAAA;AACA;AACA,MAAME,uBAAAA,GAA0B;AAC3BL,IAAAA,GAAAA,8BAAAA;AACH,IAAA,WAAA;AACA,IAAA,WAAA;AACA,IAAA;AACD,CAAA;AACD,MAAMM,wBAAAA,GAA2B;AAC/B,IAAA,IAAA;AACA,IAAA,YAAA;AACA,IAAA,QAAA;AACA,IAAA,WA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,CAAE0B,UAAU,KAAKF,CAAAA,CAAEE,UAAU,IAC7B1B,CAAAA,CAAEZ,MAAM,KAAKoC,CAAAA,CAAEpC,MAAM,IACpBoC,CAAAA,CAAEzD,WAAW,KAAK,IAAA,MAAWiC,CAAAA,CAAEjC,WAAW,KAAK,IAAG,CAAA,CAAA;oBAEvD,OAAO;AACL,wBAAA,GAAGyD,CAAC;AACJpB,wBAAAA,MAAAA,EAAQ,IAAI,CAACC,SAAS,CAACmB,GAAGiD,WAAAA,GAAc;AAACA,4BAAAA;AAAY,yBAAA,GAAG,EAAE;AAC5D,qBAAA;AACF,gBAAA,CAAA,CAAA;AACF,YAAA;YAEA,OAAO;gBACLH,IAAAA,EAAM;AACJ,oBAAA,GAAGF,QAAQ;;oBAEXhE,MAAAA,EAAQP,kBAAAA,GACJ,IAAI,CAACQ,SAAS,CAAC+D,QAAAA,EAAUG,IAAAA,CAAKvD,eAAe,CAAA,GAC7CL;AACN,iBAAA;AACA4D,gBAAAA;AACF,aAAA;AACF,QAAA;AACF,KAAA,CAAC;;;;"}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Old attribute name to the name it has after this save and every earlier
|
|
5
|
+
* save whose map is still stored. Identity entries are omitted: a field that
|
|
6
|
+
* was renamed back to its original name must not keep rewriting itself.
|
|
7
|
+
*/ const composeAttributeRenames = (previous = {}, next = {})=>{
|
|
8
|
+
const composed = {};
|
|
9
|
+
for (const [from, to] of Object.entries(previous)){
|
|
10
|
+
composed[from] = next[to] ?? to;
|
|
11
|
+
}
|
|
12
|
+
for (const [from, to] of Object.entries(next)){
|
|
13
|
+
composed[from] = to;
|
|
14
|
+
}
|
|
15
|
+
for (const [from, to] of Object.entries(composed)){
|
|
16
|
+
if (from === to) {
|
|
17
|
+
delete composed[from];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return composed;
|
|
21
|
+
};
|
|
22
|
+
const renamePath = (path, renames)=>{
|
|
23
|
+
if (!path) {
|
|
24
|
+
return path;
|
|
25
|
+
}
|
|
26
|
+
if (renames[path]) {
|
|
27
|
+
return renames[path];
|
|
28
|
+
}
|
|
29
|
+
const [head, ...rest] = path.split('.');
|
|
30
|
+
if (rest.length > 0 && renames[head]) {
|
|
31
|
+
return [
|
|
32
|
+
renames[head],
|
|
33
|
+
...rest
|
|
34
|
+
].join('.');
|
|
35
|
+
}
|
|
36
|
+
return path;
|
|
37
|
+
};
|
|
38
|
+
const replaceNames = (names, renames)=>{
|
|
39
|
+
const seen = new Set();
|
|
40
|
+
const next = [];
|
|
41
|
+
for (const name of names){
|
|
42
|
+
const renamed = renames[name] ?? name;
|
|
43
|
+
if (seen.has(renamed)) {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
seen.add(renamed);
|
|
47
|
+
next.push(renamed);
|
|
48
|
+
}
|
|
49
|
+
return next;
|
|
50
|
+
};
|
|
51
|
+
const movedMetadata = (metadata, from, to)=>{
|
|
52
|
+
return {
|
|
53
|
+
...metadata,
|
|
54
|
+
edit: metadata.edit ? {
|
|
55
|
+
...metadata.edit,
|
|
56
|
+
label: metadata.edit.label === from ? to : metadata.edit.label
|
|
57
|
+
} : metadata.edit,
|
|
58
|
+
list: metadata.list ? {
|
|
59
|
+
...metadata.list,
|
|
60
|
+
label: metadata.list.label === from ? to : metadata.list.label
|
|
61
|
+
} : metadata.list
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* One pass over the original metadata. Applying the map in place deletes one
|
|
66
|
+
* side of a swap (`title -> slug`, `slug -> title`), because the destination
|
|
67
|
+
* key is still occupied when the source is moved.
|
|
68
|
+
*/ const renameMetadata = (metadatas, renames)=>{
|
|
69
|
+
const next = {};
|
|
70
|
+
for (const [name, metadata] of Object.entries(metadatas)){
|
|
71
|
+
const to = renames[name];
|
|
72
|
+
if (!to || to === name || next[to]) {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
next[to] = movedMetadata(metadata, name, to);
|
|
76
|
+
}
|
|
77
|
+
for (const [name, metadata] of Object.entries(metadatas)){
|
|
78
|
+
const to = renames[name];
|
|
79
|
+
if (to && to !== name || next[name]) {
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
next[name] = metadata;
|
|
83
|
+
}
|
|
84
|
+
return next;
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* A relation's `mainField` names a field on the target, so a rename of that
|
|
88
|
+
* target has to be applied from the configuration of whoever owns the relation.
|
|
89
|
+
*/ const renameRelationMainFields = (metadatas, attributes, allRenames)=>{
|
|
90
|
+
const next = {
|
|
91
|
+
...metadatas
|
|
92
|
+
};
|
|
93
|
+
for (const [name, attribute] of Object.entries(attributes ?? {})){
|
|
94
|
+
if (attribute?.type !== 'relation') {
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
const targetRenames = allRenames[attribute.target ?? attribute.targetModel ?? ''];
|
|
98
|
+
const metadata = next[name];
|
|
99
|
+
if (!targetRenames || !metadata) {
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
next[name] = {
|
|
103
|
+
...metadata,
|
|
104
|
+
edit: metadata.edit ? {
|
|
105
|
+
...metadata.edit,
|
|
106
|
+
mainField: typeof metadata.edit.mainField === 'string' ? targetRenames[metadata.edit.mainField] ?? metadata.edit.mainField : metadata.edit.mainField
|
|
107
|
+
} : metadata.edit,
|
|
108
|
+
list: metadata.list ? {
|
|
109
|
+
...metadata.list,
|
|
110
|
+
mainField: typeof metadata.list.mainField === 'string' ? targetRenames[metadata.list.mainField] ?? metadata.list.mainField : metadata.list.mainField
|
|
111
|
+
} : metadata.list
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
return next;
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* Rewrites one stored Content Manager configuration for a rename save.
|
|
118
|
+
*
|
|
119
|
+
* Returns null when there is nothing to store. A model that has never been
|
|
120
|
+
* opened still gets a configuration when one of its own attributes was
|
|
121
|
+
* renamed, so the browser can repair a column list saved before the rename.
|
|
122
|
+
*/ const rewriteContentManagerConfiguration = (configuration, { attributes, ownRenames = {}, allRenames })=>{
|
|
123
|
+
const hasOwnRenames = Object.keys(ownRenames).length > 0;
|
|
124
|
+
if (!configuration && !hasOwnRenames) {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
const current = configuration ?? {};
|
|
128
|
+
const attributeRenames = composeAttributeRenames(current.attributeRenames, ownRenames);
|
|
129
|
+
const metadatas = renameRelationMainFields(renameMetadata(current.metadatas ?? {}, ownRenames), attributes, allRenames);
|
|
130
|
+
const next = {
|
|
131
|
+
...current,
|
|
132
|
+
settings: current.settings ? {
|
|
133
|
+
...current.settings,
|
|
134
|
+
mainField: renamePath(current.settings.mainField, ownRenames),
|
|
135
|
+
defaultSortBy: renamePath(current.settings.defaultSortBy, ownRenames)
|
|
136
|
+
} : current.settings,
|
|
137
|
+
metadatas,
|
|
138
|
+
layouts: current.layouts ? {
|
|
139
|
+
...current.layouts,
|
|
140
|
+
...Array.isArray(current.layouts.list) ? {
|
|
141
|
+
list: replaceNames(current.layouts.list, ownRenames)
|
|
142
|
+
} : {},
|
|
143
|
+
...Array.isArray(current.layouts.edit) ? {
|
|
144
|
+
edit: current.layouts.edit.map((row)=>row.map((field)=>({
|
|
145
|
+
...field,
|
|
146
|
+
name: ownRenames[field.name] ?? field.name
|
|
147
|
+
})))
|
|
148
|
+
} : {},
|
|
149
|
+
...Array.isArray(current.layouts.editRelations) ? {
|
|
150
|
+
editRelations: replaceNames(current.layouts.editRelations, ownRenames)
|
|
151
|
+
} : {}
|
|
152
|
+
} : current.layouts
|
|
153
|
+
};
|
|
154
|
+
if (Object.keys(attributeRenames).length > 0) {
|
|
155
|
+
next.attributeRenames = attributeRenames;
|
|
156
|
+
} else {
|
|
157
|
+
delete next.attributeRenames;
|
|
158
|
+
}
|
|
159
|
+
return next;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
exports.composeAttributeRenames = composeAttributeRenames;
|
|
163
|
+
exports.rewriteContentManagerConfiguration = rewriteContentManagerConfiguration;
|
|
164
|
+
//# sourceMappingURL=attribute-renames.js.map
|