@strapi/content-manager 0.0.0-next.7315bad3dd6542d457c3c837db874e3e6336ae9f → 0.0.0-next.76a9dc5ca66301db734af3bc2111406c17ccb860

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/dist/_chunks/{ComponentConfigurationPage-DHV8IFbd.js → ComponentConfigurationPage-BLWQy8ru.js} +3 -3
  2. package/dist/_chunks/{ComponentConfigurationPage-DHV8IFbd.js.map → ComponentConfigurationPage-BLWQy8ru.js.map} +1 -1
  3. package/dist/_chunks/{ComponentConfigurationPage-D4J64ny7.mjs → ComponentConfigurationPage-CtIa3aa2.mjs} +3 -3
  4. package/dist/_chunks/{ComponentConfigurationPage-D4J64ny7.mjs.map → ComponentConfigurationPage-CtIa3aa2.mjs.map} +1 -1
  5. package/dist/_chunks/{EditConfigurationPage-DMnf8orh.mjs → EditConfigurationPage-DsPR2DVk.mjs} +3 -3
  6. package/dist/_chunks/{EditConfigurationPage-DMnf8orh.mjs.map → EditConfigurationPage-DsPR2DVk.mjs.map} +1 -1
  7. package/dist/_chunks/{EditConfigurationPage-q76oeVU1.js → EditConfigurationPage-RQkymxCy.js} +3 -3
  8. package/dist/_chunks/{EditConfigurationPage-q76oeVU1.js.map → EditConfigurationPage-RQkymxCy.js.map} +1 -1
  9. package/dist/_chunks/{EditViewPage-BXoY-ITh.js → EditViewPage-B-kExt8C.js} +3 -3
  10. package/dist/_chunks/{EditViewPage-BXoY-ITh.js.map → EditViewPage-B-kExt8C.js.map} +1 -1
  11. package/dist/_chunks/{EditViewPage-COVXj9bh.mjs → EditViewPage-BPyVuPfM.mjs} +3 -3
  12. package/dist/_chunks/{EditViewPage-COVXj9bh.mjs.map → EditViewPage-BPyVuPfM.mjs.map} +1 -1
  13. package/dist/_chunks/{Field-Dj1nOvt8.js → Field-DPIsQRre.js} +117 -61
  14. package/dist/_chunks/Field-DPIsQRre.js.map +1 -0
  15. package/dist/_chunks/{Field-CcppsFQR.mjs → Field-Dltnt1km.mjs} +116 -61
  16. package/dist/_chunks/Field-Dltnt1km.mjs.map +1 -0
  17. package/dist/_chunks/{Form-aTchNxab.js → Form-BFi4MXMT.js} +2 -2
  18. package/dist/_chunks/{Form-aTchNxab.js.map → Form-BFi4MXMT.js.map} +1 -1
  19. package/dist/_chunks/{Form-DbWwH0-A.mjs → Form-C1IcWm1u.mjs} +2 -2
  20. package/dist/_chunks/{Form-DbWwH0-A.mjs.map → Form-C1IcWm1u.mjs.map} +1 -1
  21. package/dist/_chunks/{History-tU567_hc.mjs → History-04ChQ4pl.mjs} +32 -8
  22. package/dist/_chunks/History-04ChQ4pl.mjs.map +1 -0
  23. package/dist/_chunks/{History-Cs6XM6EU.js → History-wjcK4L0C.js} +32 -8
  24. package/dist/_chunks/History-wjcK4L0C.js.map +1 -0
  25. package/dist/_chunks/{ListConfigurationPage-DQryo_4i.mjs → ListConfigurationPage-BYqPYLSU.mjs} +2 -2
  26. package/dist/_chunks/{ListConfigurationPage-DQryo_4i.mjs.map → ListConfigurationPage-BYqPYLSU.mjs.map} +1 -1
  27. package/dist/_chunks/{ListConfigurationPage-7LeytuFD.js → ListConfigurationPage-CRbxIC3J.js} +2 -2
  28. package/dist/_chunks/{ListConfigurationPage-7LeytuFD.js.map → ListConfigurationPage-CRbxIC3J.js.map} +1 -1
  29. package/dist/_chunks/{ListViewPage-CaGBu5H5.js → ListViewPage-D5NY9183.js} +3 -3
  30. package/dist/_chunks/{ListViewPage-CaGBu5H5.js.map → ListViewPage-D5NY9183.js.map} +1 -1
  31. package/dist/_chunks/{ListViewPage-B50esy_x.mjs → ListViewPage-FU2LBuhl.mjs} +3 -3
  32. package/dist/_chunks/{ListViewPage-B50esy_x.mjs.map → ListViewPage-FU2LBuhl.mjs.map} +1 -1
  33. package/dist/_chunks/{NoContentTypePage-BaBE00IO.js → NoContentTypePage-BgQVE_Qb.js} +2 -2
  34. package/dist/_chunks/{NoContentTypePage-BaBE00IO.js.map → NoContentTypePage-BgQVE_Qb.js.map} +1 -1
  35. package/dist/_chunks/{NoContentTypePage-CiPP8cLx.mjs → NoContentTypePage-DCKUkwb8.mjs} +2 -2
  36. package/dist/_chunks/{NoContentTypePage-CiPP8cLx.mjs.map → NoContentTypePage-DCKUkwb8.mjs.map} +1 -1
  37. package/dist/_chunks/{NoPermissionsPage-DQn5cqZz.js → NoPermissionsPage-C5jwn70o.js} +2 -2
  38. package/dist/_chunks/{NoPermissionsPage-DQn5cqZz.js.map → NoPermissionsPage-C5jwn70o.js.map} +1 -1
  39. package/dist/_chunks/{NoPermissionsPage-0-CW106p.mjs → NoPermissionsPage-jqve7C8l.mjs} +2 -2
  40. package/dist/_chunks/{NoPermissionsPage-0-CW106p.mjs.map → NoPermissionsPage-jqve7C8l.mjs.map} +1 -1
  41. package/dist/_chunks/{Preview-C1dBkhXf.mjs → Preview-BMYN548c.mjs} +33 -11
  42. package/dist/_chunks/Preview-BMYN548c.mjs.map +1 -0
  43. package/dist/_chunks/{Preview-DH1h7kJ6.js → Preview-DaOihysv.js} +32 -10
  44. package/dist/_chunks/Preview-DaOihysv.js.map +1 -0
  45. package/dist/_chunks/{Relations-CkECnBOd.js → Relations-CTGM7Hv5.js} +3 -3
  46. package/dist/_chunks/{Relations-CkECnBOd.js.map → Relations-CTGM7Hv5.js.map} +1 -1
  47. package/dist/_chunks/{Relations-Bvne4TvU.mjs → Relations-gscPkxjF.mjs} +3 -3
  48. package/dist/_chunks/{Relations-Bvne4TvU.mjs.map → Relations-gscPkxjF.mjs.map} +1 -1
  49. package/dist/_chunks/{en-BK8Xyl5I.js → en-BzQmavmK.js} +7 -2
  50. package/dist/_chunks/{en-BK8Xyl5I.js.map → en-BzQmavmK.js.map} +1 -1
  51. package/dist/_chunks/{en-Dtk_ot79.mjs → en-CSxLmrh1.mjs} +7 -2
  52. package/dist/_chunks/{en-Dtk_ot79.mjs.map → en-CSxLmrh1.mjs.map} +1 -1
  53. package/dist/_chunks/{index-BN1pPa5v.js → index-Ca7YWlAA.js} +170 -108
  54. package/dist/_chunks/index-Ca7YWlAA.js.map +1 -0
  55. package/dist/_chunks/{index-ByPZ754U.mjs → index-DqasUQ6Q.mjs} +170 -108
  56. package/dist/_chunks/index-DqasUQ6Q.mjs.map +1 -0
  57. package/dist/_chunks/{layout-nBPDlXjr.js → layout-BW80JSCd.js} +3 -3
  58. package/dist/_chunks/{layout-nBPDlXjr.js.map → layout-BW80JSCd.js.map} +1 -1
  59. package/dist/_chunks/{layout-CUTOYU8I.mjs → layout-W3clJSCy.mjs} +3 -3
  60. package/dist/_chunks/{layout-CUTOYU8I.mjs.map → layout-W3clJSCy.mjs.map} +1 -1
  61. package/dist/_chunks/{relations-CBc5HYHC.mjs → relations-BlDkoeWh.mjs} +2 -2
  62. package/dist/_chunks/{relations-CBc5HYHC.mjs.map → relations-BlDkoeWh.mjs.map} +1 -1
  63. package/dist/_chunks/{relations-B6B-b7lI.js → relations-C9Usz9k5.js} +2 -2
  64. package/dist/_chunks/{relations-B6B-b7lI.js.map → relations-C9Usz9k5.js.map} +1 -1
  65. package/dist/admin/index.js +2 -1
  66. package/dist/admin/index.js.map +1 -1
  67. package/dist/admin/index.mjs +2 -1
  68. package/dist/admin/src/exports.d.ts +1 -0
  69. package/dist/admin/src/history/services/historyVersion.d.ts +1 -1
  70. package/dist/admin/src/pages/EditView/components/DocumentStatus.d.ts +1 -1
  71. package/dist/admin/src/pages/EditView/components/FormInputs/BlocksInput/Blocks/Code.d.ts +7 -0
  72. package/dist/admin/src/pages/EditView/components/FormInputs/BlocksInput/Blocks/utils/prismLanguages.d.ts +49 -0
  73. package/dist/admin/src/pages/EditView/components/FormInputs/BlocksInput/utils/constants.d.ts +1 -0
  74. package/dist/admin/src/pages/EditView/components/FormInputs/DynamicZone/DynamicComponent.d.ts +4 -1
  75. package/dist/admin/src/pages/EditView/components/FormInputs/DynamicZone/Field.d.ts +4 -1
  76. package/dist/admin/src/preview/services/preview.d.ts +1 -1
  77. package/dist/admin/src/services/api.d.ts +1 -1
  78. package/dist/admin/src/services/components.d.ts +2 -2
  79. package/dist/admin/src/services/contentTypes.d.ts +3 -3
  80. package/dist/admin/src/services/documents.d.ts +16 -16
  81. package/dist/admin/src/services/init.d.ts +1 -1
  82. package/dist/admin/src/services/relations.d.ts +2 -2
  83. package/dist/admin/src/services/uid.d.ts +3 -3
  84. package/dist/server/index.js +156 -142
  85. package/dist/server/index.js.map +1 -1
  86. package/dist/server/index.mjs +157 -143
  87. package/dist/server/index.mjs.map +1 -1
  88. package/dist/server/src/controllers/utils/metadata.d.ts +1 -0
  89. package/dist/server/src/controllers/utils/metadata.d.ts.map +1 -1
  90. package/dist/server/src/history/controllers/history-version.d.ts +1 -1
  91. package/dist/server/src/history/controllers/history-version.d.ts.map +1 -1
  92. package/dist/server/src/history/services/history.d.ts +3 -3
  93. package/dist/server/src/history/services/history.d.ts.map +1 -1
  94. package/dist/server/src/history/services/utils.d.ts +6 -10
  95. package/dist/server/src/history/services/utils.d.ts.map +1 -1
  96. package/dist/server/src/index.d.ts +3 -2
  97. package/dist/server/src/index.d.ts.map +1 -1
  98. package/dist/server/src/preview/index.d.ts.map +1 -1
  99. package/dist/server/src/services/document-metadata.d.ts +4 -2
  100. package/dist/server/src/services/document-metadata.d.ts.map +1 -1
  101. package/dist/server/src/services/index.d.ts +3 -2
  102. package/dist/server/src/services/index.d.ts.map +1 -1
  103. package/dist/server/src/services/utils/configuration/index.d.ts +2 -2
  104. package/dist/server/src/services/utils/configuration/layouts.d.ts +2 -2
  105. package/dist/server/src/services/utils/populate.d.ts +2 -2
  106. package/dist/server/src/services/utils/populate.d.ts.map +1 -1
  107. package/package.json +8 -7
  108. package/dist/_chunks/Field-CcppsFQR.mjs.map +0 -1
  109. package/dist/_chunks/Field-Dj1nOvt8.js.map +0 -1
  110. package/dist/_chunks/History-Cs6XM6EU.js.map +0 -1
  111. package/dist/_chunks/History-tU567_hc.mjs.map +0 -1
  112. package/dist/_chunks/Preview-C1dBkhXf.mjs.map +0 -1
  113. package/dist/_chunks/Preview-DH1h7kJ6.js.map +0 -1
  114. package/dist/_chunks/index-BN1pPa5v.js.map +0 -1
  115. package/dist/_chunks/index-ByPZ754U.mjs.map +0 -1
  116. package/dist/admin/src/preview/constants.d.ts +0 -1
  117. package/dist/server/src/preview/constants.d.ts +0 -2
  118. package/dist/server/src/preview/constants.d.ts.map +0 -1
@@ -175,19 +175,16 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
175
175
  });
176
176
  })
177
177
  );
178
- return existingAndMissingRelations.filter(
179
- (relation) => relation !== null
180
- );
178
+ return existingAndMissingRelations.filter((relation) => relation !== null);
181
179
  }
182
180
  return strapi2.documents(attribute.target).findOne({
183
181
  documentId: versionRelationData.documentId,
184
182
  locale: versionRelationData.locale || void 0
185
183
  });
186
184
  };
187
- const getMediaRestoreValue = async (versionRelationData, attribute) => {
188
- if (attribute.multiple) {
185
+ const getMediaRestoreValue = async (versionRelationData) => {
186
+ if (Array.isArray(versionRelationData)) {
189
187
  const existingAndMissingMedias = await Promise.all(
190
- // @ts-expect-error Fix the type definitions so this isn't any
191
188
  versionRelationData.map((media) => {
192
189
  return strapi2.db.query("plugin::upload.file").findOne({ where: { id: media.id } });
193
190
  })
@@ -356,8 +353,8 @@ const createHistoryService = ({ strapi: strapi2 }) => {
356
353
  });
357
354
  },
358
355
  async findVersionsPage(params) {
359
- const model = strapi2.getModel(params.query.contentType);
360
- const isLocalizedContentType = serviceUtils.isLocalizedContentType(model);
356
+ const schema = strapi2.getModel(params.query.contentType);
357
+ const isLocalizedContentType = serviceUtils.isLocalizedContentType(schema);
361
358
  const defaultLocale = await serviceUtils.getDefaultLocale();
362
359
  let locale = null;
363
360
  if (isLocalizedContentType) {
@@ -378,32 +375,20 @@ const createHistoryService = ({ strapi: strapi2 }) => {
378
375
  }),
379
376
  serviceUtils.getLocaleDictionary()
380
377
  ]);
381
- const populateEntryRelations = async (entry) => {
382
- const entryWithRelations = await Object.entries(entry.schema).reduce(
383
- async (currentDataWithRelations, [attributeKey, attributeSchema]) => {
384
- const attributeValue = entry.data[attributeKey];
385
- const attributeValues = Array.isArray(attributeValue) ? attributeValue : [attributeValue];
386
- if (attributeSchema.type === "media") {
387
- const permissionChecker2 = getService$2("permission-checker").create({
388
- userAbility: params.state.userAbility,
389
- model: "plugin::upload.file"
390
- });
391
- const response = await serviceUtils.buildMediaResponse(attributeValues);
392
- const sanitizedResults = await Promise.all(
393
- response.results.map((media) => permissionChecker2.sanitizeOutput(media))
394
- );
395
- return {
396
- ...await currentDataWithRelations,
397
- [attributeKey]: {
398
- results: sanitizedResults,
399
- meta: response.meta
400
- }
401
- };
378
+ const populateEntry = async (entry) => {
379
+ return strapiUtils.traverseEntity(
380
+ async (options, utils) => {
381
+ if (!options.attribute) return;
382
+ if (!options.value) return;
383
+ const currentValue = Array.isArray(options.value) ? options.value : [options.value];
384
+ if (options.attribute.type === "component") {
385
+ utils.remove("id");
402
386
  }
403
- if (attributeSchema.type === "relation" && attributeSchema.relation !== "morphToOne" && attributeSchema.relation !== "morphToMany") {
404
- if (attributeSchema.target === "admin::user") {
387
+ if (options.attribute.type === "relation" && // TODO: handle polymorphic relations
388
+ options.attribute.relation !== "morphToOne" && options.attribute.relation !== "morphToMany") {
389
+ if (options.attribute.target === "admin::user") {
405
390
  const adminUsers = await Promise.all(
406
- attributeValues.map((userToPopulate) => {
391
+ currentValue.map((userToPopulate) => {
407
392
  if (userToPopulate == null) {
408
393
  return null;
409
394
  }
@@ -415,46 +400,51 @@ const createHistoryService = ({ strapi: strapi2 }) => {
415
400
  });
416
401
  })
417
402
  );
418
- return {
419
- ...await currentDataWithRelations,
420
- /**
421
- * Ideally we would return the same "{results: [], meta: {}}" shape, however,
422
- * when sanitizing the data as a whole in the controller before sending to the client,
423
- * the data for admin relation user is completely sanitized if we return an object here as opposed to an array.
424
- */
425
- [attributeKey]: adminUsers
426
- };
403
+ utils.set(options.key, adminUsers);
427
404
  }
428
405
  const permissionChecker2 = getService$2("permission-checker").create({
429
406
  userAbility: params.state.userAbility,
430
- model: attributeSchema.target
407
+ model: options.attribute.target
431
408
  });
432
409
  const response = await serviceUtils.buildRelationReponse(
433
- attributeValues,
434
- attributeSchema
410
+ currentValue,
411
+ options.attribute
435
412
  );
436
413
  const sanitizedResults = await Promise.all(
437
414
  response.results.map((media) => permissionChecker2.sanitizeOutput(media))
438
415
  );
439
- return {
440
- ...await currentDataWithRelations,
441
- [attributeKey]: {
442
- results: sanitizedResults,
443
- meta: response.meta
444
- }
445
- };
416
+ utils.set(options.key, {
417
+ results: sanitizedResults,
418
+ meta: response.meta
419
+ });
420
+ }
421
+ if (options.attribute.type === "media") {
422
+ const permissionChecker2 = getService$2("permission-checker").create({
423
+ userAbility: params.state.userAbility,
424
+ model: "plugin::upload.file"
425
+ });
426
+ const response = await serviceUtils.buildMediaResponse(currentValue);
427
+ const sanitizedResults = await Promise.all(
428
+ response.results.map((media) => permissionChecker2.sanitizeOutput(media))
429
+ );
430
+ utils.set(options.key, {
431
+ results: sanitizedResults,
432
+ meta: response.meta
433
+ });
446
434
  }
447
- return currentDataWithRelations;
448
435
  },
449
- Promise.resolve(entry.data)
436
+ {
437
+ schema,
438
+ getModel: strapi2.getModel.bind(strapi2)
439
+ },
440
+ entry.data
450
441
  );
451
- return entryWithRelations;
452
442
  };
453
443
  const formattedResults = await Promise.all(
454
444
  results.map(async (result) => {
455
445
  return {
456
446
  ...result,
457
- data: await populateEntryRelations(result),
447
+ data: await populateEntry(result),
458
448
  meta: {
459
449
  unknownAttributes: serviceUtils.getSchemaAttributesDiff(
460
450
  result.schema,
@@ -485,30 +475,44 @@ const createHistoryService = ({ strapi: strapi2 }) => {
485
475
  // Clone to avoid mutating the original version data
486
476
  structuredClone(version.data)
487
477
  );
488
- const sanitizedSchemaAttributes = fp.omit(
489
- FIELDS_TO_IGNORE,
490
- contentTypeSchemaAttributes
491
- );
492
- const reducer = strapiUtils.async.reduce(Object.entries(sanitizedSchemaAttributes));
493
- const dataWithoutMissingRelations = await reducer(
494
- async (previousRelationAttributes, [name, attribute]) => {
495
- const versionRelationData = version.data[name];
496
- if (!versionRelationData) {
497
- return previousRelationAttributes;
478
+ const schema = structuredClone(version.schema);
479
+ schema.attributes = fp.omit(FIELDS_TO_IGNORE, contentTypeSchemaAttributes);
480
+ const dataWithoutMissingRelations = await strapiUtils.traverseEntity(
481
+ async (options, utils) => {
482
+ if (!options.attribute) return;
483
+ if (options.attribute.type === "component") {
484
+ utils.remove("id");
485
+ if (options.attribute.repeatable && options.value === null) {
486
+ utils.set(options.key, []);
487
+ }
488
+ }
489
+ if (options.attribute.type === "dynamiczone") {
490
+ if (options.value === null) {
491
+ utils.set(options.key, []);
492
+ }
498
493
  }
499
- if (attribute.type === "relation" && // TODO: handle polymorphic relations
500
- attribute.relation !== "morphToOne" && attribute.relation !== "morphToMany") {
501
- const data2 = await serviceUtils.getRelationRestoreValue(versionRelationData, attribute);
502
- previousRelationAttributes[name] = data2;
494
+ if (options.attribute.type === "relation" && // TODO: handle polymorphic relations
495
+ options.attribute.relation !== "morphToOne" && options.attribute.relation !== "morphToMany") {
496
+ if (!options.value) return;
497
+ const data2 = await serviceUtils.getRelationRestoreValue(
498
+ options.value,
499
+ options.attribute
500
+ );
501
+ utils.set(options.key, data2);
503
502
  }
504
- if (attribute.type === "media") {
505
- const data2 = await serviceUtils.getMediaRestoreValue(versionRelationData, attribute);
506
- previousRelationAttributes[name] = data2;
503
+ if (options.attribute.type === "media") {
504
+ if (!options.value) return;
505
+ const data2 = await serviceUtils.getMediaRestoreValue(
506
+ options.value
507
+ );
508
+ utils.set(options.key, data2);
507
509
  }
508
- return previousRelationAttributes;
509
510
  },
510
- // Clone to avoid mutating the original version data
511
- structuredClone(dataWithoutAddedAttributes)
511
+ {
512
+ schema,
513
+ getModel: strapi2.getModel.bind(strapi2)
514
+ },
515
+ dataWithoutAddedAttributes
512
516
  );
513
517
  const data = fp.omit(["id", ...Object.keys(schemaDiff.removed)], dataWithoutMissingRelations);
514
518
  const restoredDocument = await strapi2.documents(version.contentType).update({
@@ -737,7 +741,6 @@ const getFeature$1 = () => {
737
741
  };
738
742
  };
739
743
  const history = getFeature$1();
740
- const FEATURE_ID = "preview";
741
744
  const info = { pluginName: "content-manager", type: "admin" };
742
745
  const previewRouter = {
743
746
  type: "admin",
@@ -915,9 +918,6 @@ const services$1 = {
915
918
  "preview-config": createPreviewConfigService
916
919
  };
917
920
  const getFeature = () => {
918
- if (!strapi.features.future.isEnabled(FEATURE_ID)) {
919
- return {};
920
- }
921
921
  return {
922
922
  register() {
923
923
  const config = getService(strapi, "preview-config");
@@ -3933,6 +3933,12 @@ function getPopulateForRelation(attribute, model, attributeName, { countMany, co
3933
3933
  if (initialPopulate) {
3934
3934
  return initialPopulate;
3935
3935
  }
3936
+ if (attributeName === "localizations") {
3937
+ const validationPopulate = getPopulateForValidation(model.uid);
3938
+ return {
3939
+ populate: validationPopulate.populate
3940
+ };
3941
+ }
3936
3942
  if (!isVisibleAttribute$1(model, attributeName)) {
3937
3943
  return true;
3938
3944
  }
@@ -3992,6 +3998,9 @@ const getDeepPopulate = (uid2, {
3992
3998
  return {};
3993
3999
  }
3994
4000
  const model = strapi.getModel(uid2);
4001
+ if (!model) {
4002
+ return {};
4003
+ }
3995
4004
  return Object.keys(model.attributes).reduce(
3996
4005
  (populateAcc, attributeName) => fp.merge(
3997
4006
  populateAcc,
@@ -4011,40 +4020,46 @@ const getDeepPopulate = (uid2, {
4011
4020
  {}
4012
4021
  );
4013
4022
  };
4014
- const getValidatableFieldsPopulate = (uid2, {
4015
- initialPopulate = {},
4016
- countMany = false,
4017
- countOne = false,
4018
- maxLevel = Infinity
4019
- } = {}, level = 1) => {
4020
- if (level > maxLevel) {
4023
+ const getPopulateForValidation = (uid2) => {
4024
+ const model = strapi.getModel(uid2);
4025
+ if (!model) {
4021
4026
  return {};
4022
4027
  }
4023
- const model = strapi.getModel(uid2);
4024
4028
  return Object.entries(model.attributes).reduce((populateAcc, [attributeName, attribute]) => {
4025
- if (!getDoesAttributeRequireValidation(attribute)) {
4029
+ if (isScalarAttribute(attribute)) {
4030
+ if (getDoesAttributeRequireValidation(attribute)) {
4031
+ populateAcc.fields = populateAcc.fields || [];
4032
+ populateAcc.fields.push(attributeName);
4033
+ }
4026
4034
  return populateAcc;
4027
4035
  }
4028
- if (isScalarAttribute(attribute)) {
4029
- return fp.merge(populateAcc, {
4030
- [attributeName]: true
4031
- });
4036
+ if (isComponent(attribute)) {
4037
+ const component = attribute.component;
4038
+ const componentResult = getPopulateForValidation(component);
4039
+ if (Object.keys(componentResult).length > 0) {
4040
+ populateAcc.populate = populateAcc.populate || {};
4041
+ populateAcc.populate[attributeName] = componentResult;
4042
+ }
4043
+ return populateAcc;
4032
4044
  }
4033
- return fp.merge(
4034
- populateAcc,
4035
- getPopulateFor(
4036
- attributeName,
4037
- model,
4038
- {
4039
- // @ts-expect-error - improve types
4040
- initialPopulate: initialPopulate?.[attributeName],
4041
- countMany,
4042
- countOne,
4043
- maxLevel
4045
+ if (isDynamicZone(attribute)) {
4046
+ const components2 = attribute.components;
4047
+ const componentsResult = (components2 || []).reduce(
4048
+ (acc, componentUID) => {
4049
+ const componentResult = getPopulateForValidation(componentUID);
4050
+ if (Object.keys(componentResult).length > 0) {
4051
+ acc[componentUID] = componentResult;
4052
+ }
4053
+ return acc;
4044
4054
  },
4045
- level
4046
- )
4047
- );
4055
+ {}
4056
+ );
4057
+ if (Object.keys(componentsResult).length > 0) {
4058
+ populateAcc.populate = populateAcc.populate || {};
4059
+ populateAcc.populate[attributeName] = { on: componentsResult };
4060
+ }
4061
+ }
4062
+ return populateAcc;
4048
4063
  }, {});
4049
4064
  };
4050
4065
  const getDeepPopulateDraftCount = (uid2) => {
@@ -4286,7 +4301,6 @@ const AVAILABLE_LOCALES_FIELDS = [
4286
4301
  "locale",
4287
4302
  "updatedAt",
4288
4303
  "createdAt",
4289
- "status",
4290
4304
  "publishedAt",
4291
4305
  "documentId"
4292
4306
  ];
@@ -4307,36 +4321,20 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4307
4321
  /**
4308
4322
  * Returns available locales of a document for the current status
4309
4323
  */
4310
- async getAvailableLocales(uid2, version, allVersions, validatableFields = []) {
4324
+ async getAvailableLocales(uid2, version, allVersions) {
4311
4325
  const versionsByLocale = fp.groupBy("locale", allVersions);
4312
4326
  if (version.locale) {
4313
4327
  delete versionsByLocale[version.locale];
4314
4328
  }
4315
4329
  const model = strapi2.getModel(uid2);
4316
- const keysToKeep = [...AVAILABLE_LOCALES_FIELDS, ...validatableFields];
4317
- const traversalFunction = async (localeVersion) => strapiUtils.traverseEntity(
4318
- ({ key }, { remove }) => {
4319
- if (keysToKeep.includes(key)) {
4320
- return;
4321
- }
4322
- remove(key);
4323
- },
4324
- { schema: model, getModel: strapi2.getModel.bind(strapi2) },
4325
- // @ts-expect-error fix types DocumentVersion incompatible with Data
4326
- localeVersion
4327
- );
4328
4330
  const mappingResult = await strapiUtils.async.map(
4329
4331
  Object.values(versionsByLocale),
4330
4332
  async (localeVersions) => {
4331
- const mappedLocaleVersions = await strapiUtils.async.map(
4332
- localeVersions,
4333
- traversalFunction
4334
- );
4335
4333
  if (!strapiUtils.contentTypes.hasDraftAndPublish(model)) {
4336
- return mappedLocaleVersions[0];
4334
+ return localeVersions[0];
4337
4335
  }
4338
- const draftVersion = mappedLocaleVersions.find((v) => v.publishedAt === null);
4339
- const otherVersions = mappedLocaleVersions.filter((v) => v.id !== draftVersion?.id);
4336
+ const draftVersion = localeVersions.find((v) => v.publishedAt === null);
4337
+ const otherVersions = localeVersions.filter((v) => v.id !== draftVersion?.id);
4340
4338
  if (!draftVersion) {
4341
4339
  return;
4342
4340
  }
@@ -4370,15 +4368,17 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4370
4368
  async getManyAvailableStatus(uid2, documents) {
4371
4369
  if (!documents.length) return [];
4372
4370
  const status = documents[0].publishedAt !== null ? "published" : "draft";
4373
- const locale = documents[0]?.locale;
4374
- const otherStatus = status === "published" ? "draft" : "published";
4375
- return strapi2.documents(uid2).findMany({
4376
- filters: {
4377
- documentId: { $in: documents.map((d) => d.documentId).filter(Boolean) }
4378
- },
4379
- status: otherStatus,
4380
- locale,
4381
- fields: ["documentId", "locale", "updatedAt", "createdAt", "publishedAt"]
4371
+ const locales = documents.map((d) => d.locale).filter(Boolean);
4372
+ const where = {
4373
+ documentId: { $in: documents.map((d) => d.documentId).filter(Boolean) },
4374
+ publishedAt: { $null: status === "published" }
4375
+ };
4376
+ if (locales.length) {
4377
+ where.locale = { $in: locales };
4378
+ }
4379
+ return strapi2.query(uid2).findMany({
4380
+ where,
4381
+ select: ["id", "documentId", "locale", "updatedAt", "createdAt", "publishedAt"]
4382
4382
  });
4383
4383
  },
4384
4384
  getStatus(version, otherDocumentStatuses) {
@@ -4404,11 +4404,9 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4404
4404
  // We could refactor this so the locales are only loaded when they're
4405
4405
  // needed. e.g. in the bulk locale action modal.
4406
4406
  async getMetadata(uid2, version, { availableLocales = true, availableStatus = true } = {}) {
4407
- const populate = getValidatableFieldsPopulate(uid2);
4408
- const versions = await strapi2.db.query(uid2).findMany({
4409
- where: { documentId: version.documentId },
4407
+ const { populate = {}, fields = [] } = getPopulateForValidation(uid2);
4408
+ const params = {
4410
4409
  populate: {
4411
- // Populate only fields that require validation for bulk locale actions
4412
4410
  ...populate,
4413
4411
  // NOTE: creator fields are selected in this way to avoid exposing sensitive data
4414
4412
  createdBy: {
@@ -4417,9 +4415,15 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4417
4415
  updatedBy: {
4418
4416
  select: ["id", "firstname", "lastname", "email"]
4419
4417
  }
4418
+ },
4419
+ fields: fp.uniq([...AVAILABLE_LOCALES_FIELDS, ...fields]),
4420
+ filters: {
4421
+ documentId: version.documentId
4420
4422
  }
4421
- });
4422
- const availableLocalesResult = availableLocales ? await this.getAvailableLocales(uid2, version, versions, Object.keys(populate)) : [];
4423
+ };
4424
+ const dbParams = strapi2.get("query-params").transform(uid2, params);
4425
+ const versions = await strapi2.db.query(uid2).findMany(dbParams);
4426
+ const availableLocalesResult = availableLocales ? await this.getAvailableLocales(uid2, version, versions) : [];
4423
4427
  const availableStatusResult = availableStatus ? this.getAvailableStatus(version, versions) : null;
4424
4428
  return {
4425
4429
  availableLocales: availableLocalesResult,
@@ -4446,6 +4450,16 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4446
4450
  opts.availableStatus = false;
4447
4451
  }
4448
4452
  const meta = await this.getMetadata(uid2, document, opts);
4453
+ if (document.localizations) {
4454
+ const otherStatus = await this.getManyAvailableStatus(uid2, document.localizations);
4455
+ document.localizations = document.localizations.map((d) => {
4456
+ const status = otherStatus.find((s) => s.documentId === d.documentId);
4457
+ return {
4458
+ ...d,
4459
+ status: this.getStatus(d, status ? [status] : [])
4460
+ };
4461
+ });
4462
+ }
4449
4463
  return {
4450
4464
  data: {
4451
4465
  ...document,