@strapi/content-manager 0.0.0-next.8414b837972392b1d362ae53b86b5da1eb2ad05c → 0.0.0-next.926e9af9369b89a571145e3c8fa1ce6bfd6cc0ab

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 (123) hide show
  1. package/dist/_chunks/{ComponentConfigurationPage-BTR_hQow.js → ComponentConfigurationPage-DMxUlNOo.js} +3 -3
  2. package/dist/_chunks/{ComponentConfigurationPage-BTR_hQow.js.map → ComponentConfigurationPage-DMxUlNOo.js.map} +1 -1
  3. package/dist/_chunks/{ComponentConfigurationPage-bLQr82ce.mjs → ComponentConfigurationPage-baEkO-OV.mjs} +3 -3
  4. package/dist/_chunks/{ComponentConfigurationPage-bLQr82ce.mjs.map → ComponentConfigurationPage-baEkO-OV.mjs.map} +1 -1
  5. package/dist/_chunks/{EditConfigurationPage-z39Wv3E6.js → EditConfigurationPage-CXxV7mKn.js} +3 -3
  6. package/dist/_chunks/{EditConfigurationPage-z39Wv3E6.js.map → EditConfigurationPage-CXxV7mKn.js.map} +1 -1
  7. package/dist/_chunks/{EditConfigurationPage-BhRSnUsL.mjs → EditConfigurationPage-YR8-4VCS.mjs} +3 -3
  8. package/dist/_chunks/{EditConfigurationPage-BhRSnUsL.mjs.map → EditConfigurationPage-YR8-4VCS.mjs.map} +1 -1
  9. package/dist/_chunks/{EditViewPage-wujOq90c.js → EditViewPage-BfR6jAR6.js} +13 -76
  10. package/dist/_chunks/EditViewPage-BfR6jAR6.js.map +1 -0
  11. package/dist/_chunks/{EditViewPage-BCjNxNlY.mjs → EditViewPage-DFF7c27p.mjs} +11 -74
  12. package/dist/_chunks/EditViewPage-DFF7c27p.mjs.map +1 -0
  13. package/dist/_chunks/{Form-D7mexvm3.js → Form-CjcMRP5A.js} +2 -2
  14. package/dist/_chunks/{Form-D7mexvm3.js.map → Form-CjcMRP5A.js.map} +1 -1
  15. package/dist/_chunks/{Form-BZgvE8C8.mjs → Form-MSOSfGGN.mjs} +2 -2
  16. package/dist/_chunks/{Form-BZgvE8C8.mjs.map → Form-MSOSfGGN.mjs.map} +1 -1
  17. package/dist/_chunks/{History-DYl2A8Z_.js → History-BgZ7gVuF.js} +43 -19
  18. package/dist/_chunks/History-BgZ7gVuF.js.map +1 -0
  19. package/dist/_chunks/{History-CqNgxkqK.mjs → History-WOQNVho-.mjs} +32 -8
  20. package/dist/_chunks/History-WOQNVho-.mjs.map +1 -0
  21. package/dist/_chunks/{Field-Byr3mPTl.mjs → Input-BkKwZ6Qt.mjs} +1131 -1188
  22. package/dist/_chunks/Input-BkKwZ6Qt.mjs.map +1 -0
  23. package/dist/_chunks/{Field-B5QXnctJ.js → Input-BwOibhc3.js} +1212 -1269
  24. package/dist/_chunks/Input-BwOibhc3.js.map +1 -0
  25. package/dist/_chunks/{ListConfigurationPage-BbQjzKkQ.mjs → ListConfigurationPage-BeXfr6uW.mjs} +2 -2
  26. package/dist/_chunks/{ListConfigurationPage-BbQjzKkQ.mjs.map → ListConfigurationPage-BeXfr6uW.mjs.map} +1 -1
  27. package/dist/_chunks/{ListConfigurationPage-BXnu_OoY.js → ListConfigurationPage-DnJ3nbwL.js} +2 -2
  28. package/dist/_chunks/{ListConfigurationPage-BXnu_OoY.js.map → ListConfigurationPage-DnJ3nbwL.js.map} +1 -1
  29. package/dist/_chunks/{ListViewPage-BtSi8C1l.js → ListViewPage-CJFDudKl.js} +13 -10
  30. package/dist/_chunks/{ListViewPage-BtSi8C1l.js.map → ListViewPage-CJFDudKl.js.map} +1 -1
  31. package/dist/_chunks/{ListViewPage-D4ofkbjR.mjs → ListViewPage-VK2v44Q1.mjs} +8 -5
  32. package/dist/_chunks/{ListViewPage-D4ofkbjR.mjs.map → ListViewPage-VK2v44Q1.mjs.map} +1 -1
  33. package/dist/_chunks/{NoContentTypePage-DyUx5mXh.mjs → NoContentTypePage-T8ttty6K.mjs} +2 -2
  34. package/dist/_chunks/{NoContentTypePage-DyUx5mXh.mjs.map → NoContentTypePage-T8ttty6K.mjs.map} +1 -1
  35. package/dist/_chunks/{NoContentTypePage-CitJeOq4.js → NoContentTypePage-en2PwWgI.js} +2 -2
  36. package/dist/_chunks/{NoContentTypePage-CitJeOq4.js.map → NoContentTypePage-en2PwWgI.js.map} +1 -1
  37. package/dist/_chunks/{NoPermissionsPage-DzgWz0M-.js → NoPermissionsPage-CcjILry3.js} +2 -2
  38. package/dist/_chunks/{NoPermissionsPage-DzgWz0M-.js.map → NoPermissionsPage-CcjILry3.js.map} +1 -1
  39. package/dist/_chunks/{NoPermissionsPage-DhIiyWkk.mjs → NoPermissionsPage-CokBHhhy.mjs} +2 -2
  40. package/dist/_chunks/{NoPermissionsPage-DhIiyWkk.mjs.map → NoPermissionsPage-CokBHhhy.mjs.map} +1 -1
  41. package/dist/_chunks/{Preview-BaYGJ0nb.mjs → Preview-BF81YhRj.mjs} +10 -16
  42. package/dist/_chunks/Preview-BF81YhRj.mjs.map +1 -0
  43. package/dist/_chunks/{Preview-DfNx8Ke-.js → Preview-DgzAuzWQ.js} +10 -16
  44. package/dist/_chunks/Preview-DgzAuzWQ.js.map +1 -0
  45. package/dist/_chunks/{Relations-DuKCaXrv.js → Relations-1O-JcM4t.js} +3 -3
  46. package/dist/_chunks/{Relations-DuKCaXrv.js.map → Relations-1O-JcM4t.js.map} +1 -1
  47. package/dist/_chunks/{Relations-DM2yUTST.mjs → Relations-BncdhGCd.mjs} +3 -3
  48. package/dist/_chunks/{Relations-DM2yUTST.mjs.map → Relations-BncdhGCd.mjs.map} +1 -1
  49. package/dist/_chunks/{en-Dtk_ot79.mjs → en-BZaUty0m.mjs} +8 -2
  50. package/dist/_chunks/{en-Dtk_ot79.mjs.map → en-BZaUty0m.mjs.map} +1 -1
  51. package/dist/_chunks/{en-BK8Xyl5I.js → en-CzCnBk4S.js} +8 -2
  52. package/dist/_chunks/{en-BK8Xyl5I.js.map → en-CzCnBk4S.js.map} +1 -1
  53. package/dist/_chunks/{index-DVAIIsOs.mjs → index-DiluOUp6.mjs} +214 -48
  54. package/dist/_chunks/index-DiluOUp6.mjs.map +1 -0
  55. package/dist/_chunks/{index-BUWEmX8m.js → index-EXJvmn4t.js} +197 -31
  56. package/dist/_chunks/index-EXJvmn4t.js.map +1 -0
  57. package/dist/_chunks/{layout-C3fN7Ejz.js → layout-4TbKVax8.js} +3 -3
  58. package/dist/_chunks/{layout-C3fN7Ejz.js.map → layout-4TbKVax8.js.map} +1 -1
  59. package/dist/_chunks/{layout-Bxsv5mP7.mjs → layout-mSwsYzxv.mjs} +3 -3
  60. package/dist/_chunks/{layout-Bxsv5mP7.mjs.map → layout-mSwsYzxv.mjs.map} +1 -1
  61. package/dist/_chunks/{relations-o3pPhzY4.mjs → relations--YOvQBqv.mjs} +2 -2
  62. package/dist/_chunks/{relations-o3pPhzY4.mjs.map → relations--YOvQBqv.mjs.map} +1 -1
  63. package/dist/_chunks/{relations-BPZKAoEY.js → relations-Ai6Izh7h.js} +2 -2
  64. package/dist/_chunks/{relations-BPZKAoEY.js.map → relations-Ai6Izh7h.js.map} +1 -1
  65. package/dist/_chunks/{useDebounce-DmuSJIF3.mjs → usePrev-CZGy2Vjf.mjs} +11 -11
  66. package/dist/_chunks/usePrev-CZGy2Vjf.mjs.map +1 -0
  67. package/dist/_chunks/{useDebounce-CtcjDB3L.js → usePrev-D5J_2fEu.js} +8 -8
  68. package/dist/_chunks/usePrev-D5J_2fEu.js.map +1 -0
  69. package/dist/admin/index.js +2 -1
  70. package/dist/admin/index.js.map +1 -1
  71. package/dist/admin/index.mjs +6 -5
  72. package/dist/admin/src/exports.d.ts +1 -0
  73. package/dist/admin/src/history/services/historyVersion.d.ts +1 -1
  74. package/dist/admin/src/hooks/useDocument.d.ts +19 -2
  75. package/dist/admin/src/pages/EditView/components/DocumentStatus.d.ts +1 -1
  76. package/dist/admin/src/pages/EditView/components/FormInputs/DynamicZone/DynamicComponent.d.ts +4 -1
  77. package/dist/admin/src/pages/EditView/components/FormInputs/DynamicZone/Field.d.ts +4 -1
  78. package/dist/admin/src/pages/EditView/components/FormLayout.d.ts +27 -0
  79. package/dist/admin/src/pages/EditView/utils/data.d.ts +1 -0
  80. package/dist/admin/src/preview/pages/Preview.d.ts +1 -1
  81. package/dist/admin/src/preview/services/preview.d.ts +1 -1
  82. package/dist/admin/src/services/api.d.ts +1 -1
  83. package/dist/admin/src/services/components.d.ts +2 -2
  84. package/dist/admin/src/services/contentTypes.d.ts +3 -3
  85. package/dist/admin/src/services/documents.d.ts +16 -16
  86. package/dist/admin/src/services/init.d.ts +1 -1
  87. package/dist/admin/src/services/relations.d.ts +2 -2
  88. package/dist/admin/src/services/uid.d.ts +3 -3
  89. package/dist/server/index.js +156 -138
  90. package/dist/server/index.js.map +1 -1
  91. package/dist/server/index.mjs +157 -139
  92. package/dist/server/index.mjs.map +1 -1
  93. package/dist/server/src/controllers/utils/metadata.d.ts +1 -0
  94. package/dist/server/src/controllers/utils/metadata.d.ts.map +1 -1
  95. package/dist/server/src/history/controllers/history-version.d.ts +1 -1
  96. package/dist/server/src/history/controllers/history-version.d.ts.map +1 -1
  97. package/dist/server/src/history/services/history.d.ts +3 -3
  98. package/dist/server/src/history/services/history.d.ts.map +1 -1
  99. package/dist/server/src/history/services/utils.d.ts +6 -10
  100. package/dist/server/src/history/services/utils.d.ts.map +1 -1
  101. package/dist/server/src/index.d.ts +3 -2
  102. package/dist/server/src/index.d.ts.map +1 -1
  103. package/dist/server/src/services/document-metadata.d.ts +4 -2
  104. package/dist/server/src/services/document-metadata.d.ts.map +1 -1
  105. package/dist/server/src/services/index.d.ts +3 -2
  106. package/dist/server/src/services/index.d.ts.map +1 -1
  107. package/dist/server/src/services/utils/configuration/index.d.ts +2 -2
  108. package/dist/server/src/services/utils/configuration/layouts.d.ts +2 -2
  109. package/dist/server/src/services/utils/populate.d.ts +2 -2
  110. package/dist/server/src/services/utils/populate.d.ts.map +1 -1
  111. package/package.json +6 -7
  112. package/dist/_chunks/EditViewPage-BCjNxNlY.mjs.map +0 -1
  113. package/dist/_chunks/EditViewPage-wujOq90c.js.map +0 -1
  114. package/dist/_chunks/Field-B5QXnctJ.js.map +0 -1
  115. package/dist/_chunks/Field-Byr3mPTl.mjs.map +0 -1
  116. package/dist/_chunks/History-CqNgxkqK.mjs.map +0 -1
  117. package/dist/_chunks/History-DYl2A8Z_.js.map +0 -1
  118. package/dist/_chunks/Preview-BaYGJ0nb.mjs.map +0 -1
  119. package/dist/_chunks/Preview-DfNx8Ke-.js.map +0 -1
  120. package/dist/_chunks/index-BUWEmX8m.js.map +0 -1
  121. package/dist/_chunks/index-DVAIIsOs.mjs.map +0 -1
  122. package/dist/_chunks/useDebounce-CtcjDB3L.js.map +0 -1
  123. package/dist/_chunks/useDebounce-DmuSJIF3.mjs.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
+ });
446
420
  }
447
- return currentDataWithRelations;
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
+ });
434
+ }
435
+ },
436
+ {
437
+ schema,
438
+ getModel: strapi2.getModel.bind(strapi2)
448
439
  },
449
- Promise.resolve(entry.data)
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
+ }
498
488
  }
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;
489
+ if (options.attribute.type === "dynamiczone") {
490
+ if (options.value === null) {
491
+ utils.set(options.key, []);
492
+ }
493
+ }
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({
@@ -3929,6 +3933,12 @@ function getPopulateForRelation(attribute, model, attributeName, { countMany, co
3929
3933
  if (initialPopulate) {
3930
3934
  return initialPopulate;
3931
3935
  }
3936
+ if (attributeName === "localizations") {
3937
+ const validationPopulate = getPopulateForValidation(model.uid);
3938
+ return {
3939
+ populate: validationPopulate.populate
3940
+ };
3941
+ }
3932
3942
  if (!isVisibleAttribute$1(model, attributeName)) {
3933
3943
  return true;
3934
3944
  }
@@ -3988,6 +3998,9 @@ const getDeepPopulate = (uid2, {
3988
3998
  return {};
3989
3999
  }
3990
4000
  const model = strapi.getModel(uid2);
4001
+ if (!model) {
4002
+ return {};
4003
+ }
3991
4004
  return Object.keys(model.attributes).reduce(
3992
4005
  (populateAcc, attributeName) => fp.merge(
3993
4006
  populateAcc,
@@ -4007,40 +4020,46 @@ const getDeepPopulate = (uid2, {
4007
4020
  {}
4008
4021
  );
4009
4022
  };
4010
- const getValidatableFieldsPopulate = (uid2, {
4011
- initialPopulate = {},
4012
- countMany = false,
4013
- countOne = false,
4014
- maxLevel = Infinity
4015
- } = {}, level = 1) => {
4016
- if (level > maxLevel) {
4023
+ const getPopulateForValidation = (uid2) => {
4024
+ const model = strapi.getModel(uid2);
4025
+ if (!model) {
4017
4026
  return {};
4018
4027
  }
4019
- const model = strapi.getModel(uid2);
4020
4028
  return Object.entries(model.attributes).reduce((populateAcc, [attributeName, attribute]) => {
4021
- if (!getDoesAttributeRequireValidation(attribute)) {
4029
+ if (isScalarAttribute(attribute)) {
4030
+ if (getDoesAttributeRequireValidation(attribute)) {
4031
+ populateAcc.fields = populateAcc.fields || [];
4032
+ populateAcc.fields.push(attributeName);
4033
+ }
4022
4034
  return populateAcc;
4023
4035
  }
4024
- if (isScalarAttribute(attribute)) {
4025
- return fp.merge(populateAcc, {
4026
- [attributeName]: true
4027
- });
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;
4028
4044
  }
4029
- return fp.merge(
4030
- populateAcc,
4031
- getPopulateFor(
4032
- attributeName,
4033
- model,
4034
- {
4035
- // @ts-expect-error - improve types
4036
- initialPopulate: initialPopulate?.[attributeName],
4037
- countMany,
4038
- countOne,
4039
- 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;
4040
4054
  },
4041
- level
4042
- )
4043
- );
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;
4044
4063
  }, {});
4045
4064
  };
4046
4065
  const getDeepPopulateDraftCount = (uid2) => {
@@ -4282,7 +4301,6 @@ const AVAILABLE_LOCALES_FIELDS = [
4282
4301
  "locale",
4283
4302
  "updatedAt",
4284
4303
  "createdAt",
4285
- "status",
4286
4304
  "publishedAt",
4287
4305
  "documentId"
4288
4306
  ];
@@ -4303,36 +4321,20 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4303
4321
  /**
4304
4322
  * Returns available locales of a document for the current status
4305
4323
  */
4306
- async getAvailableLocales(uid2, version, allVersions, validatableFields = []) {
4324
+ async getAvailableLocales(uid2, version, allVersions) {
4307
4325
  const versionsByLocale = fp.groupBy("locale", allVersions);
4308
4326
  if (version.locale) {
4309
4327
  delete versionsByLocale[version.locale];
4310
4328
  }
4311
4329
  const model = strapi2.getModel(uid2);
4312
- const keysToKeep = [...AVAILABLE_LOCALES_FIELDS, ...validatableFields];
4313
- const traversalFunction = async (localeVersion) => strapiUtils.traverseEntity(
4314
- ({ key }, { remove }) => {
4315
- if (keysToKeep.includes(key)) {
4316
- return;
4317
- }
4318
- remove(key);
4319
- },
4320
- { schema: model, getModel: strapi2.getModel.bind(strapi2) },
4321
- // @ts-expect-error fix types DocumentVersion incompatible with Data
4322
- localeVersion
4323
- );
4324
4330
  const mappingResult = await strapiUtils.async.map(
4325
4331
  Object.values(versionsByLocale),
4326
4332
  async (localeVersions) => {
4327
- const mappedLocaleVersions = await strapiUtils.async.map(
4328
- localeVersions,
4329
- traversalFunction
4330
- );
4331
4333
  if (!strapiUtils.contentTypes.hasDraftAndPublish(model)) {
4332
- return mappedLocaleVersions[0];
4334
+ return localeVersions[0];
4333
4335
  }
4334
- const draftVersion = mappedLocaleVersions.find((v) => v.publishedAt === null);
4335
- 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);
4336
4338
  if (!draftVersion) {
4337
4339
  return;
4338
4340
  }
@@ -4366,15 +4368,17 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4366
4368
  async getManyAvailableStatus(uid2, documents) {
4367
4369
  if (!documents.length) return [];
4368
4370
  const status = documents[0].publishedAt !== null ? "published" : "draft";
4369
- const locale = documents[0]?.locale;
4370
- const otherStatus = status === "published" ? "draft" : "published";
4371
- return strapi2.documents(uid2).findMany({
4372
- filters: {
4373
- documentId: { $in: documents.map((d) => d.documentId).filter(Boolean) }
4374
- },
4375
- status: otherStatus,
4376
- locale,
4377
- 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"]
4378
4382
  });
4379
4383
  },
4380
4384
  getStatus(version, otherDocumentStatuses) {
@@ -4400,11 +4404,9 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4400
4404
  // We could refactor this so the locales are only loaded when they're
4401
4405
  // needed. e.g. in the bulk locale action modal.
4402
4406
  async getMetadata(uid2, version, { availableLocales = true, availableStatus = true } = {}) {
4403
- const populate = getValidatableFieldsPopulate(uid2);
4404
- const versions = await strapi2.db.query(uid2).findMany({
4405
- where: { documentId: version.documentId },
4407
+ const { populate = {}, fields = [] } = getPopulateForValidation(uid2);
4408
+ const params = {
4406
4409
  populate: {
4407
- // Populate only fields that require validation for bulk locale actions
4408
4410
  ...populate,
4409
4411
  // NOTE: creator fields are selected in this way to avoid exposing sensitive data
4410
4412
  createdBy: {
@@ -4413,9 +4415,15 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4413
4415
  updatedBy: {
4414
4416
  select: ["id", "firstname", "lastname", "email"]
4415
4417
  }
4418
+ },
4419
+ fields: fp.uniq([...AVAILABLE_LOCALES_FIELDS, ...fields]),
4420
+ filters: {
4421
+ documentId: version.documentId
4416
4422
  }
4417
- });
4418
- 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) : [];
4419
4427
  const availableStatusResult = availableStatus ? this.getAvailableStatus(version, versions) : null;
4420
4428
  return {
4421
4429
  availableLocales: availableLocalesResult,
@@ -4442,6 +4450,16 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4442
4450
  opts.availableStatus = false;
4443
4451
  }
4444
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
+ }
4445
4463
  return {
4446
4464
  data: {
4447
4465
  ...document,