@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
@@ -1,4 +1,4 @@
1
- import strapiUtils, { validateYupSchema, errors, async, contentTypes as contentTypes$1, yup as yup$1, validateYupSchemaSync, policy, traverse, setCreatorFields, isOperatorOfType, relations as relations$1, traverseEntity, pagination } from "@strapi/utils";
1
+ import strapiUtils, { validateYupSchema, errors, async, contentTypes as contentTypes$1, traverseEntity, yup as yup$1, validateYupSchemaSync, policy, traverse, setCreatorFields, isOperatorOfType, relations as relations$1, pagination } from "@strapi/utils";
2
2
  import { pick, omit, difference, castArray, mergeWith, intersection, pipe, propOr, isEqual, isEmpty, set, isNil as isNil$1, has, prop, assoc, mapValues, flow, uniq, uniqBy, concat, getOr, propEq, merge, groupBy } from "lodash/fp";
3
3
  import "@strapi/types";
4
4
  import * as yup from "yup";
@@ -150,19 +150,16 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
150
150
  });
151
151
  })
152
152
  );
153
- return existingAndMissingRelations.filter(
154
- (relation) => relation !== null
155
- );
153
+ return existingAndMissingRelations.filter((relation) => relation !== null);
156
154
  }
157
155
  return strapi2.documents(attribute.target).findOne({
158
156
  documentId: versionRelationData.documentId,
159
157
  locale: versionRelationData.locale || void 0
160
158
  });
161
159
  };
162
- const getMediaRestoreValue = async (versionRelationData, attribute) => {
163
- if (attribute.multiple) {
160
+ const getMediaRestoreValue = async (versionRelationData) => {
161
+ if (Array.isArray(versionRelationData)) {
164
162
  const existingAndMissingMedias = await Promise.all(
165
- // @ts-expect-error Fix the type definitions so this isn't any
166
163
  versionRelationData.map((media) => {
167
164
  return strapi2.db.query("plugin::upload.file").findOne({ where: { id: media.id } });
168
165
  })
@@ -331,8 +328,8 @@ const createHistoryService = ({ strapi: strapi2 }) => {
331
328
  });
332
329
  },
333
330
  async findVersionsPage(params) {
334
- const model = strapi2.getModel(params.query.contentType);
335
- const isLocalizedContentType = serviceUtils.isLocalizedContentType(model);
331
+ const schema = strapi2.getModel(params.query.contentType);
332
+ const isLocalizedContentType = serviceUtils.isLocalizedContentType(schema);
336
333
  const defaultLocale = await serviceUtils.getDefaultLocale();
337
334
  let locale = null;
338
335
  if (isLocalizedContentType) {
@@ -353,32 +350,20 @@ const createHistoryService = ({ strapi: strapi2 }) => {
353
350
  }),
354
351
  serviceUtils.getLocaleDictionary()
355
352
  ]);
356
- const populateEntryRelations = async (entry) => {
357
- const entryWithRelations = await Object.entries(entry.schema).reduce(
358
- async (currentDataWithRelations, [attributeKey, attributeSchema]) => {
359
- const attributeValue = entry.data[attributeKey];
360
- const attributeValues = Array.isArray(attributeValue) ? attributeValue : [attributeValue];
361
- if (attributeSchema.type === "media") {
362
- const permissionChecker2 = getService$2("permission-checker").create({
363
- userAbility: params.state.userAbility,
364
- model: "plugin::upload.file"
365
- });
366
- const response = await serviceUtils.buildMediaResponse(attributeValues);
367
- const sanitizedResults = await Promise.all(
368
- response.results.map((media) => permissionChecker2.sanitizeOutput(media))
369
- );
370
- return {
371
- ...await currentDataWithRelations,
372
- [attributeKey]: {
373
- results: sanitizedResults,
374
- meta: response.meta
375
- }
376
- };
353
+ const populateEntry = async (entry) => {
354
+ return traverseEntity(
355
+ async (options, utils) => {
356
+ if (!options.attribute) return;
357
+ if (!options.value) return;
358
+ const currentValue = Array.isArray(options.value) ? options.value : [options.value];
359
+ if (options.attribute.type === "component") {
360
+ utils.remove("id");
377
361
  }
378
- if (attributeSchema.type === "relation" && attributeSchema.relation !== "morphToOne" && attributeSchema.relation !== "morphToMany") {
379
- if (attributeSchema.target === "admin::user") {
362
+ if (options.attribute.type === "relation" && // TODO: handle polymorphic relations
363
+ options.attribute.relation !== "morphToOne" && options.attribute.relation !== "morphToMany") {
364
+ if (options.attribute.target === "admin::user") {
380
365
  const adminUsers = await Promise.all(
381
- attributeValues.map((userToPopulate) => {
366
+ currentValue.map((userToPopulate) => {
382
367
  if (userToPopulate == null) {
383
368
  return null;
384
369
  }
@@ -390,46 +375,51 @@ const createHistoryService = ({ strapi: strapi2 }) => {
390
375
  });
391
376
  })
392
377
  );
393
- return {
394
- ...await currentDataWithRelations,
395
- /**
396
- * Ideally we would return the same "{results: [], meta: {}}" shape, however,
397
- * when sanitizing the data as a whole in the controller before sending to the client,
398
- * the data for admin relation user is completely sanitized if we return an object here as opposed to an array.
399
- */
400
- [attributeKey]: adminUsers
401
- };
378
+ utils.set(options.key, adminUsers);
402
379
  }
403
380
  const permissionChecker2 = getService$2("permission-checker").create({
404
381
  userAbility: params.state.userAbility,
405
- model: attributeSchema.target
382
+ model: options.attribute.target
406
383
  });
407
384
  const response = await serviceUtils.buildRelationReponse(
408
- attributeValues,
409
- attributeSchema
385
+ currentValue,
386
+ options.attribute
410
387
  );
411
388
  const sanitizedResults = await Promise.all(
412
389
  response.results.map((media) => permissionChecker2.sanitizeOutput(media))
413
390
  );
414
- return {
415
- ...await currentDataWithRelations,
416
- [attributeKey]: {
417
- results: sanitizedResults,
418
- meta: response.meta
419
- }
420
- };
391
+ utils.set(options.key, {
392
+ results: sanitizedResults,
393
+ meta: response.meta
394
+ });
421
395
  }
422
- return currentDataWithRelations;
396
+ if (options.attribute.type === "media") {
397
+ const permissionChecker2 = getService$2("permission-checker").create({
398
+ userAbility: params.state.userAbility,
399
+ model: "plugin::upload.file"
400
+ });
401
+ const response = await serviceUtils.buildMediaResponse(currentValue);
402
+ const sanitizedResults = await Promise.all(
403
+ response.results.map((media) => permissionChecker2.sanitizeOutput(media))
404
+ );
405
+ utils.set(options.key, {
406
+ results: sanitizedResults,
407
+ meta: response.meta
408
+ });
409
+ }
410
+ },
411
+ {
412
+ schema,
413
+ getModel: strapi2.getModel.bind(strapi2)
423
414
  },
424
- Promise.resolve(entry.data)
415
+ entry.data
425
416
  );
426
- return entryWithRelations;
427
417
  };
428
418
  const formattedResults = await Promise.all(
429
419
  results.map(async (result) => {
430
420
  return {
431
421
  ...result,
432
- data: await populateEntryRelations(result),
422
+ data: await populateEntry(result),
433
423
  meta: {
434
424
  unknownAttributes: serviceUtils.getSchemaAttributesDiff(
435
425
  result.schema,
@@ -460,30 +450,44 @@ const createHistoryService = ({ strapi: strapi2 }) => {
460
450
  // Clone to avoid mutating the original version data
461
451
  structuredClone(version.data)
462
452
  );
463
- const sanitizedSchemaAttributes = omit(
464
- FIELDS_TO_IGNORE,
465
- contentTypeSchemaAttributes
466
- );
467
- const reducer = async.reduce(Object.entries(sanitizedSchemaAttributes));
468
- const dataWithoutMissingRelations = await reducer(
469
- async (previousRelationAttributes, [name, attribute]) => {
470
- const versionRelationData = version.data[name];
471
- if (!versionRelationData) {
472
- return previousRelationAttributes;
453
+ const schema = structuredClone(version.schema);
454
+ schema.attributes = omit(FIELDS_TO_IGNORE, contentTypeSchemaAttributes);
455
+ const dataWithoutMissingRelations = await traverseEntity(
456
+ async (options, utils) => {
457
+ if (!options.attribute) return;
458
+ if (options.attribute.type === "component") {
459
+ utils.remove("id");
460
+ if (options.attribute.repeatable && options.value === null) {
461
+ utils.set(options.key, []);
462
+ }
473
463
  }
474
- if (attribute.type === "relation" && // TODO: handle polymorphic relations
475
- attribute.relation !== "morphToOne" && attribute.relation !== "morphToMany") {
476
- const data2 = await serviceUtils.getRelationRestoreValue(versionRelationData, attribute);
477
- previousRelationAttributes[name] = data2;
464
+ if (options.attribute.type === "dynamiczone") {
465
+ if (options.value === null) {
466
+ utils.set(options.key, []);
467
+ }
468
+ }
469
+ if (options.attribute.type === "relation" && // TODO: handle polymorphic relations
470
+ options.attribute.relation !== "morphToOne" && options.attribute.relation !== "morphToMany") {
471
+ if (!options.value) return;
472
+ const data2 = await serviceUtils.getRelationRestoreValue(
473
+ options.value,
474
+ options.attribute
475
+ );
476
+ utils.set(options.key, data2);
478
477
  }
479
- if (attribute.type === "media") {
480
- const data2 = await serviceUtils.getMediaRestoreValue(versionRelationData, attribute);
481
- previousRelationAttributes[name] = data2;
478
+ if (options.attribute.type === "media") {
479
+ if (!options.value) return;
480
+ const data2 = await serviceUtils.getMediaRestoreValue(
481
+ options.value
482
+ );
483
+ utils.set(options.key, data2);
482
484
  }
483
- return previousRelationAttributes;
484
485
  },
485
- // Clone to avoid mutating the original version data
486
- structuredClone(dataWithoutAddedAttributes)
486
+ {
487
+ schema,
488
+ getModel: strapi2.getModel.bind(strapi2)
489
+ },
490
+ dataWithoutAddedAttributes
487
491
  );
488
492
  const data = omit(["id", ...Object.keys(schemaDiff.removed)], dataWithoutMissingRelations);
489
493
  const restoredDocument = await strapi2.documents(version.contentType).update({
@@ -3904,6 +3908,12 @@ function getPopulateForRelation(attribute, model, attributeName, { countMany, co
3904
3908
  if (initialPopulate) {
3905
3909
  return initialPopulate;
3906
3910
  }
3911
+ if (attributeName === "localizations") {
3912
+ const validationPopulate = getPopulateForValidation(model.uid);
3913
+ return {
3914
+ populate: validationPopulate.populate
3915
+ };
3916
+ }
3907
3917
  if (!isVisibleAttribute$1(model, attributeName)) {
3908
3918
  return true;
3909
3919
  }
@@ -3963,6 +3973,9 @@ const getDeepPopulate = (uid2, {
3963
3973
  return {};
3964
3974
  }
3965
3975
  const model = strapi.getModel(uid2);
3976
+ if (!model) {
3977
+ return {};
3978
+ }
3966
3979
  return Object.keys(model.attributes).reduce(
3967
3980
  (populateAcc, attributeName) => merge(
3968
3981
  populateAcc,
@@ -3982,40 +3995,46 @@ const getDeepPopulate = (uid2, {
3982
3995
  {}
3983
3996
  );
3984
3997
  };
3985
- const getValidatableFieldsPopulate = (uid2, {
3986
- initialPopulate = {},
3987
- countMany = false,
3988
- countOne = false,
3989
- maxLevel = Infinity
3990
- } = {}, level = 1) => {
3991
- if (level > maxLevel) {
3998
+ const getPopulateForValidation = (uid2) => {
3999
+ const model = strapi.getModel(uid2);
4000
+ if (!model) {
3992
4001
  return {};
3993
4002
  }
3994
- const model = strapi.getModel(uid2);
3995
4003
  return Object.entries(model.attributes).reduce((populateAcc, [attributeName, attribute]) => {
3996
- if (!getDoesAttributeRequireValidation(attribute)) {
4004
+ if (isScalarAttribute(attribute)) {
4005
+ if (getDoesAttributeRequireValidation(attribute)) {
4006
+ populateAcc.fields = populateAcc.fields || [];
4007
+ populateAcc.fields.push(attributeName);
4008
+ }
3997
4009
  return populateAcc;
3998
4010
  }
3999
- if (isScalarAttribute(attribute)) {
4000
- return merge(populateAcc, {
4001
- [attributeName]: true
4002
- });
4011
+ if (isComponent(attribute)) {
4012
+ const component = attribute.component;
4013
+ const componentResult = getPopulateForValidation(component);
4014
+ if (Object.keys(componentResult).length > 0) {
4015
+ populateAcc.populate = populateAcc.populate || {};
4016
+ populateAcc.populate[attributeName] = componentResult;
4017
+ }
4018
+ return populateAcc;
4003
4019
  }
4004
- return merge(
4005
- populateAcc,
4006
- getPopulateFor(
4007
- attributeName,
4008
- model,
4009
- {
4010
- // @ts-expect-error - improve types
4011
- initialPopulate: initialPopulate?.[attributeName],
4012
- countMany,
4013
- countOne,
4014
- maxLevel
4020
+ if (isDynamicZone(attribute)) {
4021
+ const components2 = attribute.components;
4022
+ const componentsResult = (components2 || []).reduce(
4023
+ (acc, componentUID) => {
4024
+ const componentResult = getPopulateForValidation(componentUID);
4025
+ if (Object.keys(componentResult).length > 0) {
4026
+ acc[componentUID] = componentResult;
4027
+ }
4028
+ return acc;
4015
4029
  },
4016
- level
4017
- )
4018
- );
4030
+ {}
4031
+ );
4032
+ if (Object.keys(componentsResult).length > 0) {
4033
+ populateAcc.populate = populateAcc.populate || {};
4034
+ populateAcc.populate[attributeName] = { on: componentsResult };
4035
+ }
4036
+ }
4037
+ return populateAcc;
4019
4038
  }, {});
4020
4039
  };
4021
4040
  const getDeepPopulateDraftCount = (uid2) => {
@@ -4257,7 +4276,6 @@ const AVAILABLE_LOCALES_FIELDS = [
4257
4276
  "locale",
4258
4277
  "updatedAt",
4259
4278
  "createdAt",
4260
- "status",
4261
4279
  "publishedAt",
4262
4280
  "documentId"
4263
4281
  ];
@@ -4278,36 +4296,20 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4278
4296
  /**
4279
4297
  * Returns available locales of a document for the current status
4280
4298
  */
4281
- async getAvailableLocales(uid2, version, allVersions, validatableFields = []) {
4299
+ async getAvailableLocales(uid2, version, allVersions) {
4282
4300
  const versionsByLocale = groupBy("locale", allVersions);
4283
4301
  if (version.locale) {
4284
4302
  delete versionsByLocale[version.locale];
4285
4303
  }
4286
4304
  const model = strapi2.getModel(uid2);
4287
- const keysToKeep = [...AVAILABLE_LOCALES_FIELDS, ...validatableFields];
4288
- const traversalFunction = async (localeVersion) => traverseEntity(
4289
- ({ key }, { remove }) => {
4290
- if (keysToKeep.includes(key)) {
4291
- return;
4292
- }
4293
- remove(key);
4294
- },
4295
- { schema: model, getModel: strapi2.getModel.bind(strapi2) },
4296
- // @ts-expect-error fix types DocumentVersion incompatible with Data
4297
- localeVersion
4298
- );
4299
4305
  const mappingResult = await async.map(
4300
4306
  Object.values(versionsByLocale),
4301
4307
  async (localeVersions) => {
4302
- const mappedLocaleVersions = await async.map(
4303
- localeVersions,
4304
- traversalFunction
4305
- );
4306
4308
  if (!contentTypes$1.hasDraftAndPublish(model)) {
4307
- return mappedLocaleVersions[0];
4309
+ return localeVersions[0];
4308
4310
  }
4309
- const draftVersion = mappedLocaleVersions.find((v) => v.publishedAt === null);
4310
- const otherVersions = mappedLocaleVersions.filter((v) => v.id !== draftVersion?.id);
4311
+ const draftVersion = localeVersions.find((v) => v.publishedAt === null);
4312
+ const otherVersions = localeVersions.filter((v) => v.id !== draftVersion?.id);
4311
4313
  if (!draftVersion) {
4312
4314
  return;
4313
4315
  }
@@ -4341,15 +4343,17 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4341
4343
  async getManyAvailableStatus(uid2, documents) {
4342
4344
  if (!documents.length) return [];
4343
4345
  const status = documents[0].publishedAt !== null ? "published" : "draft";
4344
- const locale = documents[0]?.locale;
4345
- const otherStatus = status === "published" ? "draft" : "published";
4346
- return strapi2.documents(uid2).findMany({
4347
- filters: {
4348
- documentId: { $in: documents.map((d) => d.documentId).filter(Boolean) }
4349
- },
4350
- status: otherStatus,
4351
- locale,
4352
- fields: ["documentId", "locale", "updatedAt", "createdAt", "publishedAt"]
4346
+ const locales = documents.map((d) => d.locale).filter(Boolean);
4347
+ const where = {
4348
+ documentId: { $in: documents.map((d) => d.documentId).filter(Boolean) },
4349
+ publishedAt: { $null: status === "published" }
4350
+ };
4351
+ if (locales.length) {
4352
+ where.locale = { $in: locales };
4353
+ }
4354
+ return strapi2.query(uid2).findMany({
4355
+ where,
4356
+ select: ["id", "documentId", "locale", "updatedAt", "createdAt", "publishedAt"]
4353
4357
  });
4354
4358
  },
4355
4359
  getStatus(version, otherDocumentStatuses) {
@@ -4375,11 +4379,9 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4375
4379
  // We could refactor this so the locales are only loaded when they're
4376
4380
  // needed. e.g. in the bulk locale action modal.
4377
4381
  async getMetadata(uid2, version, { availableLocales = true, availableStatus = true } = {}) {
4378
- const populate = getValidatableFieldsPopulate(uid2);
4379
- const versions = await strapi2.db.query(uid2).findMany({
4380
- where: { documentId: version.documentId },
4382
+ const { populate = {}, fields = [] } = getPopulateForValidation(uid2);
4383
+ const params = {
4381
4384
  populate: {
4382
- // Populate only fields that require validation for bulk locale actions
4383
4385
  ...populate,
4384
4386
  // NOTE: creator fields are selected in this way to avoid exposing sensitive data
4385
4387
  createdBy: {
@@ -4388,9 +4390,15 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4388
4390
  updatedBy: {
4389
4391
  select: ["id", "firstname", "lastname", "email"]
4390
4392
  }
4393
+ },
4394
+ fields: uniq([...AVAILABLE_LOCALES_FIELDS, ...fields]),
4395
+ filters: {
4396
+ documentId: version.documentId
4391
4397
  }
4392
- });
4393
- const availableLocalesResult = availableLocales ? await this.getAvailableLocales(uid2, version, versions, Object.keys(populate)) : [];
4398
+ };
4399
+ const dbParams = strapi2.get("query-params").transform(uid2, params);
4400
+ const versions = await strapi2.db.query(uid2).findMany(dbParams);
4401
+ const availableLocalesResult = availableLocales ? await this.getAvailableLocales(uid2, version, versions) : [];
4394
4402
  const availableStatusResult = availableStatus ? this.getAvailableStatus(version, versions) : null;
4395
4403
  return {
4396
4404
  availableLocales: availableLocalesResult,
@@ -4417,6 +4425,16 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4417
4425
  opts.availableStatus = false;
4418
4426
  }
4419
4427
  const meta = await this.getMetadata(uid2, document, opts);
4428
+ if (document.localizations) {
4429
+ const otherStatus = await this.getManyAvailableStatus(uid2, document.localizations);
4430
+ document.localizations = document.localizations.map((d) => {
4431
+ const status = otherStatus.find((s) => s.documentId === d.documentId);
4432
+ return {
4433
+ ...d,
4434
+ status: this.getStatus(d, status ? [status] : [])
4435
+ };
4436
+ });
4437
+ }
4420
4438
  return {
4421
4439
  data: {
4422
4440
  ...document,