@strapi/core 5.0.0-rc.12 → 5.0.0-rc.14

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 (36) hide show
  1. package/dist/core-api/service/collection-type.d.ts +2 -2
  2. package/dist/middlewares/security.d.ts.map +1 -1
  3. package/dist/middlewares/security.js +1 -1
  4. package/dist/middlewares/security.js.map +1 -1
  5. package/dist/middlewares/security.mjs +1 -1
  6. package/dist/middlewares/security.mjs.map +1 -1
  7. package/dist/migrations/database/5.0.0-discard-drafts.d.ts +12 -9
  8. package/dist/migrations/database/5.0.0-discard-drafts.d.ts.map +1 -1
  9. package/dist/migrations/database/5.0.0-discard-drafts.js +50 -11
  10. package/dist/migrations/database/5.0.0-discard-drafts.js.map +1 -1
  11. package/dist/migrations/database/5.0.0-discard-drafts.mjs +51 -12
  12. package/dist/migrations/database/5.0.0-discard-drafts.mjs.map +1 -1
  13. package/dist/services/content-api/index.d.ts +6 -2
  14. package/dist/services/content-api/index.d.ts.map +1 -1
  15. package/dist/services/content-api/permissions/index.d.ts +6 -2
  16. package/dist/services/content-api/permissions/index.d.ts.map +1 -1
  17. package/dist/services/content-api/permissions/providers/action.d.ts +3 -1
  18. package/dist/services/content-api/permissions/providers/action.d.ts.map +1 -1
  19. package/dist/services/content-api/permissions/providers/condition.d.ts +3 -1
  20. package/dist/services/content-api/permissions/providers/condition.d.ts.map +1 -1
  21. package/dist/services/cron.d.ts +3 -3
  22. package/dist/services/cron.d.ts.map +1 -1
  23. package/dist/services/cron.js.map +1 -1
  24. package/dist/services/cron.mjs.map +1 -1
  25. package/dist/services/document-service/repository.d.ts.map +1 -1
  26. package/dist/services/document-service/repository.js +42 -6
  27. package/dist/services/document-service/repository.js.map +1 -1
  28. package/dist/services/document-service/repository.mjs +43 -7
  29. package/dist/services/document-service/repository.mjs.map +1 -1
  30. package/dist/services/document-service/utils/unidirectional-relations.d.ts +33 -0
  31. package/dist/services/document-service/utils/unidirectional-relations.d.ts.map +1 -0
  32. package/dist/services/document-service/utils/unidirectional-relations.js +58 -0
  33. package/dist/services/document-service/utils/unidirectional-relations.js.map +1 -0
  34. package/dist/services/document-service/utils/unidirectional-relations.mjs +58 -0
  35. package/dist/services/document-service/utils/unidirectional-relations.mjs.map +1 -0
  36. package/package.json +14 -15
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unidirectional-relations.js","sources":["../../../../src/services/document-service/utils/unidirectional-relations.ts"],"sourcesContent":["/* eslint-disable no-continue */\nimport { keyBy } from 'lodash/fp';\n\nimport { UID, Schema } from '@strapi/types';\n\n/**\n * Loads lingering relations that need to be updated when overriding a published or draft entry.\n * This is necessary because the relations are uni-directional and the target entry is not aware of the source entry.\n * This is not the case for bi-directional relations, where the target entry is also linked to the source entry.\n *\n * @param uid The content type uid\n * @param oldEntries The old entries that are being overridden\n * @returns An array of relations that need to be updated with the join table reference.\n */\nconst load = async (uid: UID.ContentType, oldEntries: { id: string; locale: string }[]) => {\n const updates = [] as any;\n\n // Iterate all components and content types to find relations that need to be updated\n await strapi.db.transaction(async ({ trx }) => {\n const contentTypes = Object.values(strapi.contentTypes) as Schema.ContentType[];\n const components = Object.values(strapi.components) as Schema.Component[];\n\n for (const model of [...contentTypes, ...components]) {\n const dbModel = strapi.db.metadata.get(model.uid);\n\n for (const attribute of Object.values(dbModel.attributes) as any) {\n /**\n * Only consider unidirectional relations\n */\n if (attribute.type !== 'relation') continue;\n if (attribute.target !== uid) continue;\n if (attribute.inversedBy || attribute.mappedBy) continue;\n const joinTable = attribute.joinTable;\n // TODO: joinColumn relations\n if (!joinTable) continue;\n\n const { name } = joinTable.inverseJoinColumn;\n\n /**\n * Load all relations that need to be updated\n */\n const oldEntriesIds = oldEntries.map((entry) => entry.id);\n const relations = await strapi.db\n .getConnection()\n .select('*')\n .from(joinTable.name)\n .whereIn(name, oldEntriesIds)\n .transacting(trx);\n\n if (relations.length === 0) continue;\n\n updates.push({ joinTable, relations });\n }\n }\n });\n\n return updates;\n};\n\n/**\n * Updates uni directional relations to target the right entries when overriding published or draft entries.\n *\n * @param oldEntries The old entries that are being overridden\n * @param newEntries The new entries that are overriding the old ones\n * @param oldRelations The relations that were previously loaded with `load` @see load\n */\nconst sync = async (\n oldEntries: { id: string; locale: string }[],\n newEntries: { id: string; locale: string }[],\n oldRelations: { joinTable: any; relations: any[] }[]\n) => {\n /**\n * Create a map of old entry ids to new entry ids\n *\n * Will be used to update the relation target ids\n */\n const newEntryByLocale = keyBy('locale', newEntries);\n const oldEntriesMap = oldEntries.reduce(\n (acc, entry) => {\n const newEntry = newEntryByLocale[entry.locale];\n if (!newEntry) return acc;\n acc[entry.id] = newEntry.id;\n return acc;\n },\n {} as Record<string, string>\n );\n\n await strapi.db.transaction(async ({ trx }) => {\n const con = strapi.db.getConnection();\n\n // Iterate old relations that are deleted and insert the new ones\n for (const { joinTable, relations } of oldRelations) {\n // Update old ids with the new ones\n const newRelations = relations.map((relation) => {\n const column = joinTable.inverseJoinColumn.name;\n const newId = oldEntriesMap[relation[column]];\n return { ...relation, [column]: newId };\n });\n\n // Insert those relations into the join table\n await con.batchInsert(joinTable.name, newRelations).transacting(trx);\n }\n });\n};\n\nexport { load, sync };\n"],"names":["keyBy"],"mappings":";;;AAcM,MAAA,OAAO,OAAO,KAAsB,eAAiD;AACzF,QAAM,UAAU,CAAA;AAGhB,QAAM,OAAO,GAAG,YAAY,OAAO,EAAE,UAAU;AAC7C,UAAM,eAAe,OAAO,OAAO,OAAO,YAAY;AACtD,UAAM,aAAa,OAAO,OAAO,OAAO,UAAU;AAElD,eAAW,SAAS,CAAC,GAAG,cAAc,GAAG,UAAU,GAAG;AACpD,YAAM,UAAU,OAAO,GAAG,SAAS,IAAI,MAAM,GAAG;AAEhD,iBAAW,aAAa,OAAO,OAAO,QAAQ,UAAU,GAAU;AAIhE,YAAI,UAAU,SAAS;AAAY;AACnC,YAAI,UAAU,WAAW;AAAK;AAC1B,YAAA,UAAU,cAAc,UAAU;AAAU;AAChD,cAAM,YAAY,UAAU;AAE5B,YAAI,CAAC;AAAW;AAEV,cAAA,EAAE,KAAK,IAAI,UAAU;AAK3B,cAAM,gBAAgB,WAAW,IAAI,CAAC,UAAU,MAAM,EAAE;AACxD,cAAM,YAAY,MAAM,OAAO,GAC5B,gBACA,OAAO,GAAG,EACV,KAAK,UAAU,IAAI,EACnB,QAAQ,MAAM,aAAa,EAC3B,YAAY,GAAG;AAElB,YAAI,UAAU,WAAW;AAAG;AAE5B,gBAAQ,KAAK,EAAE,WAAW,UAAW,CAAA;AAAA,MACvC;AAAA,IACF;AAAA,EAAA,CACD;AAEM,SAAA;AACT;AASA,MAAM,OAAO,OACX,YACA,YACA,iBACG;AAMG,QAAA,mBAAmBA,GAAAA,MAAM,UAAU,UAAU;AACnD,QAAM,gBAAgB,WAAW;AAAA,IAC/B,CAAC,KAAK,UAAU;AACR,YAAA,WAAW,iBAAiB,MAAM,MAAM;AAC9C,UAAI,CAAC;AAAiB,eAAA;AAClB,UAAA,MAAM,EAAE,IAAI,SAAS;AAClB,aAAA;AAAA,IACT;AAAA,IACA,CAAC;AAAA,EAAA;AAGH,QAAM,OAAO,GAAG,YAAY,OAAO,EAAE,UAAU;AACvC,UAAA,MAAM,OAAO,GAAG,cAAc;AAGpC,eAAW,EAAE,WAAW,UAAU,KAAK,cAAc;AAEnD,YAAM,eAAe,UAAU,IAAI,CAAC,aAAa;AACzC,cAAA,SAAS,UAAU,kBAAkB;AAC3C,cAAM,QAAQ,cAAc,SAAS,MAAM,CAAC;AAC5C,eAAO,EAAE,GAAG,UAAU,CAAC,MAAM,GAAG,MAAM;AAAA,MAAA,CACvC;AAGD,YAAM,IAAI,YAAY,UAAU,MAAM,YAAY,EAAE,YAAY,GAAG;AAAA,IACrE;AAAA,EAAA,CACD;AACH;;;"}
@@ -0,0 +1,58 @@
1
+ import { keyBy } from "lodash/fp";
2
+ const load = async (uid, oldEntries) => {
3
+ const updates = [];
4
+ await strapi.db.transaction(async ({ trx }) => {
5
+ const contentTypes = Object.values(strapi.contentTypes);
6
+ const components = Object.values(strapi.components);
7
+ for (const model of [...contentTypes, ...components]) {
8
+ const dbModel = strapi.db.metadata.get(model.uid);
9
+ for (const attribute of Object.values(dbModel.attributes)) {
10
+ if (attribute.type !== "relation")
11
+ continue;
12
+ if (attribute.target !== uid)
13
+ continue;
14
+ if (attribute.inversedBy || attribute.mappedBy)
15
+ continue;
16
+ const joinTable = attribute.joinTable;
17
+ if (!joinTable)
18
+ continue;
19
+ const { name } = joinTable.inverseJoinColumn;
20
+ const oldEntriesIds = oldEntries.map((entry) => entry.id);
21
+ const relations = await strapi.db.getConnection().select("*").from(joinTable.name).whereIn(name, oldEntriesIds).transacting(trx);
22
+ if (relations.length === 0)
23
+ continue;
24
+ updates.push({ joinTable, relations });
25
+ }
26
+ }
27
+ });
28
+ return updates;
29
+ };
30
+ const sync = async (oldEntries, newEntries, oldRelations) => {
31
+ const newEntryByLocale = keyBy("locale", newEntries);
32
+ const oldEntriesMap = oldEntries.reduce(
33
+ (acc, entry) => {
34
+ const newEntry = newEntryByLocale[entry.locale];
35
+ if (!newEntry)
36
+ return acc;
37
+ acc[entry.id] = newEntry.id;
38
+ return acc;
39
+ },
40
+ {}
41
+ );
42
+ await strapi.db.transaction(async ({ trx }) => {
43
+ const con = strapi.db.getConnection();
44
+ for (const { joinTable, relations } of oldRelations) {
45
+ const newRelations = relations.map((relation) => {
46
+ const column = joinTable.inverseJoinColumn.name;
47
+ const newId = oldEntriesMap[relation[column]];
48
+ return { ...relation, [column]: newId };
49
+ });
50
+ await con.batchInsert(joinTable.name, newRelations).transacting(trx);
51
+ }
52
+ });
53
+ };
54
+ export {
55
+ load,
56
+ sync
57
+ };
58
+ //# sourceMappingURL=unidirectional-relations.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unidirectional-relations.mjs","sources":["../../../../src/services/document-service/utils/unidirectional-relations.ts"],"sourcesContent":["/* eslint-disable no-continue */\nimport { keyBy } from 'lodash/fp';\n\nimport { UID, Schema } from '@strapi/types';\n\n/**\n * Loads lingering relations that need to be updated when overriding a published or draft entry.\n * This is necessary because the relations are uni-directional and the target entry is not aware of the source entry.\n * This is not the case for bi-directional relations, where the target entry is also linked to the source entry.\n *\n * @param uid The content type uid\n * @param oldEntries The old entries that are being overridden\n * @returns An array of relations that need to be updated with the join table reference.\n */\nconst load = async (uid: UID.ContentType, oldEntries: { id: string; locale: string }[]) => {\n const updates = [] as any;\n\n // Iterate all components and content types to find relations that need to be updated\n await strapi.db.transaction(async ({ trx }) => {\n const contentTypes = Object.values(strapi.contentTypes) as Schema.ContentType[];\n const components = Object.values(strapi.components) as Schema.Component[];\n\n for (const model of [...contentTypes, ...components]) {\n const dbModel = strapi.db.metadata.get(model.uid);\n\n for (const attribute of Object.values(dbModel.attributes) as any) {\n /**\n * Only consider unidirectional relations\n */\n if (attribute.type !== 'relation') continue;\n if (attribute.target !== uid) continue;\n if (attribute.inversedBy || attribute.mappedBy) continue;\n const joinTable = attribute.joinTable;\n // TODO: joinColumn relations\n if (!joinTable) continue;\n\n const { name } = joinTable.inverseJoinColumn;\n\n /**\n * Load all relations that need to be updated\n */\n const oldEntriesIds = oldEntries.map((entry) => entry.id);\n const relations = await strapi.db\n .getConnection()\n .select('*')\n .from(joinTable.name)\n .whereIn(name, oldEntriesIds)\n .transacting(trx);\n\n if (relations.length === 0) continue;\n\n updates.push({ joinTable, relations });\n }\n }\n });\n\n return updates;\n};\n\n/**\n * Updates uni directional relations to target the right entries when overriding published or draft entries.\n *\n * @param oldEntries The old entries that are being overridden\n * @param newEntries The new entries that are overriding the old ones\n * @param oldRelations The relations that were previously loaded with `load` @see load\n */\nconst sync = async (\n oldEntries: { id: string; locale: string }[],\n newEntries: { id: string; locale: string }[],\n oldRelations: { joinTable: any; relations: any[] }[]\n) => {\n /**\n * Create a map of old entry ids to new entry ids\n *\n * Will be used to update the relation target ids\n */\n const newEntryByLocale = keyBy('locale', newEntries);\n const oldEntriesMap = oldEntries.reduce(\n (acc, entry) => {\n const newEntry = newEntryByLocale[entry.locale];\n if (!newEntry) return acc;\n acc[entry.id] = newEntry.id;\n return acc;\n },\n {} as Record<string, string>\n );\n\n await strapi.db.transaction(async ({ trx }) => {\n const con = strapi.db.getConnection();\n\n // Iterate old relations that are deleted and insert the new ones\n for (const { joinTable, relations } of oldRelations) {\n // Update old ids with the new ones\n const newRelations = relations.map((relation) => {\n const column = joinTable.inverseJoinColumn.name;\n const newId = oldEntriesMap[relation[column]];\n return { ...relation, [column]: newId };\n });\n\n // Insert those relations into the join table\n await con.batchInsert(joinTable.name, newRelations).transacting(trx);\n }\n });\n};\n\nexport { load, sync };\n"],"names":[],"mappings":";AAcM,MAAA,OAAO,OAAO,KAAsB,eAAiD;AACzF,QAAM,UAAU,CAAA;AAGhB,QAAM,OAAO,GAAG,YAAY,OAAO,EAAE,UAAU;AAC7C,UAAM,eAAe,OAAO,OAAO,OAAO,YAAY;AACtD,UAAM,aAAa,OAAO,OAAO,OAAO,UAAU;AAElD,eAAW,SAAS,CAAC,GAAG,cAAc,GAAG,UAAU,GAAG;AACpD,YAAM,UAAU,OAAO,GAAG,SAAS,IAAI,MAAM,GAAG;AAEhD,iBAAW,aAAa,OAAO,OAAO,QAAQ,UAAU,GAAU;AAIhE,YAAI,UAAU,SAAS;AAAY;AACnC,YAAI,UAAU,WAAW;AAAK;AAC1B,YAAA,UAAU,cAAc,UAAU;AAAU;AAChD,cAAM,YAAY,UAAU;AAE5B,YAAI,CAAC;AAAW;AAEV,cAAA,EAAE,KAAK,IAAI,UAAU;AAK3B,cAAM,gBAAgB,WAAW,IAAI,CAAC,UAAU,MAAM,EAAE;AACxD,cAAM,YAAY,MAAM,OAAO,GAC5B,gBACA,OAAO,GAAG,EACV,KAAK,UAAU,IAAI,EACnB,QAAQ,MAAM,aAAa,EAC3B,YAAY,GAAG;AAElB,YAAI,UAAU,WAAW;AAAG;AAE5B,gBAAQ,KAAK,EAAE,WAAW,UAAW,CAAA;AAAA,MACvC;AAAA,IACF;AAAA,EAAA,CACD;AAEM,SAAA;AACT;AASA,MAAM,OAAO,OACX,YACA,YACA,iBACG;AAMG,QAAA,mBAAmB,MAAM,UAAU,UAAU;AACnD,QAAM,gBAAgB,WAAW;AAAA,IAC/B,CAAC,KAAK,UAAU;AACR,YAAA,WAAW,iBAAiB,MAAM,MAAM;AAC9C,UAAI,CAAC;AAAiB,eAAA;AAClB,UAAA,MAAM,EAAE,IAAI,SAAS;AAClB,aAAA;AAAA,IACT;AAAA,IACA,CAAC;AAAA,EAAA;AAGH,QAAM,OAAO,GAAG,YAAY,OAAO,EAAE,UAAU;AACvC,UAAA,MAAM,OAAO,GAAG,cAAc;AAGpC,eAAW,EAAE,WAAW,UAAU,KAAK,cAAc;AAEnD,YAAM,eAAe,UAAU,IAAI,CAAC,aAAa;AACzC,cAAA,SAAS,UAAU,kBAAkB;AAC3C,cAAM,QAAQ,cAAc,SAAS,MAAM,CAAC;AAC5C,eAAO,EAAE,GAAG,UAAU,CAAC,MAAM,GAAG,MAAM;AAAA,MAAA,CACvC;AAGD,YAAM,IAAI,YAAY,UAAU,MAAM,YAAY,EAAE,YAAY,GAAG;AAAA,IACrE;AAAA,EAAA,CACD;AACH;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/core",
3
- "version": "5.0.0-rc.12",
3
+ "version": "5.0.0-rc.14",
4
4
  "description": "Core of Strapi",
5
5
  "homepage": "https://strapi.io",
6
6
  "bugs": {
@@ -55,16 +55,15 @@
55
55
  "@koa/cors": "5.0.0",
56
56
  "@koa/router": "12.0.1",
57
57
  "@paralleldrive/cuid2": "2.2.2",
58
- "@strapi/admin": "5.0.0-rc.12",
59
- "@strapi/database": "5.0.0-rc.12",
60
- "@strapi/generate-new": "5.0.0-rc.12",
61
- "@strapi/generators": "5.0.0-rc.12",
62
- "@strapi/logger": "5.0.0-rc.12",
58
+ "@strapi/admin": "5.0.0-rc.14",
59
+ "@strapi/database": "5.0.0-rc.14",
60
+ "@strapi/generators": "5.0.0-rc.14",
61
+ "@strapi/logger": "5.0.0-rc.14",
63
62
  "@strapi/pack-up": "5.0.0",
64
- "@strapi/permissions": "5.0.0-rc.12",
65
- "@strapi/types": "5.0.0-rc.12",
66
- "@strapi/typescript-utils": "5.0.0-rc.12",
67
- "@strapi/utils": "5.0.0-rc.12",
63
+ "@strapi/permissions": "5.0.0-rc.14",
64
+ "@strapi/types": "5.0.0-rc.14",
65
+ "@strapi/typescript-utils": "5.0.0-rc.14",
66
+ "@strapi/utils": "5.0.0-rc.14",
68
67
  "bcryptjs": "2.4.3",
69
68
  "boxen": "5.1.2",
70
69
  "chalk": "4.1.2",
@@ -94,7 +93,7 @@
94
93
  "koa-static": "5.0.0",
95
94
  "lodash": "4.17.21",
96
95
  "mime-types": "2.1.35",
97
- "node-schedule": "2.1.0",
96
+ "node-schedule": "2.1.1",
98
97
  "open": "8.4.0",
99
98
  "ora": "5.4.1",
100
99
  "package-json": "7.0.0",
@@ -124,15 +123,15 @@
124
123
  "@types/lodash": "^4.14.191",
125
124
  "@types/mime-types": "2.1.1",
126
125
  "@types/node": "18.19.24",
127
- "@types/node-schedule": "2.1.0",
126
+ "@types/node-schedule": "2.1.7",
128
127
  "@types/statuses": "2.0.1",
129
- "eslint-config-custom": "5.0.0-rc.12",
128
+ "eslint-config-custom": "5.0.0-rc.14",
130
129
  "supertest": "6.3.3",
131
- "tsconfig": "5.0.0-rc.12"
130
+ "tsconfig": "5.0.0-rc.14"
132
131
  },
133
132
  "engines": {
134
133
  "node": ">=18.0.0 <=20.x.x",
135
134
  "npm": ">=6.0.0"
136
135
  },
137
- "gitHead": "18f223b8357a308e33cd62e07c2173784535bf4e"
136
+ "gitHead": "e18c706dc0bfda296f9c3005e719bd60b3732531"
138
137
  }