@strapi/content-manager 0.0.0-experimental.5b211b38912691ee2eab22d47b5095ea2fcfec76 → 0.0.0-experimental.5e04dee5c96cd68273df3b3cadf4635e19dc2afc

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 (103) hide show
  1. package/LICENSE +18 -3
  2. package/dist/_chunks/{ComponentConfigurationPage-DmwmiFQy.mjs → ComponentConfigurationPage-B3yDbeU1.mjs} +3 -3
  3. package/dist/_chunks/{ComponentConfigurationPage-DmwmiFQy.mjs.map → ComponentConfigurationPage-B3yDbeU1.mjs.map} +1 -1
  4. package/dist/_chunks/{ComponentConfigurationPage-C-49MccQ.js → ComponentConfigurationPage-KXSuLnQD.js} +3 -3
  5. package/dist/_chunks/{ComponentConfigurationPage-C-49MccQ.js.map → ComponentConfigurationPage-KXSuLnQD.js.map} +1 -1
  6. package/dist/_chunks/{EditConfigurationPage-DjFJw56M.js → EditConfigurationPage-BQ17--5R.js} +3 -3
  7. package/dist/_chunks/{EditConfigurationPage-DjFJw56M.js.map → EditConfigurationPage-BQ17--5R.js.map} +1 -1
  8. package/dist/_chunks/{EditConfigurationPage-JT3E7NZy.mjs → EditConfigurationPage-D7PrLO8j.mjs} +3 -3
  9. package/dist/_chunks/{EditConfigurationPage-JT3E7NZy.mjs.map → EditConfigurationPage-D7PrLO8j.mjs.map} +1 -1
  10. package/dist/_chunks/{EditViewPage-CPj61RMh.mjs → EditViewPage-B7VgwJaG.mjs} +18 -7
  11. package/dist/_chunks/EditViewPage-B7VgwJaG.mjs.map +1 -0
  12. package/dist/_chunks/{EditViewPage-zT3fBr4Y.js → EditViewPage-BgjdnGz2.js} +18 -7
  13. package/dist/_chunks/EditViewPage-BgjdnGz2.js.map +1 -0
  14. package/dist/_chunks/{Field-Boxf9Ajp.js → Field-CdK7ZLmv.js} +165 -81
  15. package/dist/_chunks/Field-CdK7ZLmv.js.map +1 -0
  16. package/dist/_chunks/{Field-dha5VnIQ.mjs → Field-tHCw4lGA.mjs} +166 -82
  17. package/dist/_chunks/Field-tHCw4lGA.mjs.map +1 -0
  18. package/dist/_chunks/{Form-DHrru2AV.mjs → Form-BJxdTv3Q.mjs} +22 -11
  19. package/dist/_chunks/Form-BJxdTv3Q.mjs.map +1 -0
  20. package/dist/_chunks/{Form-y5g1SRsh.js → Form-C_0KTVvV.js} +22 -11
  21. package/dist/_chunks/Form-C_0KTVvV.js.map +1 -0
  22. package/dist/_chunks/{History-Bru_KoeP.mjs → History-DR2txJLE.mjs} +44 -19
  23. package/dist/_chunks/History-DR2txJLE.mjs.map +1 -0
  24. package/dist/_chunks/{History-CqN6K7SX.js → History-nuEzM5qm.js} +44 -19
  25. package/dist/_chunks/History-nuEzM5qm.js.map +1 -0
  26. package/dist/_chunks/{ListConfigurationPage-R_p-SbHZ.js → ListConfigurationPage-CnB86Psm.js} +20 -8
  27. package/dist/_chunks/ListConfigurationPage-CnB86Psm.js.map +1 -0
  28. package/dist/_chunks/{ListConfigurationPage-D8wGABj0.mjs → ListConfigurationPage-voFVtXu6.mjs} +20 -8
  29. package/dist/_chunks/ListConfigurationPage-voFVtXu6.mjs.map +1 -0
  30. package/dist/_chunks/{ListViewPage-SID6TRb9.mjs → ListViewPage-B_GaWgRH.mjs} +22 -8
  31. package/dist/_chunks/ListViewPage-B_GaWgRH.mjs.map +1 -0
  32. package/dist/_chunks/{ListViewPage-pEw_zug9.js → ListViewPage-SXIXm-RM.js} +21 -7
  33. package/dist/_chunks/ListViewPage-SXIXm-RM.js.map +1 -0
  34. package/dist/_chunks/{NoContentTypePage-C5dcQojD.js → NoContentTypePage-BzsQ3hLZ.js} +2 -2
  35. package/dist/_chunks/{NoContentTypePage-C5dcQojD.js.map → NoContentTypePage-BzsQ3hLZ.js.map} +1 -1
  36. package/dist/_chunks/{NoContentTypePage-CJ7UXwrQ.mjs → NoContentTypePage-CYiGpsbj.mjs} +2 -2
  37. package/dist/_chunks/{NoContentTypePage-CJ7UXwrQ.mjs.map → NoContentTypePage-CYiGpsbj.mjs.map} +1 -1
  38. package/dist/_chunks/{NoPermissionsPage-B7syEq5E.mjs → NoPermissionsPage-B5baIHal.mjs} +2 -2
  39. package/dist/_chunks/{NoPermissionsPage-B7syEq5E.mjs.map → NoPermissionsPage-B5baIHal.mjs.map} +1 -1
  40. package/dist/_chunks/{NoPermissionsPage-BtPrImPP.js → NoPermissionsPage-IGkId4C5.js} +2 -2
  41. package/dist/_chunks/{NoPermissionsPage-BtPrImPP.js.map → NoPermissionsPage-IGkId4C5.js.map} +1 -1
  42. package/dist/_chunks/{Relations-B9Crnhnn.mjs → Relations-CIYDdKU-.mjs} +4 -4
  43. package/dist/_chunks/Relations-CIYDdKU-.mjs.map +1 -0
  44. package/dist/_chunks/{Relations-DjTQ5kGB.js → Relations-Dhuurpx2.js} +4 -4
  45. package/dist/_chunks/Relations-Dhuurpx2.js.map +1 -0
  46. package/dist/_chunks/{en-Ux26r5pl.mjs → en-BrCTWlZv.mjs} +5 -4
  47. package/dist/_chunks/{en-Ux26r5pl.mjs.map → en-BrCTWlZv.mjs.map} +1 -1
  48. package/dist/_chunks/{en-fbKQxLGn.js → en-uOUIxfcQ.js} +5 -4
  49. package/dist/_chunks/{en-fbKQxLGn.js.map → en-uOUIxfcQ.js.map} +1 -1
  50. package/dist/_chunks/{index-DJXJw9V5.mjs → index-C9TJPyni.mjs} +317 -138
  51. package/dist/_chunks/index-C9TJPyni.mjs.map +1 -0
  52. package/dist/_chunks/{index-DVPWZkbS.js → index-CdT0kHZ8.js} +314 -135
  53. package/dist/_chunks/index-CdT0kHZ8.js.map +1 -0
  54. package/dist/_chunks/{layout-Bau7ZfLV.mjs → layout-BNqvLR_b.mjs} +23 -11
  55. package/dist/_chunks/layout-BNqvLR_b.mjs.map +1 -0
  56. package/dist/_chunks/{layout-Dm6fbiQj.js → layout-C6dxWYT7.js} +22 -10
  57. package/dist/_chunks/layout-C6dxWYT7.js.map +1 -0
  58. package/dist/_chunks/{relations-BH_kBSJ0.mjs → relations-CkKqKw65.mjs} +2 -2
  59. package/dist/_chunks/{relations-BH_kBSJ0.mjs.map → relations-CkKqKw65.mjs.map} +1 -1
  60. package/dist/_chunks/{relations-CKnpRgrN.js → relations-DtFaDnP1.js} +2 -2
  61. package/dist/_chunks/{relations-CKnpRgrN.js.map → relations-DtFaDnP1.js.map} +1 -1
  62. package/dist/admin/index.js +1 -1
  63. package/dist/admin/index.mjs +1 -1
  64. package/dist/admin/src/history/index.d.ts +3 -0
  65. package/dist/admin/src/index.d.ts +1 -0
  66. package/dist/admin/src/pages/EditView/components/DocumentActions.d.ts +1 -0
  67. package/dist/admin/src/pages/EditView/components/FormInputs/Relations.d.ts +20 -0
  68. package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/EditorLayout.d.ts +2 -2
  69. package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygFooter.d.ts +2 -2
  70. package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygStyles.d.ts +10 -22
  71. package/dist/server/index.js +134 -85
  72. package/dist/server/index.js.map +1 -1
  73. package/dist/server/index.mjs +135 -86
  74. package/dist/server/index.mjs.map +1 -1
  75. package/dist/server/src/controllers/collection-types.d.ts.map +1 -1
  76. package/dist/server/src/controllers/uid.d.ts.map +1 -1
  77. package/dist/server/src/controllers/validation/dimensions.d.ts +4 -2
  78. package/dist/server/src/controllers/validation/dimensions.d.ts.map +1 -1
  79. package/dist/server/src/history/services/lifecycles.d.ts.map +1 -1
  80. package/dist/server/src/history/services/utils.d.ts +1 -1
  81. package/dist/server/src/history/services/utils.d.ts.map +1 -1
  82. package/dist/server/src/services/document-manager.d.ts.map +1 -1
  83. package/dist/server/src/services/document-metadata.d.ts.map +1 -1
  84. package/dist/server/src/services/utils/populate.d.ts.map +1 -1
  85. package/package.json +8 -8
  86. package/dist/_chunks/EditViewPage-CPj61RMh.mjs.map +0 -1
  87. package/dist/_chunks/EditViewPage-zT3fBr4Y.js.map +0 -1
  88. package/dist/_chunks/Field-Boxf9Ajp.js.map +0 -1
  89. package/dist/_chunks/Field-dha5VnIQ.mjs.map +0 -1
  90. package/dist/_chunks/Form-DHrru2AV.mjs.map +0 -1
  91. package/dist/_chunks/Form-y5g1SRsh.js.map +0 -1
  92. package/dist/_chunks/History-Bru_KoeP.mjs.map +0 -1
  93. package/dist/_chunks/History-CqN6K7SX.js.map +0 -1
  94. package/dist/_chunks/ListConfigurationPage-D8wGABj0.mjs.map +0 -1
  95. package/dist/_chunks/ListConfigurationPage-R_p-SbHZ.js.map +0 -1
  96. package/dist/_chunks/ListViewPage-SID6TRb9.mjs.map +0 -1
  97. package/dist/_chunks/ListViewPage-pEw_zug9.js.map +0 -1
  98. package/dist/_chunks/Relations-B9Crnhnn.mjs.map +0 -1
  99. package/dist/_chunks/Relations-DjTQ5kGB.js.map +0 -1
  100. package/dist/_chunks/index-DJXJw9V5.mjs.map +0 -1
  101. package/dist/_chunks/index-DVPWZkbS.js.map +0 -1
  102. package/dist/_chunks/layout-Bau7ZfLV.mjs.map +0 -1
  103. package/dist/_chunks/layout-Dm6fbiQj.js.map +0 -1
@@ -4,41 +4,32 @@ export declare const CustomIconButton: import("styled-components").IStyledCompon
4
4
  children?: import("react").ReactNode;
5
5
  } & import("@strapi/design-system/dist/types").AsProp<"button"> & Omit<Omit<import("react").DetailedHTMLProps<import("react").ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref">, "children" | keyof import("@strapi/design-system/dist/types").AsProp<C> | keyof import("@strapi/design-system").TransientBoxProps> & {
6
6
  ref?: ((instance: HTMLButtonElement | null) => void) | import("react").RefObject<HTMLButtonElement> | null | undefined;
7
- } & import("@strapi/design-system").TransientFlexProps & {
8
- disabled?: boolean | undefined;
9
- } & {
7
+ } & import("@strapi/design-system").TransientFlexProps & Pick<import("@strapi/design-system").ButtonProps, "size" | "variant"> & {
10
8
  children: import("react").ReactNode;
9
+ disabled?: boolean | undefined;
11
10
  label: string;
12
11
  onClick?: import("react").MouseEventHandler<HTMLButtonElement> | undefined;
13
- size?: "S" | "M" | "L" | undefined;
14
- variant?: "secondary" | "tertiary" | undefined;
15
12
  withTooltip?: boolean | undefined;
16
13
  }, never>> & Omit<IconButtonComponent, keyof import("react").Component<any, {}, any>>;
17
14
  export declare const CustomLinkIconButton: import("styled-components").IStyledComponent<"web", import("styled-components/dist/types").FastOmit<import("styled-components/dist/types").FastOmit<import("@strapi/design-system").TransientBoxProps & {
18
15
  children?: import("react").ReactNode;
19
16
  } & import("@strapi/design-system/dist/types").AsProp<"button"> & Omit<Omit<import("react").DetailedHTMLProps<import("react").ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref">, "children" | keyof import("@strapi/design-system/dist/types").AsProp<C> | keyof import("@strapi/design-system").TransientBoxProps> & {
20
17
  ref?: ((instance: HTMLButtonElement | null) => void) | import("react").RefObject<HTMLButtonElement> | null | undefined;
21
- } & import("@strapi/design-system").TransientFlexProps & {
22
- disabled?: boolean | undefined;
23
- } & {
18
+ } & import("@strapi/design-system").TransientFlexProps & Pick<import("@strapi/design-system").ButtonProps, "size" | "variant"> & {
24
19
  children: import("react").ReactNode;
20
+ disabled?: boolean | undefined;
25
21
  label: string;
26
22
  onClick?: import("react").MouseEventHandler<HTMLButtonElement> | undefined;
27
- size?: "S" | "M" | "L" | undefined;
28
- variant?: "secondary" | "tertiary" | undefined;
29
23
  withTooltip?: boolean | undefined;
30
24
  }, never>, never>> & Omit<import("styled-components").IStyledComponent<"web", import("styled-components/dist/types").FastOmit<import("@strapi/design-system").TransientBoxProps & {
31
25
  children?: import("react").ReactNode;
32
26
  } & import("@strapi/design-system/dist/types").AsProp<"button"> & Omit<Omit<import("react").DetailedHTMLProps<import("react").ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref">, "children" | keyof import("@strapi/design-system/dist/types").AsProp<C> | keyof import("@strapi/design-system").TransientBoxProps> & {
33
27
  ref?: ((instance: HTMLButtonElement | null) => void) | import("react").RefObject<HTMLButtonElement> | null | undefined;
34
- } & import("@strapi/design-system").TransientFlexProps & {
35
- disabled?: boolean | undefined;
36
- } & {
28
+ } & import("@strapi/design-system").TransientFlexProps & Pick<import("@strapi/design-system").ButtonProps, "size" | "variant"> & {
37
29
  children: import("react").ReactNode;
30
+ disabled?: boolean | undefined;
38
31
  label: string;
39
32
  onClick?: import("react").MouseEventHandler<HTMLButtonElement> | undefined;
40
- size?: "S" | "M" | "L" | undefined;
41
- variant?: "secondary" | "tertiary" | undefined;
42
33
  withTooltip?: boolean | undefined;
43
34
  }, never>> & Omit<IconButtonComponent, keyof import("react").Component<any, {}, any>>, keyof import("react").Component<any, {}, any>>;
44
35
  export declare const MainButtons: import("styled-components").IStyledComponent<"web", import("styled-components/dist/types").FastOmit<any, never>> | (import("styled-components").IStyledComponent<"web", import("styled-components/dist/types").FastOmit<any, never>> & Omit<any, keyof import("react").Component<any, {}, any>>);
@@ -46,17 +37,14 @@ export declare const MoreButton: import("styled-components").IStyledComponent<"w
46
37
  children?: import("react").ReactNode;
47
38
  } & import("@strapi/design-system/dist/types").AsProp<"button"> & Omit<Omit<import("react").DetailedHTMLProps<import("react").ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref">, "children" | keyof import("@strapi/design-system/dist/types").AsProp<C> | keyof import("@strapi/design-system").TransientBoxProps> & {
48
39
  ref?: ((instance: HTMLButtonElement | null) => void) | import("react").RefObject<HTMLButtonElement> | null | undefined;
49
- } & import("@strapi/design-system").TransientFlexProps & {
50
- disabled?: boolean | undefined;
51
- } & {
40
+ } & import("@strapi/design-system").TransientFlexProps & Pick<import("@strapi/design-system").ButtonProps, "size" | "variant"> & {
52
41
  children: import("react").ReactNode;
42
+ disabled?: boolean | undefined;
53
43
  label: string;
54
44
  onClick?: import("react").MouseEventHandler<HTMLButtonElement> | undefined;
55
- size?: "S" | "M" | "L" | undefined;
56
- variant?: "secondary" | "tertiary" | undefined;
57
45
  withTooltip?: boolean | undefined;
58
46
  }, never>> & Omit<IconButtonComponent, keyof import("react").Component<any, {}, any>>;
59
47
  export declare const IconButtonGroupMargin: import("styled-components").IStyledComponent<"web", import("styled-components/dist/types").FastOmit<any, never>> | (import("styled-components").IStyledComponent<"web", import("styled-components/dist/types").FastOmit<any, never>> & Omit<any, keyof import("react").Component<any, {}, any>>);
60
- export declare const ExpandButton: import("styled-components").IStyledComponent<"web", import("styled-components/dist/types").FastOmit<Omit<Omit<import("@strapi/design-system").BaseButtonProps<import("react").ElementType<any, keyof import("react").JSX.IntrinsicElements>>, "ref"> & import("react").RefAttributes<unknown>, "ref"> & {
48
+ export declare const ExpandButton: import("styled-components").IStyledComponent<"web", import("styled-components/dist/types").FastOmit<Omit<Omit<import("@strapi/design-system").ButtonProps<import("react").ElementType<any, keyof import("react").JSX.IntrinsicElements>>, "ref"> & import("react").RefAttributes<unknown>, "ref"> & {
61
49
  ref?: ((instance: unknown) => void) | import("react").RefObject<unknown> | null | undefined;
62
- }, never>> & Omit<(<C extends import("react").ElementType<any, keyof import("react").JSX.IntrinsicElements> = "button">(props: import("react").PropsWithoutRef<import("@strapi/design-system").BaseButtonProps<C>> & import("react").RefAttributes<unknown>) => import("react").ReactNode), keyof import("react").Component<any, {}, any>>;
50
+ }, never>> & Omit<(<C extends import("react").ElementType<any, keyof import("react").JSX.IntrinsicElements> = "button">(props: import("react").PropsWithoutRef<import("@strapi/design-system").ButtonProps<C>> & import("react").RefAttributes<unknown>) => import("react").ReactNode), keyof import("react").Component<any, {}, any>>;
@@ -226,20 +226,25 @@ 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": {
236
+ const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
237
+ if (isMorphRelation) {
238
+ break;
239
+ }
235
240
  const isVisible2 = strapiUtils.contentTypes.isVisibleAttribute(model, attributeName);
236
241
  if (isVisible2) {
237
- acc[attributeName] = { fields: ["documentId", "locale", "publishedAt"] };
242
+ acc[attributeName] = { [fieldSelector]: ["documentId", "locale", "publishedAt"] };
238
243
  }
239
244
  break;
240
245
  }
241
246
  case "media": {
242
- acc[attributeName] = { fields: ["id"] };
247
+ acc[attributeName] = { [fieldSelector]: ["id"] };
243
248
  break;
244
249
  }
245
250
  case "component": {
@@ -490,6 +495,42 @@ const createHistoryService = ({ strapi: strapi2 }) => {
490
495
  }
491
496
  };
492
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
+ };
493
534
  const createLifecyclesService = ({ strapi: strapi2 }) => {
494
535
  const state = {
495
536
  deleteExpiredJob: null,
@@ -502,63 +543,43 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
502
543
  return;
503
544
  }
504
545
  strapi2.documents.use(async (context, next) => {
505
- if (!strapi2.requestContext.get()?.request.url.startsWith("/content-manager")) {
506
- return next();
507
- }
508
- if (context.action !== "create" && context.action !== "update" && context.action !== "clone" && context.action !== "publish" && context.action !== "unpublish" && context.action !== "discardDraft") {
509
- return next();
510
- }
511
- if (context.action === "update" && strapi2.requestContext.get()?.request.url.endsWith("/actions/publish")) {
512
- return next();
513
- }
514
- const contentTypeUid = context.contentType.uid;
515
- if (!contentTypeUid.startsWith("api::")) {
516
- return next();
517
- }
518
546
  const result = await next();
519
- const documentContext = {
520
- documentId: context.action === "create" || context.action === "clone" ? result.documentId : context.params.documentId,
521
- locale: context.params?.locale
522
- };
547
+ if (!shouldCreateHistoryVersion(context)) {
548
+ return result;
549
+ }
550
+ const documentId = context.action === "create" || context.action === "clone" ? result.documentId : context.params.documentId;
523
551
  const defaultLocale = await serviceUtils.getDefaultLocale();
524
- const locale = documentContext.locale || defaultLocale;
525
- if (Array.isArray(locale)) {
526
- strapi2.log.warn(
527
- "[Content manager history middleware]: An array of locales was provided, but only a single locale is supported for the findOne operation."
528
- );
529
- return next();
552
+ const locales = fp.castArray(context.params?.locale || defaultLocale);
553
+ if (!locales.length) {
554
+ return result;
530
555
  }
531
- const document = await strapi2.documents(contentTypeUid).findOne({
532
- documentId: documentContext.documentId,
533
- locale,
534
- 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
+ )
535
569
  });
536
- const status = await serviceUtils.getVersionStatus(contentTypeUid, document);
537
- const attributesSchema = strapi2.getModel(contentTypeUid).attributes;
538
- const componentsSchemas = Object.keys(
539
- attributesSchema
540
- ).reduce((currentComponentSchemas, key) => {
541
- const fieldSchema = attributesSchema[key];
542
- if (fieldSchema.type === "component") {
543
- const componentSchema = strapi2.getModel(fieldSchema.component).attributes;
544
- return {
545
- ...currentComponentSchemas,
546
- [fieldSchema.component]: componentSchema
547
- };
548
- }
549
- return currentComponentSchemas;
550
- }, {});
551
570
  await strapi2.db.transaction(async ({ onCommit }) => {
552
- onCommit(() => {
553
- getService(strapi2, "history").createVersion({
554
- contentType: contentTypeUid,
555
- data: fp.omit(FIELDS_TO_IGNORE, document),
556
- schema: fp.omit(FIELDS_TO_IGNORE, attributesSchema),
557
- componentsSchemas,
558
- relatedDocumentId: documentContext.documentId,
559
- locale,
560
- status
561
- });
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
+ }
562
583
  });
563
584
  });
564
585
  return result;
@@ -1591,9 +1612,11 @@ const multipleLocaleSchema = strapiUtils.yup.lazy(
1591
1612
  (value) => Array.isArray(value) ? strapiUtils.yup.array().of(singleLocaleSchema.required()) : singleLocaleSchema
1592
1613
  );
1593
1614
  const statusSchema = strapiUtils.yup.mixed().oneOf(["draft", "published"], "Invalid status");
1594
- const getDocumentLocaleAndStatus = async (request, opts = { allowMultipleLocales: false }) => {
1615
+ const getDocumentLocaleAndStatus = async (request, model, opts = { allowMultipleLocales: false }) => {
1595
1616
  const { allowMultipleLocales } = opts;
1596
- const { locale, status, ...rest } = request || {};
1617
+ const { locale, status: providedStatus, ...rest } = request || {};
1618
+ const defaultStatus = strapiUtils.contentTypes.hasDraftAndPublish(strapi.getModel(model)) ? void 0 : "published";
1619
+ const status = providedStatus !== void 0 ? providedStatus : defaultStatus;
1597
1620
  const schema = strapiUtils.yup.object().shape({
1598
1621
  locale: allowMultipleLocales ? multipleLocaleSchema : singleLocaleSchema,
1599
1622
  status: statusSchema
@@ -1641,7 +1664,7 @@ const createDocument = async (ctx, opts) => {
1641
1664
  const setCreator = strapiUtils.setCreatorFields({ user });
1642
1665
  const sanitizeFn = strapiUtils.async.pipe(pickPermittedFields, setCreator);
1643
1666
  const sanitizedBody = await sanitizeFn(body);
1644
- const { locale, status = "draft" } = await getDocumentLocaleAndStatus(body);
1667
+ const { locale, status } = await getDocumentLocaleAndStatus(body, model);
1645
1668
  return documentManager2.create(model, {
1646
1669
  data: sanitizedBody,
1647
1670
  locale,
@@ -1660,7 +1683,7 @@ const updateDocument = async (ctx, opts) => {
1660
1683
  }
1661
1684
  const permissionQuery = await permissionChecker2.sanitizedQuery.update(ctx.query);
1662
1685
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
1663
- const { locale } = await getDocumentLocaleAndStatus(body);
1686
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
1664
1687
  const [documentVersion, documentExists] = await Promise.all([
1665
1688
  documentManager2.findOne(id, model, { populate, locale, status: "draft" }),
1666
1689
  documentManager2.exists(model, id)
@@ -1698,7 +1721,7 @@ const collectionTypes = {
1698
1721
  }
1699
1722
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
1700
1723
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(1).countRelations({ toOne: false, toMany: true }).build();
1701
- const { locale, status } = await getDocumentLocaleAndStatus(query);
1724
+ const { locale, status } = await getDocumentLocaleAndStatus(query, model);
1702
1725
  const { results: documents, pagination } = await documentManager2.findPage(
1703
1726
  { ...permissionQuery, populate, locale, status },
1704
1727
  model
@@ -1733,7 +1756,7 @@ const collectionTypes = {
1733
1756
  }
1734
1757
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
1735
1758
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1736
- const { locale, status = "draft" } = await getDocumentLocaleAndStatus(ctx.query);
1759
+ const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
1737
1760
  const version = await documentManager2.findOne(id, model, {
1738
1761
  populate,
1739
1762
  locale,
@@ -1800,7 +1823,7 @@ const collectionTypes = {
1800
1823
  }
1801
1824
  const permissionQuery = await permissionChecker2.sanitizedQuery.create(ctx.query);
1802
1825
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
1803
- const { locale } = await getDocumentLocaleAndStatus(body);
1826
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
1804
1827
  const document = await documentManager2.findOne(id, model, {
1805
1828
  populate,
1806
1829
  locale,
@@ -1845,7 +1868,7 @@ const collectionTypes = {
1845
1868
  }
1846
1869
  const permissionQuery = await permissionChecker2.sanitizedQuery.delete(ctx.query);
1847
1870
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
1848
- const { locale } = await getDocumentLocaleAndStatus(ctx.query);
1871
+ const { locale } = await getDocumentLocaleAndStatus(ctx.query, model);
1849
1872
  const documentLocales = await documentManager2.findLocales(id, model, { populate, locale });
1850
1873
  if (documentLocales.length === 0) {
1851
1874
  return ctx.notFound();
@@ -1874,11 +1897,28 @@ const collectionTypes = {
1874
1897
  const publishedDocument = await strapi.db.transaction(async () => {
1875
1898
  const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
1876
1899
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1877
- const document = id ? await updateDocument(ctx, { populate }) : await createDocument(ctx, { populate });
1900
+ let document;
1901
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
1902
+ const isCreate = fp.isNil(id);
1903
+ if (isCreate) {
1904
+ if (permissionChecker2.cannot.create()) {
1905
+ throw new strapiUtils.errors.ForbiddenError();
1906
+ }
1907
+ document = await createDocument(ctx, { populate });
1908
+ }
1909
+ const isUpdate = !isCreate;
1910
+ if (isUpdate) {
1911
+ document = await documentManager2.findOne(id, model, { populate, locale });
1912
+ if (!document) {
1913
+ throw new strapiUtils.errors.NotFoundError("Document not found");
1914
+ }
1915
+ if (permissionChecker2.can.update(document)) {
1916
+ await updateDocument(ctx);
1917
+ }
1918
+ }
1878
1919
  if (permissionChecker2.cannot.publish(document)) {
1879
1920
  throw new strapiUtils.errors.ForbiddenError();
1880
1921
  }
1881
- const { locale } = await getDocumentLocaleAndStatus(body);
1882
1922
  const publishResult = await documentManager2.publish(document.documentId, model, {
1883
1923
  locale
1884
1924
  // TODO: Allow setting creator fields on publish
@@ -1905,7 +1945,9 @@ const collectionTypes = {
1905
1945
  }
1906
1946
  const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
1907
1947
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1908
- const { locale } = await getDocumentLocaleAndStatus(body, { allowMultipleLocales: true });
1948
+ const { locale } = await getDocumentLocaleAndStatus(body, model, {
1949
+ allowMultipleLocales: true
1950
+ });
1909
1951
  const entityPromises = documentIds.map(
1910
1952
  (documentId) => documentManager2.findLocales(documentId, model, { populate, locale, isPublished: false })
1911
1953
  );
@@ -1932,7 +1974,7 @@ const collectionTypes = {
1932
1974
  if (permissionChecker2.cannot.unpublish()) {
1933
1975
  return ctx.forbidden();
1934
1976
  }
1935
- const { locale } = await getDocumentLocaleAndStatus(body);
1977
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
1936
1978
  const entityPromises = documentIds.map(
1937
1979
  (documentId) => documentManager2.findLocales(documentId, model, { locale, isPublished: true })
1938
1980
  );
@@ -1965,7 +2007,7 @@ const collectionTypes = {
1965
2007
  }
1966
2008
  const permissionQuery = await permissionChecker2.sanitizedQuery.unpublish(ctx.query);
1967
2009
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
1968
- const { locale } = await getDocumentLocaleAndStatus(body);
2010
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
1969
2011
  const document = await documentManager2.findOne(id, model, {
1970
2012
  populate,
1971
2013
  locale,
@@ -2002,7 +2044,7 @@ const collectionTypes = {
2002
2044
  }
2003
2045
  const permissionQuery = await permissionChecker2.sanitizedQuery.discard(ctx.query);
2004
2046
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2005
- const { locale } = await getDocumentLocaleAndStatus(body);
2047
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
2006
2048
  const document = await documentManager2.findOne(id, model, {
2007
2049
  populate,
2008
2050
  locale,
@@ -2033,7 +2075,7 @@ const collectionTypes = {
2033
2075
  }
2034
2076
  const permissionQuery = await permissionChecker2.sanitizedQuery.delete(query);
2035
2077
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2036
- const { locale } = await getDocumentLocaleAndStatus(body);
2078
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
2037
2079
  const documentLocales = await documentManager2.findLocales(documentIds, model, {
2038
2080
  populate,
2039
2081
  locale
@@ -2060,7 +2102,7 @@ const collectionTypes = {
2060
2102
  }
2061
2103
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
2062
2104
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2063
- const { locale, status = "draft" } = await getDocumentLocaleAndStatus(ctx.query);
2105
+ const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
2064
2106
  const entity = await documentManager2.findOne(id, model, { populate, locale, status });
2065
2107
  if (!entity) {
2066
2108
  return ctx.notFound();
@@ -2588,7 +2630,7 @@ const createOrUpdateDocument = async (ctx, opts) => {
2588
2630
  throw new strapiUtils.errors.ForbiddenError();
2589
2631
  }
2590
2632
  const sanitizedQuery = await permissionChecker2.sanitizedQuery.update(query);
2591
- const { locale } = await getDocumentLocaleAndStatus(body);
2633
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
2592
2634
  const [documentVersion, otherDocumentVersion] = await Promise.all([
2593
2635
  findDocument(sanitizedQuery, model, { locale, status: "draft" }),
2594
2636
  // Find the first document to check if it exists
@@ -2629,7 +2671,7 @@ const singleTypes = {
2629
2671
  return ctx.forbidden();
2630
2672
  }
2631
2673
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
2632
- const { locale, status } = await getDocumentLocaleAndStatus(query);
2674
+ const { locale, status } = await getDocumentLocaleAndStatus(query, model);
2633
2675
  const version = await findDocument(permissionQuery, model, { locale, status });
2634
2676
  if (!version) {
2635
2677
  if (permissionChecker2.cannot.create()) {
@@ -2674,7 +2716,7 @@ const singleTypes = {
2674
2716
  }
2675
2717
  const sanitizedQuery = await permissionChecker2.sanitizedQuery.delete(query);
2676
2718
  const populate = await buildPopulateFromQuery(sanitizedQuery, model);
2677
- const { locale } = await getDocumentLocaleAndStatus(query);
2719
+ const { locale } = await getDocumentLocaleAndStatus(query, model);
2678
2720
  const documentLocales = await documentManager2.findLocales(void 0, model, {
2679
2721
  populate,
2680
2722
  locale
@@ -2711,7 +2753,7 @@ const singleTypes = {
2711
2753
  if (permissionChecker2.cannot.publish(document)) {
2712
2754
  throw new strapiUtils.errors.ForbiddenError();
2713
2755
  }
2714
- const { locale } = await getDocumentLocaleAndStatus(document);
2756
+ const { locale } = await getDocumentLocaleAndStatus(document, model);
2715
2757
  const publishResult = await documentManager2.publish(document.documentId, model, { locale });
2716
2758
  return publishResult.at(0);
2717
2759
  });
@@ -2734,7 +2776,7 @@ const singleTypes = {
2734
2776
  return ctx.forbidden();
2735
2777
  }
2736
2778
  const sanitizedQuery = await permissionChecker2.sanitizedQuery.unpublish(query);
2737
- const { locale } = await getDocumentLocaleAndStatus(body);
2779
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
2738
2780
  const document = await findDocument(sanitizedQuery, model, { locale });
2739
2781
  if (!document) {
2740
2782
  return ctx.notFound();
@@ -2766,7 +2808,7 @@ const singleTypes = {
2766
2808
  return ctx.forbidden();
2767
2809
  }
2768
2810
  const sanitizedQuery = await permissionChecker2.sanitizedQuery.discard(query);
2769
- const { locale } = await getDocumentLocaleAndStatus(body);
2811
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
2770
2812
  const document = await findDocument(sanitizedQuery, model, { locale, status: "published" });
2771
2813
  if (!document) {
2772
2814
  return ctx.notFound();
@@ -2786,7 +2828,7 @@ const singleTypes = {
2786
2828
  const { query } = ctx.request;
2787
2829
  const documentManager2 = getService$1("document-manager");
2788
2830
  const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2789
- const { locale } = await getDocumentLocaleAndStatus(query);
2831
+ const { locale } = await getDocumentLocaleAndStatus(query, model);
2790
2832
  if (permissionChecker2.cannot.read()) {
2791
2833
  return ctx.forbidden();
2792
2834
  }
@@ -2807,7 +2849,7 @@ const uid$1 = {
2807
2849
  async generateUID(ctx) {
2808
2850
  const { contentTypeUID, field, data } = await validateGenerateUIDInput(ctx.request.body);
2809
2851
  const { query = {} } = ctx.request;
2810
- const { locale } = await getDocumentLocaleAndStatus(query);
2852
+ const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
2811
2853
  await validateUIDField(contentTypeUID, field);
2812
2854
  const uidService = getService$1("uid");
2813
2855
  ctx.body = {
@@ -2819,7 +2861,7 @@ const uid$1 = {
2819
2861
  ctx.request.body
2820
2862
  );
2821
2863
  const { query = {} } = ctx.request;
2822
- const { locale } = await getDocumentLocaleAndStatus(query);
2864
+ const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
2823
2865
  await validateUIDField(contentTypeUID, field);
2824
2866
  const uidService = getService$1("uid");
2825
2867
  const isAvailable = await uidService.checkUIDAvailability({
@@ -3744,6 +3786,10 @@ const getDeepPopulateDraftCount = (uid2) => {
3744
3786
  const attribute = model.attributes[attributeName];
3745
3787
  switch (attribute.type) {
3746
3788
  case "relation": {
3789
+ const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
3790
+ if (isMorphRelation) {
3791
+ break;
3792
+ }
3747
3793
  if (isVisibleAttribute$1(model, attributeName)) {
3748
3794
  populateAcc[attributeName] = {
3749
3795
  count: true,
@@ -4121,7 +4167,13 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4121
4167
  */
4122
4168
  async formatDocumentWithMetadata(uid2, document, opts = {}) {
4123
4169
  if (!document) {
4124
- return document;
4170
+ return {
4171
+ data: document,
4172
+ meta: {
4173
+ availableLocales: [],
4174
+ availableStatus: []
4175
+ }
4176
+ };
4125
4177
  }
4126
4178
  const hasDraftAndPublish = strapiUtils.contentTypes.hasDraftAndPublish(strapi2.getModel(uid2));
4127
4179
  if (!hasDraftAndPublish) {
@@ -4229,10 +4281,7 @@ const documentManager = ({ strapi: strapi2 }) => {
4229
4281
  async clone(id, body, uid2) {
4230
4282
  const populate = await buildDeepPopulate(uid2);
4231
4283
  const params = {
4232
- data: {
4233
- ...omitIdField(body),
4234
- [PUBLISHED_AT_ATTRIBUTE]: null
4235
- },
4284
+ data: omitIdField(body),
4236
4285
  populate
4237
4286
  };
4238
4287
  return strapi2.documents(uid2).clone({ ...params, documentId: id }).then((result) => result?.entries.at(0));