@strapi/core 5.10.3 → 5.11.0

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.
package/dist/index.mjs CHANGED
@@ -290,7 +290,7 @@ const getDirs = ({ appDir, distDir }, config)=>({
290
290
  });
291
291
 
292
292
  var name = "@strapi/core";
293
- var version = "5.10.3";
293
+ var version = "5.11.0";
294
294
  var description = "Core of Strapi";
295
295
  var homepage = "https://strapi.io";
296
296
  var bugs = {
@@ -346,14 +346,14 @@ var dependencies = {
346
346
  "@koa/cors": "5.0.0",
347
347
  "@koa/router": "12.0.2",
348
348
  "@paralleldrive/cuid2": "2.2.2",
349
- "@strapi/admin": "5.10.3",
350
- "@strapi/database": "5.10.3",
351
- "@strapi/generators": "5.10.3",
352
- "@strapi/logger": "5.10.3",
353
- "@strapi/permissions": "5.10.3",
354
- "@strapi/types": "5.10.3",
355
- "@strapi/typescript-utils": "5.10.3",
356
- "@strapi/utils": "5.10.3",
349
+ "@strapi/admin": "5.11.0",
350
+ "@strapi/database": "5.11.0",
351
+ "@strapi/generators": "5.11.0",
352
+ "@strapi/logger": "5.11.0",
353
+ "@strapi/permissions": "5.11.0",
354
+ "@strapi/types": "5.11.0",
355
+ "@strapi/typescript-utils": "5.11.0",
356
+ "@strapi/utils": "5.11.0",
357
357
  bcryptjs: "2.4.3",
358
358
  boxen: "5.1.2",
359
359
  chalk: "4.1.2",
@@ -372,7 +372,7 @@ var dependencies = {
372
372
  "http-errors": "2.0.0",
373
373
  inquirer: "8.2.5",
374
374
  "is-docker": "2.2.1",
375
- koa: "2.15.2",
375
+ koa: "2.15.4",
376
376
  "koa-body": "6.0.1",
377
377
  "koa-compose": "4.1.0",
378
378
  "koa-compress": "5.1.1",
@@ -416,9 +416,9 @@ var devDependencies = {
416
416
  "@types/node": "18.19.24",
417
417
  "@types/node-schedule": "2.1.7",
418
418
  "@types/statuses": "2.0.1",
419
- "eslint-config-custom": "5.10.3",
419
+ "eslint-config-custom": "5.11.0",
420
420
  supertest: "6.3.3",
421
- tsconfig: "5.10.3"
421
+ tsconfig: "5.11.0"
422
422
  };
423
423
  var engines = {
424
424
  node: ">=18.0.0 <=22.x.x",
@@ -6748,7 +6748,7 @@ const EVENTS = {
6748
6748
  * Loads lingering relations that need to be updated when overriding a published or draft entry.
6749
6749
  * This is necessary because the relations are uni-directional and the target entry is not aware of the source entry.
6750
6750
  * This is not the case for bi-directional relations, where the target entry is also linked to the source entry.
6751
- */ const load = async (uid, { oldVersions, newVersions })=>{
6751
+ */ const load$1 = async (uid, { oldVersions, newVersions })=>{
6752
6752
  const updates = [];
6753
6753
  // Iterate all components and content types to find relations that need to be updated
6754
6754
  await strapi.db.transaction(async ({ trx })=>{
@@ -6823,7 +6823,7 @@ const EVENTS = {
6823
6823
  * @param oldEntries The old entries that are being overridden
6824
6824
  * @param newEntries The new entries that are overriding the old ones
6825
6825
  * @param oldRelations The relations that were previously loaded with `load` @see load
6826
- */ const sync = async (oldEntries, newEntries, oldRelations)=>{
6826
+ */ const sync$1 = async (oldEntries, newEntries, oldRelations)=>{
6827
6827
  /**
6828
6828
  * Create a map of old entry ids to new entry ids
6829
6829
  *
@@ -6853,6 +6853,137 @@ const EVENTS = {
6853
6853
  });
6854
6854
  };
6855
6855
 
6856
+ /**
6857
+ * Loads all bidirectional relations that need to be synchronized when content entries change state
6858
+ * (e.g., during publish/unpublish operations).
6859
+ *
6860
+ * In Strapi, bidirectional relations allow maintaining order from both sides of the relation.
6861
+ * When an entry is published, the following occurs:
6862
+ *
6863
+ * 1. The old published entry is deleted
6864
+ * 2. A new entry is created with all its relations
6865
+ *
6866
+ * This process affects relation ordering in the following way:
6867
+ *
6868
+ * Initial state (Entry A related to X, Y, Z):
6869
+ * ```
6870
+ * Entry A (draft) Entry A (published)
6871
+ * │ │
6872
+ * ├──(1)→ X ├──(1)→ X
6873
+ * ├──(2)→ Y ├──(2)→ Y
6874
+ * └──(3)→ Z └──(3)→ Z
6875
+ *
6876
+ * X's perspective: Y's perspective: Z's perspective:
6877
+ * └──(2)→ Entry A └──(1)→ Entry A └──(3)→ Entry A
6878
+ * ```
6879
+ *
6880
+ * After publishing Entry A (without relation order sync):
6881
+ * ```
6882
+ * Entry A (draft) Entry A (new published)
6883
+ * │ │
6884
+ * ├──(1)→ X ├──(1)→ X
6885
+ * ├──(2)→ Y ├──(2)→ Y
6886
+ * └──(3)→ Z └──(3)→ Z
6887
+ *
6888
+ * X's perspective: Y's perspective: Z's perspective:
6889
+ * └──(3)→ Entry A └──(3)→ Entry A └──(3)→ Entry A
6890
+ * (all relations appear last in order)
6891
+ * ```
6892
+ *
6893
+ * This module preserves the original ordering from both perspectives by:
6894
+ * 1. Capturing the relation order before the entry state changes
6895
+ * 2. Restoring this order after the new relations are created
6896
+ *
6897
+ * @param uid - The unique identifier of the content type being processed
6898
+ * @param context - Object containing arrays of old and new entry versions
6899
+ * @returns Array of objects containing join table metadata and relations to be updated
6900
+ */ const load = async (uid, { oldVersions })=>{
6901
+ const relationsToUpdate = [];
6902
+ await strapi.db.transaction(async ({ trx })=>{
6903
+ const contentTypes = Object.values(strapi.contentTypes);
6904
+ const components = Object.values(strapi.components);
6905
+ for (const model of [
6906
+ ...contentTypes,
6907
+ ...components
6908
+ ]){
6909
+ const dbModel = strapi.db.metadata.get(model.uid);
6910
+ for (const attribute of Object.values(dbModel.attributes)){
6911
+ // Skip if not a bidirectional relation targeting our content type
6912
+ if (attribute.type !== 'relation' || attribute.target !== uid || !(attribute.inversedBy || attribute.mappedBy)) {
6913
+ continue;
6914
+ }
6915
+ const joinTable = attribute.joinTable;
6916
+ if (!joinTable) {
6917
+ continue;
6918
+ }
6919
+ const { name: targetColumnName } = joinTable.inverseJoinColumn;
6920
+ // Load all relations that need their order preserved
6921
+ const oldEntryIds = oldVersions.map((entry)=>entry.id);
6922
+ const existingRelations = await strapi.db.getConnection().select('*').from(joinTable.name).whereIn(targetColumnName, oldEntryIds).transacting(trx);
6923
+ if (existingRelations.length > 0) {
6924
+ relationsToUpdate.push({
6925
+ joinTable,
6926
+ relations: existingRelations
6927
+ });
6928
+ }
6929
+ }
6930
+ }
6931
+ });
6932
+ return relationsToUpdate;
6933
+ };
6934
+ /**
6935
+ * Synchronizes the order of bidirectional relations after content entries have changed state.
6936
+ *
6937
+ * When entries change state (e.g., draft → published), their IDs change and all relations are recreated.
6938
+ * While the order of relations from the entry's perspective is maintained (as they're created in order),
6939
+ * the inverse relations (from related entries' perspective) would all appear last in order since they're new.
6940
+ *
6941
+ * Example:
6942
+ * ```
6943
+ * Before publish:
6944
+ * Article(id:1) →(order:1)→ Category(id:5)
6945
+ * Category(id:5) →(order:3)→ Article(id:1)
6946
+ *
6947
+ * After publish (without sync):
6948
+ * Article(id:2) →(order:1)→ Category(id:5) [order preserved]
6949
+ * Category(id:5) →(order:99)→ Article(id:2) [order lost - appears last]
6950
+ *
6951
+ * After sync:
6952
+ * Article(id:2) →(order:1)→ Category(id:5) [order preserved]
6953
+ * Category(id:5) →(order:3)→ Article(id:2) [order restored]
6954
+ * ```
6955
+ *
6956
+ * @param oldEntries - Array of previous entry versions with their IDs and locales
6957
+ * @param newEntries - Array of new entry versions with their IDs and locales
6958
+ * @param existingRelations - Array of join table data containing the relations to be updated
6959
+ */ const sync = async (oldEntries, newEntries, existingRelations)=>{
6960
+ // Group new entries by locale for easier lookup
6961
+ const newEntriesByLocale = keyBy('locale', newEntries);
6962
+ // Create a mapping of old entry IDs to new entry IDs based on locale
6963
+ const entryIdMapping = oldEntries.reduce((acc, oldEntry)=>{
6964
+ const newEntry = newEntriesByLocale[oldEntry.locale];
6965
+ if (!newEntry) return acc;
6966
+ acc[oldEntry.id] = newEntry.id;
6967
+ return acc;
6968
+ }, {});
6969
+ await strapi.db.transaction(async ({ trx })=>{
6970
+ for (const { joinTable, relations } of existingRelations){
6971
+ const sourceColumn = joinTable.inverseJoinColumn.name;
6972
+ const targetColumn = joinTable.joinColumn.name;
6973
+ const orderColumn = joinTable.orderColumnName;
6974
+ // Update order values for each relation
6975
+ // TODO: Find a way to batch it more efficiently
6976
+ await async.map(relations, (relation)=>{
6977
+ const { [sourceColumn]: oldSourceId, [targetColumn]: targetId, [orderColumn]: originalOrder } = relation;
6978
+ // Update the order column for the new relation entry
6979
+ return trx.from(joinTable.name).where(sourceColumn, entryIdMapping[oldSourceId]).where(targetColumn, targetId).update({
6980
+ [orderColumn]: originalOrder
6981
+ });
6982
+ });
6983
+ }
6984
+ });
6985
+ };
6986
+
6856
6987
  const textNodeValidator = yup$1.object().shape({
6857
6988
  type: yup$1.string().equals([
6858
6989
  'text'
@@ -7881,7 +8012,11 @@ const createContentTypeRepository = (uid, validator = entityValidator)=>{
7881
8012
  })
7882
8013
  ]);
7883
8014
  // Load any unidirectional relation targetting the old published entries
7884
- const relationsToSync = await load(uid, {
8015
+ const relationsToSync = await load$1(uid, {
8016
+ newVersions: draftsToPublish,
8017
+ oldVersions: oldPublishedVersions
8018
+ });
8019
+ const bidirectionalRelationsToSync = await load(uid, {
7885
8020
  newVersions: draftsToPublish,
7886
8021
  oldVersions: oldPublishedVersions
7887
8022
  });
@@ -7890,10 +8025,14 @@ const createContentTypeRepository = (uid, validator = entityValidator)=>{
7890
8025
  // Transform draft entry data and create published versions
7891
8026
  const publishedEntries = await async.map(draftsToPublish, (draft)=>entries.publish(draft, queryParams));
7892
8027
  // Sync unidirectional relations with the new published entries
7893
- await sync([
8028
+ await sync$1([
7894
8029
  ...oldPublishedVersions,
7895
8030
  ...draftsToPublish
7896
8031
  ], publishedEntries, relationsToSync);
8032
+ await sync([
8033
+ ...oldPublishedVersions,
8034
+ ...draftsToPublish
8035
+ ], publishedEntries, bidirectionalRelationsToSync);
7897
8036
  publishedEntries.forEach(emitEvent('entry.publish'));
7898
8037
  return {
7899
8038
  documentId,
@@ -7951,7 +8090,11 @@ const createContentTypeRepository = (uid, validator = entityValidator)=>{
7951
8090
  })
7952
8091
  ]);
7953
8092
  // Load any unidirectional relation targeting the old drafts
7954
- const relationsToSync = await load(uid, {
8093
+ const relationsToSync = await load$1(uid, {
8094
+ newVersions: versionsToDraft,
8095
+ oldVersions: oldDrafts
8096
+ });
8097
+ const bidirectionalRelationsToSync = await load(uid, {
7955
8098
  newVersions: versionsToDraft,
7956
8099
  oldVersions: oldDrafts
7957
8100
  });
@@ -7960,10 +8103,14 @@ const createContentTypeRepository = (uid, validator = entityValidator)=>{
7960
8103
  // Transform published entry data and create draft versions
7961
8104
  const draftEntries = await async.map(versionsToDraft, (entry)=>entries.discardDraft(entry, queryParams));
7962
8105
  // Sync unidirectional relations with the new draft entries
7963
- await sync([
8106
+ await sync$1([
7964
8107
  ...oldDrafts,
7965
8108
  ...versionsToDraft
7966
8109
  ], draftEntries, relationsToSync);
8110
+ await sync([
8111
+ ...oldDrafts,
8112
+ ...versionsToDraft
8113
+ ], draftEntries, bidirectionalRelationsToSync);
7967
8114
  draftEntries.forEach(emitEvent('entry.draft-discard'));
7968
8115
  return {
7969
8116
  documentId,