@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.js CHANGED
@@ -312,7 +312,7 @@ const getDirs = ({ appDir, distDir }, config)=>({
312
312
  });
313
313
 
314
314
  var name = "@strapi/core";
315
- var version = "5.10.3";
315
+ var version = "5.11.0";
316
316
  var description = "Core of Strapi";
317
317
  var homepage = "https://strapi.io";
318
318
  var bugs = {
@@ -368,14 +368,14 @@ var dependencies = {
368
368
  "@koa/cors": "5.0.0",
369
369
  "@koa/router": "12.0.2",
370
370
  "@paralleldrive/cuid2": "2.2.2",
371
- "@strapi/admin": "5.10.3",
372
- "@strapi/database": "5.10.3",
373
- "@strapi/generators": "5.10.3",
374
- "@strapi/logger": "5.10.3",
375
- "@strapi/permissions": "5.10.3",
376
- "@strapi/types": "5.10.3",
377
- "@strapi/typescript-utils": "5.10.3",
378
- "@strapi/utils": "5.10.3",
371
+ "@strapi/admin": "5.11.0",
372
+ "@strapi/database": "5.11.0",
373
+ "@strapi/generators": "5.11.0",
374
+ "@strapi/logger": "5.11.0",
375
+ "@strapi/permissions": "5.11.0",
376
+ "@strapi/types": "5.11.0",
377
+ "@strapi/typescript-utils": "5.11.0",
378
+ "@strapi/utils": "5.11.0",
379
379
  bcryptjs: "2.4.3",
380
380
  boxen: "5.1.2",
381
381
  chalk: "4.1.2",
@@ -394,7 +394,7 @@ var dependencies = {
394
394
  "http-errors": "2.0.0",
395
395
  inquirer: "8.2.5",
396
396
  "is-docker": "2.2.1",
397
- koa: "2.15.2",
397
+ koa: "2.15.4",
398
398
  "koa-body": "6.0.1",
399
399
  "koa-compose": "4.1.0",
400
400
  "koa-compress": "5.1.1",
@@ -438,9 +438,9 @@ var devDependencies = {
438
438
  "@types/node": "18.19.24",
439
439
  "@types/node-schedule": "2.1.7",
440
440
  "@types/statuses": "2.0.1",
441
- "eslint-config-custom": "5.10.3",
441
+ "eslint-config-custom": "5.11.0",
442
442
  supertest: "6.3.3",
443
- tsconfig: "5.10.3"
443
+ tsconfig: "5.11.0"
444
444
  };
445
445
  var engines = {
446
446
  node: ">=18.0.0 <=22.x.x",
@@ -6770,7 +6770,7 @@ const EVENTS = {
6770
6770
  * Loads lingering relations that need to be updated when overriding a published or draft entry.
6771
6771
  * This is necessary because the relations are uni-directional and the target entry is not aware of the source entry.
6772
6772
  * This is not the case for bi-directional relations, where the target entry is also linked to the source entry.
6773
- */ const load = async (uid, { oldVersions, newVersions })=>{
6773
+ */ const load$1 = async (uid, { oldVersions, newVersions })=>{
6774
6774
  const updates = [];
6775
6775
  // Iterate all components and content types to find relations that need to be updated
6776
6776
  await strapi.db.transaction(async ({ trx })=>{
@@ -6845,7 +6845,7 @@ const EVENTS = {
6845
6845
  * @param oldEntries The old entries that are being overridden
6846
6846
  * @param newEntries The new entries that are overriding the old ones
6847
6847
  * @param oldRelations The relations that were previously loaded with `load` @see load
6848
- */ const sync = async (oldEntries, newEntries, oldRelations)=>{
6848
+ */ const sync$1 = async (oldEntries, newEntries, oldRelations)=>{
6849
6849
  /**
6850
6850
  * Create a map of old entry ids to new entry ids
6851
6851
  *
@@ -6875,6 +6875,137 @@ const EVENTS = {
6875
6875
  });
6876
6876
  };
6877
6877
 
6878
+ /**
6879
+ * Loads all bidirectional relations that need to be synchronized when content entries change state
6880
+ * (e.g., during publish/unpublish operations).
6881
+ *
6882
+ * In Strapi, bidirectional relations allow maintaining order from both sides of the relation.
6883
+ * When an entry is published, the following occurs:
6884
+ *
6885
+ * 1. The old published entry is deleted
6886
+ * 2. A new entry is created with all its relations
6887
+ *
6888
+ * This process affects relation ordering in the following way:
6889
+ *
6890
+ * Initial state (Entry A related to X, Y, Z):
6891
+ * ```
6892
+ * Entry A (draft) Entry A (published)
6893
+ * │ │
6894
+ * ├──(1)→ X ├──(1)→ X
6895
+ * ├──(2)→ Y ├──(2)→ Y
6896
+ * └──(3)→ Z └──(3)→ Z
6897
+ *
6898
+ * X's perspective: Y's perspective: Z's perspective:
6899
+ * └──(2)→ Entry A └──(1)→ Entry A └──(3)→ Entry A
6900
+ * ```
6901
+ *
6902
+ * After publishing Entry A (without relation order sync):
6903
+ * ```
6904
+ * Entry A (draft) Entry A (new published)
6905
+ * │ │
6906
+ * ├──(1)→ X ├──(1)→ X
6907
+ * ├──(2)→ Y ├──(2)→ Y
6908
+ * └──(3)→ Z └──(3)→ Z
6909
+ *
6910
+ * X's perspective: Y's perspective: Z's perspective:
6911
+ * └──(3)→ Entry A └──(3)→ Entry A └──(3)→ Entry A
6912
+ * (all relations appear last in order)
6913
+ * ```
6914
+ *
6915
+ * This module preserves the original ordering from both perspectives by:
6916
+ * 1. Capturing the relation order before the entry state changes
6917
+ * 2. Restoring this order after the new relations are created
6918
+ *
6919
+ * @param uid - The unique identifier of the content type being processed
6920
+ * @param context - Object containing arrays of old and new entry versions
6921
+ * @returns Array of objects containing join table metadata and relations to be updated
6922
+ */ const load = async (uid, { oldVersions })=>{
6923
+ const relationsToUpdate = [];
6924
+ await strapi.db.transaction(async ({ trx })=>{
6925
+ const contentTypes = Object.values(strapi.contentTypes);
6926
+ const components = Object.values(strapi.components);
6927
+ for (const model of [
6928
+ ...contentTypes,
6929
+ ...components
6930
+ ]){
6931
+ const dbModel = strapi.db.metadata.get(model.uid);
6932
+ for (const attribute of Object.values(dbModel.attributes)){
6933
+ // Skip if not a bidirectional relation targeting our content type
6934
+ if (attribute.type !== 'relation' || attribute.target !== uid || !(attribute.inversedBy || attribute.mappedBy)) {
6935
+ continue;
6936
+ }
6937
+ const joinTable = attribute.joinTable;
6938
+ if (!joinTable) {
6939
+ continue;
6940
+ }
6941
+ const { name: targetColumnName } = joinTable.inverseJoinColumn;
6942
+ // Load all relations that need their order preserved
6943
+ const oldEntryIds = oldVersions.map((entry)=>entry.id);
6944
+ const existingRelations = await strapi.db.getConnection().select('*').from(joinTable.name).whereIn(targetColumnName, oldEntryIds).transacting(trx);
6945
+ if (existingRelations.length > 0) {
6946
+ relationsToUpdate.push({
6947
+ joinTable,
6948
+ relations: existingRelations
6949
+ });
6950
+ }
6951
+ }
6952
+ }
6953
+ });
6954
+ return relationsToUpdate;
6955
+ };
6956
+ /**
6957
+ * Synchronizes the order of bidirectional relations after content entries have changed state.
6958
+ *
6959
+ * When entries change state (e.g., draft → published), their IDs change and all relations are recreated.
6960
+ * While the order of relations from the entry's perspective is maintained (as they're created in order),
6961
+ * the inverse relations (from related entries' perspective) would all appear last in order since they're new.
6962
+ *
6963
+ * Example:
6964
+ * ```
6965
+ * Before publish:
6966
+ * Article(id:1) →(order:1)→ Category(id:5)
6967
+ * Category(id:5) →(order:3)→ Article(id:1)
6968
+ *
6969
+ * After publish (without sync):
6970
+ * Article(id:2) →(order:1)→ Category(id:5) [order preserved]
6971
+ * Category(id:5) →(order:99)→ Article(id:2) [order lost - appears last]
6972
+ *
6973
+ * After sync:
6974
+ * Article(id:2) →(order:1)→ Category(id:5) [order preserved]
6975
+ * Category(id:5) →(order:3)→ Article(id:2) [order restored]
6976
+ * ```
6977
+ *
6978
+ * @param oldEntries - Array of previous entry versions with their IDs and locales
6979
+ * @param newEntries - Array of new entry versions with their IDs and locales
6980
+ * @param existingRelations - Array of join table data containing the relations to be updated
6981
+ */ const sync = async (oldEntries, newEntries, existingRelations)=>{
6982
+ // Group new entries by locale for easier lookup
6983
+ const newEntriesByLocale = fp.keyBy('locale', newEntries);
6984
+ // Create a mapping of old entry IDs to new entry IDs based on locale
6985
+ const entryIdMapping = oldEntries.reduce((acc, oldEntry)=>{
6986
+ const newEntry = newEntriesByLocale[oldEntry.locale];
6987
+ if (!newEntry) return acc;
6988
+ acc[oldEntry.id] = newEntry.id;
6989
+ return acc;
6990
+ }, {});
6991
+ await strapi.db.transaction(async ({ trx })=>{
6992
+ for (const { joinTable, relations } of existingRelations){
6993
+ const sourceColumn = joinTable.inverseJoinColumn.name;
6994
+ const targetColumn = joinTable.joinColumn.name;
6995
+ const orderColumn = joinTable.orderColumnName;
6996
+ // Update order values for each relation
6997
+ // TODO: Find a way to batch it more efficiently
6998
+ await strapiUtils.async.map(relations, (relation)=>{
6999
+ const { [sourceColumn]: oldSourceId, [targetColumn]: targetId, [orderColumn]: originalOrder } = relation;
7000
+ // Update the order column for the new relation entry
7001
+ return trx.from(joinTable.name).where(sourceColumn, entryIdMapping[oldSourceId]).where(targetColumn, targetId).update({
7002
+ [orderColumn]: originalOrder
7003
+ });
7004
+ });
7005
+ }
7006
+ });
7007
+ };
7008
+
6878
7009
  const textNodeValidator = strapiUtils.yup.object().shape({
6879
7010
  type: strapiUtils.yup.string().equals([
6880
7011
  'text'
@@ -7903,7 +8034,11 @@ const createContentTypeRepository = (uid, validator = entityValidator)=>{
7903
8034
  })
7904
8035
  ]);
7905
8036
  // Load any unidirectional relation targetting the old published entries
7906
- const relationsToSync = await load(uid, {
8037
+ const relationsToSync = await load$1(uid, {
8038
+ newVersions: draftsToPublish,
8039
+ oldVersions: oldPublishedVersions
8040
+ });
8041
+ const bidirectionalRelationsToSync = await load(uid, {
7907
8042
  newVersions: draftsToPublish,
7908
8043
  oldVersions: oldPublishedVersions
7909
8044
  });
@@ -7912,10 +8047,14 @@ const createContentTypeRepository = (uid, validator = entityValidator)=>{
7912
8047
  // Transform draft entry data and create published versions
7913
8048
  const publishedEntries = await strapiUtils.async.map(draftsToPublish, (draft)=>entries.publish(draft, queryParams));
7914
8049
  // Sync unidirectional relations with the new published entries
7915
- await sync([
8050
+ await sync$1([
7916
8051
  ...oldPublishedVersions,
7917
8052
  ...draftsToPublish
7918
8053
  ], publishedEntries, relationsToSync);
8054
+ await sync([
8055
+ ...oldPublishedVersions,
8056
+ ...draftsToPublish
8057
+ ], publishedEntries, bidirectionalRelationsToSync);
7919
8058
  publishedEntries.forEach(emitEvent('entry.publish'));
7920
8059
  return {
7921
8060
  documentId,
@@ -7973,7 +8112,11 @@ const createContentTypeRepository = (uid, validator = entityValidator)=>{
7973
8112
  })
7974
8113
  ]);
7975
8114
  // Load any unidirectional relation targeting the old drafts
7976
- const relationsToSync = await load(uid, {
8115
+ const relationsToSync = await load$1(uid, {
8116
+ newVersions: versionsToDraft,
8117
+ oldVersions: oldDrafts
8118
+ });
8119
+ const bidirectionalRelationsToSync = await load(uid, {
7977
8120
  newVersions: versionsToDraft,
7978
8121
  oldVersions: oldDrafts
7979
8122
  });
@@ -7982,10 +8125,14 @@ const createContentTypeRepository = (uid, validator = entityValidator)=>{
7982
8125
  // Transform published entry data and create draft versions
7983
8126
  const draftEntries = await strapiUtils.async.map(versionsToDraft, (entry)=>entries.discardDraft(entry, queryParams));
7984
8127
  // Sync unidirectional relations with the new draft entries
7985
- await sync([
8128
+ await sync$1([
7986
8129
  ...oldDrafts,
7987
8130
  ...versionsToDraft
7988
8131
  ], draftEntries, relationsToSync);
8132
+ await sync([
8133
+ ...oldDrafts,
8134
+ ...versionsToDraft
8135
+ ], draftEntries, bidirectionalRelationsToSync);
7989
8136
  draftEntries.forEach(emitEvent('entry.draft-discard'));
7990
8137
  return {
7991
8138
  documentId,