@strapi/content-manager 5.0.0-rc.5 → 5.0.0-rc.7

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 (69) hide show
  1. package/dist/_chunks/{ComponentConfigurationPage-DXYBg6Q4.js → ComponentConfigurationPage-BNxtMIfV.js} +3 -3
  2. package/dist/_chunks/{ComponentConfigurationPage-DXYBg6Q4.js.map → ComponentConfigurationPage-BNxtMIfV.js.map} +1 -1
  3. package/dist/_chunks/{ComponentConfigurationPage-Diwy7rap.mjs → ComponentConfigurationPage-BWOQWCv2.mjs} +3 -3
  4. package/dist/_chunks/{ComponentConfigurationPage-Diwy7rap.mjs.map → ComponentConfigurationPage-BWOQWCv2.mjs.map} +1 -1
  5. package/dist/_chunks/{EditConfigurationPage-DCyvZplh.js → EditConfigurationPage-D340bYlT.js} +3 -3
  6. package/dist/_chunks/{EditConfigurationPage-DCyvZplh.js.map → EditConfigurationPage-D340bYlT.js.map} +1 -1
  7. package/dist/_chunks/{EditConfigurationPage-C62aCKGN.mjs → EditConfigurationPage-GTp-Ucnw.mjs} +3 -3
  8. package/dist/_chunks/{EditConfigurationPage-C62aCKGN.mjs.map → EditConfigurationPage-GTp-Ucnw.mjs.map} +1 -1
  9. package/dist/_chunks/{EditViewPage-D7pEHIUi.mjs → EditViewPage-BVMS5hT-.mjs} +3 -3
  10. package/dist/_chunks/{EditViewPage-D7pEHIUi.mjs.map → EditViewPage-BVMS5hT-.mjs.map} +1 -1
  11. package/dist/_chunks/{EditViewPage-Q1iL6Yjq.js → EditViewPage-CXkmnAvI.js} +3 -3
  12. package/dist/_chunks/{EditViewPage-Q1iL6Yjq.js.map → EditViewPage-CXkmnAvI.js.map} +1 -1
  13. package/dist/_chunks/{Field-tNsYzab8.js → Field-Ibi32diw.js} +3 -3
  14. package/dist/_chunks/{Field-tNsYzab8.js.map → Field-Ibi32diw.js.map} +1 -1
  15. package/dist/_chunks/{Field-B5WAARex.mjs → Field-nNgv5bpd.mjs} +3 -3
  16. package/dist/_chunks/{Field-B5WAARex.mjs.map → Field-nNgv5bpd.mjs.map} +1 -1
  17. package/dist/_chunks/{Form-BLOtEgdG.js → Form-Dhnh34ym.js} +2 -2
  18. package/dist/_chunks/{Form-BLOtEgdG.js.map → Form-Dhnh34ym.js.map} +1 -1
  19. package/dist/_chunks/{Form-BdgxktG0.mjs → Form-DodJsI2A.mjs} +2 -2
  20. package/dist/_chunks/{Form-BdgxktG0.mjs.map → Form-DodJsI2A.mjs.map} +1 -1
  21. package/dist/_chunks/{History-CNQ3y0Td.js → History-C9auUkDi.js} +4 -4
  22. package/dist/_chunks/{History-CNQ3y0Td.js.map → History-C9auUkDi.js.map} +1 -1
  23. package/dist/_chunks/{History-DCbphAxD.mjs → History-CKCSQXz_.mjs} +4 -4
  24. package/dist/_chunks/{History-DCbphAxD.mjs.map → History-CKCSQXz_.mjs.map} +1 -1
  25. package/dist/_chunks/{ListConfigurationPage-CGiDaV99.js → ListConfigurationPage-Bg4rWUjX.js} +2 -2
  26. package/dist/_chunks/{ListConfigurationPage-CGiDaV99.js.map → ListConfigurationPage-Bg4rWUjX.js.map} +1 -1
  27. package/dist/_chunks/{ListConfigurationPage-DfvPhk6u.mjs → ListConfigurationPage-CKEC4ttG.mjs} +2 -2
  28. package/dist/_chunks/{ListConfigurationPage-DfvPhk6u.mjs.map → ListConfigurationPage-CKEC4ttG.mjs.map} +1 -1
  29. package/dist/_chunks/{ListViewPage-D4UEitVJ.mjs → ListViewPage-B7_WJUjG.mjs} +3 -3
  30. package/dist/_chunks/{ListViewPage-D4UEitVJ.mjs.map → ListViewPage-B7_WJUjG.mjs.map} +1 -1
  31. package/dist/_chunks/{ListViewPage-BoBeCtmC.js → ListViewPage-C2gIeYHG.js} +3 -3
  32. package/dist/_chunks/{ListViewPage-BoBeCtmC.js.map → ListViewPage-C2gIeYHG.js.map} +1 -1
  33. package/dist/_chunks/{NoContentTypePage-Dg8RTwSG.mjs → NoContentTypePage-Ckem6Ll6.mjs} +2 -2
  34. package/dist/_chunks/{NoContentTypePage-Dg8RTwSG.mjs.map → NoContentTypePage-Ckem6Ll6.mjs.map} +1 -1
  35. package/dist/_chunks/{NoContentTypePage-r8lNSL9g.js → NoContentTypePage-DqgdUfyn.js} +2 -2
  36. package/dist/_chunks/{NoContentTypePage-r8lNSL9g.js.map → NoContentTypePage-DqgdUfyn.js.map} +1 -1
  37. package/dist/_chunks/{NoPermissionsPage-Kpz9mv4K.mjs → NoPermissionsPage-BO-GEjA4.mjs} +2 -2
  38. package/dist/_chunks/{NoPermissionsPage-Kpz9mv4K.mjs.map → NoPermissionsPage-BO-GEjA4.mjs.map} +1 -1
  39. package/dist/_chunks/{NoPermissionsPage-C-4rQU7A.js → NoPermissionsPage-CF29Q-sW.js} +2 -2
  40. package/dist/_chunks/{NoPermissionsPage-C-4rQU7A.js.map → NoPermissionsPage-CF29Q-sW.js.map} +1 -1
  41. package/dist/_chunks/{Relations-DORNjmbK.js → Relations-C0uC9J4f.js} +3 -3
  42. package/dist/_chunks/{Relations-DORNjmbK.js.map → Relations-C0uC9J4f.js.map} +1 -1
  43. package/dist/_chunks/{Relations-Q66m8cnC.mjs → Relations-DItV5eow.mjs} +3 -3
  44. package/dist/_chunks/{Relations-Q66m8cnC.mjs.map → Relations-DItV5eow.mjs.map} +1 -1
  45. package/dist/_chunks/{index-B74KYy73.js → index-Dd0nXyJF.js} +11 -10
  46. package/dist/_chunks/index-Dd0nXyJF.js.map +1 -0
  47. package/dist/_chunks/{index-CW--YEA6.mjs → index-DrNe6ctw.mjs} +11 -10
  48. package/dist/_chunks/index-DrNe6ctw.mjs.map +1 -0
  49. package/dist/_chunks/{layout-CcKSoI_3.mjs → layout-B3ez7kvr.mjs} +3 -3
  50. package/dist/_chunks/{layout-CcKSoI_3.mjs.map → layout-B3ez7kvr.mjs.map} +1 -1
  51. package/dist/_chunks/{layout-CwR7rEv4.js → layout-CLLtt_5O.js} +3 -3
  52. package/dist/_chunks/{layout-CwR7rEv4.js.map → layout-CLLtt_5O.js.map} +1 -1
  53. package/dist/_chunks/{relations-Dsery6I2.mjs → relations-B0hlsUU_.mjs} +2 -2
  54. package/dist/_chunks/{relations-Dsery6I2.mjs.map → relations-B0hlsUU_.mjs.map} +1 -1
  55. package/dist/_chunks/{relations-S1dd0utS.js → relations-bRxcNv1q.js} +2 -2
  56. package/dist/_chunks/{relations-S1dd0utS.js.map → relations-bRxcNv1q.js.map} +1 -1
  57. package/dist/admin/index.js +1 -1
  58. package/dist/admin/index.mjs +1 -1
  59. package/dist/server/index.js +79 -56
  60. package/dist/server/index.js.map +1 -1
  61. package/dist/server/index.mjs +80 -57
  62. package/dist/server/index.mjs.map +1 -1
  63. package/dist/server/src/history/services/lifecycles.d.ts.map +1 -1
  64. package/dist/server/src/history/services/utils.d.ts +1 -1
  65. package/dist/server/src/history/services/utils.d.ts.map +1 -1
  66. package/dist/server/src/services/document-metadata.d.ts.map +1 -1
  67. package/package.json +6 -6
  68. package/dist/_chunks/index-B74KYy73.js.map +0 -1
  69. package/dist/_chunks/index-CW--YEA6.mjs.map +0 -1
@@ -226,9 +226,10 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
226
226
  const meta = await documentMetadataService.getMetadata(contentTypeUid, document);
227
227
  return documentMetadataService.getStatus(document, meta.availableStatus);
228
228
  };
229
- const getDeepPopulate2 = (uid2) => {
229
+ const getDeepPopulate2 = (uid2, useDatabaseSyntax = false) => {
230
230
  const model = strapi2.getModel(uid2);
231
231
  const attributes = Object.entries(model.attributes);
232
+ const fieldSelector = useDatabaseSyntax ? "select" : "fields";
232
233
  return attributes.reduce((acc, [attributeName, attribute]) => {
233
234
  switch (attribute.type) {
234
235
  case "relation": {
@@ -238,12 +239,12 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
238
239
  }
239
240
  const isVisible2 = strapiUtils.contentTypes.isVisibleAttribute(model, attributeName);
240
241
  if (isVisible2) {
241
- acc[attributeName] = { fields: ["documentId", "locale", "publishedAt"] };
242
+ acc[attributeName] = { [fieldSelector]: ["documentId", "locale", "publishedAt"] };
242
243
  }
243
244
  break;
244
245
  }
245
246
  case "media": {
246
- acc[attributeName] = { fields: ["id"] };
247
+ acc[attributeName] = { [fieldSelector]: ["id"] };
247
248
  break;
248
249
  }
249
250
  case "component": {
@@ -494,6 +495,42 @@ const createHistoryService = ({ strapi: strapi2 }) => {
494
495
  }
495
496
  };
496
497
  };
498
+ const shouldCreateHistoryVersion = (context) => {
499
+ if (!strapi.requestContext.get()?.request.url.startsWith("/content-manager")) {
500
+ return false;
501
+ }
502
+ if (context.action !== "create" && context.action !== "update" && context.action !== "clone" && context.action !== "publish" && context.action !== "unpublish" && context.action !== "discardDraft") {
503
+ return false;
504
+ }
505
+ if (context.action === "update" && strapi.requestContext.get()?.request.url.endsWith("/actions/publish")) {
506
+ return false;
507
+ }
508
+ if (!context.contentType.uid.startsWith("api::")) {
509
+ return false;
510
+ }
511
+ return true;
512
+ };
513
+ const getSchemas = (uid2) => {
514
+ const attributesSchema = strapi.getModel(uid2).attributes;
515
+ const componentsSchemas = Object.keys(attributesSchema).reduce(
516
+ (currentComponentSchemas, key) => {
517
+ const fieldSchema = attributesSchema[key];
518
+ if (fieldSchema.type === "component") {
519
+ const componentSchema = strapi.getModel(fieldSchema.component).attributes;
520
+ return {
521
+ ...currentComponentSchemas,
522
+ [fieldSchema.component]: componentSchema
523
+ };
524
+ }
525
+ return currentComponentSchemas;
526
+ },
527
+ {}
528
+ );
529
+ return {
530
+ schema: fp.omit(FIELDS_TO_IGNORE, attributesSchema),
531
+ componentsSchemas
532
+ };
533
+ };
497
534
  const createLifecyclesService = ({ strapi: strapi2 }) => {
498
535
  const state = {
499
536
  deleteExpiredJob: null,
@@ -506,63 +543,43 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
506
543
  return;
507
544
  }
508
545
  strapi2.documents.use(async (context, next) => {
509
- if (!strapi2.requestContext.get()?.request.url.startsWith("/content-manager")) {
510
- return next();
511
- }
512
- if (context.action !== "create" && context.action !== "update" && context.action !== "clone" && context.action !== "publish" && context.action !== "unpublish" && context.action !== "discardDraft") {
513
- return next();
514
- }
515
- if (context.action === "update" && strapi2.requestContext.get()?.request.url.endsWith("/actions/publish")) {
516
- return next();
517
- }
518
- const contentTypeUid = context.contentType.uid;
519
- if (!contentTypeUid.startsWith("api::")) {
520
- return next();
521
- }
522
546
  const result = await next();
523
- const documentContext = {
524
- documentId: context.action === "create" || context.action === "clone" ? result.documentId : context.params.documentId,
525
- locale: context.params?.locale
526
- };
547
+ if (!shouldCreateHistoryVersion(context)) {
548
+ return result;
549
+ }
550
+ const documentId = context.action === "create" || context.action === "clone" ? result.documentId : context.params.documentId;
527
551
  const defaultLocale = await serviceUtils.getDefaultLocale();
528
- const locale = documentContext.locale || defaultLocale;
529
- if (Array.isArray(locale)) {
530
- strapi2.log.warn(
531
- "[Content manager history middleware]: An array of locales was provided, but only a single locale is supported for the findOne operation."
532
- );
533
- return next();
552
+ const locales = fp.castArray(context.params?.locale || defaultLocale);
553
+ if (!locales.length) {
554
+ return result;
534
555
  }
535
- const document = await strapi2.documents(contentTypeUid).findOne({
536
- documentId: documentContext.documentId,
537
- locale,
538
- populate: serviceUtils.getDeepPopulate(contentTypeUid)
556
+ const uid2 = context.contentType.uid;
557
+ const schemas = getSchemas(uid2);
558
+ const localeEntries = await strapi2.db.query(uid2).findMany({
559
+ where: {
560
+ documentId,
561
+ locale: { $in: locales },
562
+ publishedAt: null
563
+ },
564
+ populate: serviceUtils.getDeepPopulate(
565
+ uid2,
566
+ true
567
+ /* use database syntax */
568
+ )
539
569
  });
540
- const status = await serviceUtils.getVersionStatus(contentTypeUid, document);
541
- const attributesSchema = strapi2.getModel(contentTypeUid).attributes;
542
- const componentsSchemas = Object.keys(
543
- attributesSchema
544
- ).reduce((currentComponentSchemas, key) => {
545
- const fieldSchema = attributesSchema[key];
546
- if (fieldSchema.type === "component") {
547
- const componentSchema = strapi2.getModel(fieldSchema.component).attributes;
548
- return {
549
- ...currentComponentSchemas,
550
- [fieldSchema.component]: componentSchema
551
- };
552
- }
553
- return currentComponentSchemas;
554
- }, {});
555
570
  await strapi2.db.transaction(async ({ onCommit }) => {
556
- onCommit(() => {
557
- getService(strapi2, "history").createVersion({
558
- contentType: contentTypeUid,
559
- data: fp.omit(FIELDS_TO_IGNORE, document),
560
- schema: fp.omit(FIELDS_TO_IGNORE, attributesSchema),
561
- componentsSchemas,
562
- relatedDocumentId: documentContext.documentId,
563
- locale,
564
- status
565
- });
571
+ onCommit(async () => {
572
+ for (const entry of localeEntries) {
573
+ const status = await serviceUtils.getVersionStatus(uid2, entry);
574
+ await getService(strapi2, "history").createVersion({
575
+ contentType: uid2,
576
+ data: fp.omit(FIELDS_TO_IGNORE, entry),
577
+ relatedDocumentId: documentId,
578
+ locale: entry.locale,
579
+ status,
580
+ ...schemas
581
+ });
582
+ }
566
583
  });
567
584
  });
568
585
  return result;
@@ -4150,7 +4167,13 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4150
4167
  */
4151
4168
  async formatDocumentWithMetadata(uid2, document, opts = {}) {
4152
4169
  if (!document) {
4153
- return document;
4170
+ return {
4171
+ data: document,
4172
+ meta: {
4173
+ availableLocales: [],
4174
+ availableStatus: []
4175
+ }
4176
+ };
4154
4177
  }
4155
4178
  const hasDraftAndPublish = strapiUtils.contentTypes.hasDraftAndPublish(strapi2.getModel(uid2));
4156
4179
  if (!hasDraftAndPublish) {