@strapi/core 0.0.0-experimental.6d27139261823fc4b18da9f3c10b271d5010dbf0 → 0.0.0-experimental.71ed910bd859c7e558bd1c1042eaadb7d26fd22a
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.
Potentially problematic release.
This version of @strapi/core might be problematic. Click here for more details.
- package/dist/core-api/service/collection-type.d.ts +2 -2
- package/dist/factories.js.map +1 -1
- package/dist/factories.mjs.map +1 -1
- package/dist/loaders/plugins/get-enabled-plugins.d.ts.map +1 -1
- package/dist/loaders/plugins/get-enabled-plugins.js +5 -2
- package/dist/loaders/plugins/get-enabled-plugins.js.map +1 -1
- package/dist/loaders/plugins/get-enabled-plugins.mjs +5 -2
- package/dist/loaders/plugins/get-enabled-plugins.mjs.map +1 -1
- package/dist/loaders/plugins/index.d.ts.map +1 -1
- package/dist/loaders/plugins/index.js +28 -1
- package/dist/loaders/plugins/index.js.map +1 -1
- package/dist/loaders/plugins/index.mjs +9 -1
- package/dist/loaders/plugins/index.mjs.map +1 -1
- package/dist/middlewares/security.d.ts.map +1 -1
- package/dist/middlewares/security.js +1 -1
- package/dist/middlewares/security.js.map +1 -1
- package/dist/middlewares/security.mjs +1 -1
- package/dist/middlewares/security.mjs.map +1 -1
- package/dist/migrations/database/5.0.0-discard-drafts.d.ts +12 -9
- package/dist/migrations/database/5.0.0-discard-drafts.d.ts.map +1 -1
- package/dist/migrations/database/5.0.0-discard-drafts.js +55 -11
- package/dist/migrations/database/5.0.0-discard-drafts.js.map +1 -1
- package/dist/migrations/database/5.0.0-discard-drafts.mjs +56 -12
- package/dist/migrations/database/5.0.0-discard-drafts.mjs.map +1 -1
- package/dist/migrations/draft-publish.d.ts +1 -1
- package/dist/migrations/draft-publish.d.ts.map +1 -1
- package/dist/migrations/draft-publish.js.map +1 -1
- package/dist/migrations/draft-publish.mjs.map +1 -1
- package/dist/migrations/i18n.d.ts +5 -0
- package/dist/migrations/i18n.d.ts.map +1 -0
- package/dist/migrations/i18n.js +54 -0
- package/dist/migrations/i18n.js.map +1 -0
- package/dist/migrations/i18n.mjs +54 -0
- package/dist/migrations/i18n.mjs.map +1 -0
- package/dist/migrations/index.d.ts +5 -0
- package/dist/migrations/index.d.ts.map +1 -0
- package/dist/migrations/index.js +15 -0
- package/dist/migrations/index.js.map +1 -0
- package/dist/migrations/index.mjs +15 -0
- package/dist/migrations/index.mjs.map +1 -0
- package/dist/providers/admin.d.ts.map +1 -1
- package/dist/providers/admin.js.map +1 -1
- package/dist/providers/admin.mjs.map +1 -1
- package/dist/providers/registries.js +3 -3
- package/dist/providers/registries.js.map +1 -1
- package/dist/providers/registries.mjs +3 -3
- package/dist/providers/registries.mjs.map +1 -1
- package/dist/services/content-api/index.d.ts +6 -2
- package/dist/services/content-api/index.d.ts.map +1 -1
- package/dist/services/content-api/permissions/index.d.ts +6 -2
- package/dist/services/content-api/permissions/index.d.ts.map +1 -1
- package/dist/services/content-api/permissions/providers/action.d.ts +3 -1
- package/dist/services/content-api/permissions/providers/action.d.ts.map +1 -1
- package/dist/services/content-api/permissions/providers/condition.d.ts +3 -1
- package/dist/services/content-api/permissions/providers/condition.d.ts.map +1 -1
- package/dist/services/cron.d.ts +3 -3
- package/dist/services/cron.d.ts.map +1 -1
- package/dist/services/cron.js.map +1 -1
- package/dist/services/cron.mjs.map +1 -1
- package/dist/services/document-service/repository.d.ts.map +1 -1
- package/dist/services/document-service/repository.js +42 -6
- package/dist/services/document-service/repository.js.map +1 -1
- package/dist/services/document-service/repository.mjs +43 -7
- package/dist/services/document-service/repository.mjs.map +1 -1
- package/dist/services/document-service/utils/populate.d.ts.map +1 -1
- package/dist/services/document-service/utils/populate.js +3 -1
- package/dist/services/document-service/utils/populate.js.map +1 -1
- package/dist/services/document-service/utils/populate.mjs +3 -1
- package/dist/services/document-service/utils/populate.mjs.map +1 -1
- package/dist/services/document-service/utils/unidirectional-relations.d.ts +33 -0
- package/dist/services/document-service/utils/unidirectional-relations.d.ts.map +1 -0
- package/dist/services/document-service/utils/unidirectional-relations.js +58 -0
- package/dist/services/document-service/utils/unidirectional-relations.js.map +1 -0
- package/dist/services/document-service/utils/unidirectional-relations.mjs +58 -0
- package/dist/services/document-service/utils/unidirectional-relations.mjs.map +1 -0
- package/package.json +15 -14
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const strapiUtils = require("@strapi/utils");
|
|
4
|
+
const { CREATED_BY_ATTRIBUTE, UPDATED_BY_ATTRIBUTE } = strapiUtils.contentTypes.constants;
|
|
4
5
|
const getDeepPopulate = (uid, opts = {}) => {
|
|
5
6
|
const model = strapi.getModel(uid);
|
|
6
7
|
const attributes = Object.entries(model.attributes);
|
|
@@ -12,7 +13,8 @@ const getDeepPopulate = (uid, opts = {}) => {
|
|
|
12
13
|
break;
|
|
13
14
|
}
|
|
14
15
|
const isVisible = strapiUtils.contentTypes.isVisibleAttribute(model, attributeName);
|
|
15
|
-
|
|
16
|
+
const isCreatorField = [CREATED_BY_ATTRIBUTE, UPDATED_BY_ATTRIBUTE].includes(attributeName);
|
|
17
|
+
if (isVisible || isCreatorField) {
|
|
16
18
|
acc[attributeName] = { select: opts.relationalFields };
|
|
17
19
|
}
|
|
18
20
|
break;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"populate.js","sources":["../../../../src/services/document-service/utils/populate.ts"],"sourcesContent":["import { UID } from '@strapi/types';\nimport { contentTypes } from '@strapi/utils';\n\ninterface Options {\n /**\n * Fields to select when populating relations\n */\n relationalFields?: string[];\n}\n\n// We want to build a populate object based on the schema\nexport const getDeepPopulate = (uid: UID.Schema, opts: Options = {}) => {\n const model = strapi.getModel(uid);\n const attributes = Object.entries(model.attributes);\n\n return attributes.reduce((acc: any, [attributeName, attribute]) => {\n switch (attribute.type) {\n case 'relation': {\n // TODO: Support polymorphic relations\n const isMorphRelation = attribute.relation.toLowerCase().startsWith('morph');\n if (isMorphRelation) {\n break;\n }\n\n //
|
|
1
|
+
{"version":3,"file":"populate.js","sources":["../../../../src/services/document-service/utils/populate.ts"],"sourcesContent":["import { UID } from '@strapi/types';\nimport { contentTypes } from '@strapi/utils';\n\ninterface Options {\n /**\n * Fields to select when populating relations\n */\n relationalFields?: string[];\n}\n\nconst { CREATED_BY_ATTRIBUTE, UPDATED_BY_ATTRIBUTE } = contentTypes.constants;\n\n// We want to build a populate object based on the schema\nexport const getDeepPopulate = (uid: UID.Schema, opts: Options = {}) => {\n const model = strapi.getModel(uid);\n const attributes = Object.entries(model.attributes);\n\n return attributes.reduce((acc: any, [attributeName, attribute]) => {\n switch (attribute.type) {\n case 'relation': {\n // TODO: Support polymorphic relations\n const isMorphRelation = attribute.relation.toLowerCase().startsWith('morph');\n if (isMorphRelation) {\n break;\n }\n\n // Ignore not visible fields other than createdBy and updatedBy\n const isVisible = contentTypes.isVisibleAttribute(model, attributeName);\n const isCreatorField = [CREATED_BY_ATTRIBUTE, UPDATED_BY_ATTRIBUTE].includes(attributeName);\n\n if (isVisible || isCreatorField) {\n acc[attributeName] = { select: opts.relationalFields };\n }\n\n break;\n }\n\n case 'media': {\n acc[attributeName] = { select: ['id'] };\n break;\n }\n\n case 'component': {\n const populate = getDeepPopulate(attribute.component, opts);\n acc[attributeName] = { populate };\n break;\n }\n\n case 'dynamiczone': {\n // Use fragments to populate the dynamic zone components\n const populatedComponents = (attribute.components || []).reduce(\n (acc: any, componentUID: UID.Component) => {\n acc[componentUID] = { populate: getDeepPopulate(componentUID, opts) };\n return acc;\n },\n {}\n );\n\n acc[attributeName] = { on: populatedComponents };\n break;\n }\n default:\n break;\n }\n\n return acc;\n }, {});\n};\n"],"names":["contentTypes","acc"],"mappings":";;;AAUA,MAAM,EAAE,sBAAsB,yBAAyBA,YAAAA,aAAa;AAG7D,MAAM,kBAAkB,CAAC,KAAiB,OAAgB,OAAO;AAChE,QAAA,QAAQ,OAAO,SAAS,GAAG;AACjC,QAAM,aAAa,OAAO,QAAQ,MAAM,UAAU;AAElD,SAAO,WAAW,OAAO,CAAC,KAAU,CAAC,eAAe,SAAS,MAAM;AACjE,YAAQ,UAAU,MAAM;AAAA,MACtB,KAAK,YAAY;AAEf,cAAM,kBAAkB,UAAU,SAAS,YAAY,EAAE,WAAW,OAAO;AAC3E,YAAI,iBAAiB;AACnB;AAAA,QACF;AAGA,cAAM,YAAYA,YAAA,aAAa,mBAAmB,OAAO,aAAa;AACtE,cAAM,iBAAiB,CAAC,sBAAsB,oBAAoB,EAAE,SAAS,aAAa;AAE1F,YAAI,aAAa,gBAAgB;AAC/B,cAAI,aAAa,IAAI,EAAE,QAAQ,KAAK,iBAAiB;AAAA,QACvD;AAEA;AAAA,MACF;AAAA,MAEA,KAAK,SAAS;AACZ,YAAI,aAAa,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE;AACtC;AAAA,MACF;AAAA,MAEA,KAAK,aAAa;AAChB,cAAM,WAAW,gBAAgB,UAAU,WAAW,IAAI;AACtD,YAAA,aAAa,IAAI,EAAE;AACvB;AAAA,MACF;AAAA,MAEA,KAAK,eAAe;AAElB,cAAM,uBAAuB,UAAU,cAAc,CAAI,GAAA;AAAA,UACvD,CAACC,MAAU,iBAAgC;AACzCA,iBAAI,YAAY,IAAI,EAAE,UAAU,gBAAgB,cAAc,IAAI;AAC3DA,mBAAAA;AAAAA,UACT;AAAA,UACA,CAAC;AAAA,QAAA;AAGH,YAAI,aAAa,IAAI,EAAE,IAAI,oBAAoB;AAC/C;AAAA,MACF;AAAA,IAGF;AAEO,WAAA;AAAA,EACT,GAAG,CAAE,CAAA;AACP;;"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { contentTypes } from "@strapi/utils";
|
|
2
|
+
const { CREATED_BY_ATTRIBUTE, UPDATED_BY_ATTRIBUTE } = contentTypes.constants;
|
|
2
3
|
const getDeepPopulate = (uid, opts = {}) => {
|
|
3
4
|
const model = strapi.getModel(uid);
|
|
4
5
|
const attributes = Object.entries(model.attributes);
|
|
@@ -10,7 +11,8 @@ const getDeepPopulate = (uid, opts = {}) => {
|
|
|
10
11
|
break;
|
|
11
12
|
}
|
|
12
13
|
const isVisible = contentTypes.isVisibleAttribute(model, attributeName);
|
|
13
|
-
|
|
14
|
+
const isCreatorField = [CREATED_BY_ATTRIBUTE, UPDATED_BY_ATTRIBUTE].includes(attributeName);
|
|
15
|
+
if (isVisible || isCreatorField) {
|
|
14
16
|
acc[attributeName] = { select: opts.relationalFields };
|
|
15
17
|
}
|
|
16
18
|
break;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"populate.mjs","sources":["../../../../src/services/document-service/utils/populate.ts"],"sourcesContent":["import { UID } from '@strapi/types';\nimport { contentTypes } from '@strapi/utils';\n\ninterface Options {\n /**\n * Fields to select when populating relations\n */\n relationalFields?: string[];\n}\n\n// We want to build a populate object based on the schema\nexport const getDeepPopulate = (uid: UID.Schema, opts: Options = {}) => {\n const model = strapi.getModel(uid);\n const attributes = Object.entries(model.attributes);\n\n return attributes.reduce((acc: any, [attributeName, attribute]) => {\n switch (attribute.type) {\n case 'relation': {\n // TODO: Support polymorphic relations\n const isMorphRelation = attribute.relation.toLowerCase().startsWith('morph');\n if (isMorphRelation) {\n break;\n }\n\n //
|
|
1
|
+
{"version":3,"file":"populate.mjs","sources":["../../../../src/services/document-service/utils/populate.ts"],"sourcesContent":["import { UID } from '@strapi/types';\nimport { contentTypes } from '@strapi/utils';\n\ninterface Options {\n /**\n * Fields to select when populating relations\n */\n relationalFields?: string[];\n}\n\nconst { CREATED_BY_ATTRIBUTE, UPDATED_BY_ATTRIBUTE } = contentTypes.constants;\n\n// We want to build a populate object based on the schema\nexport const getDeepPopulate = (uid: UID.Schema, opts: Options = {}) => {\n const model = strapi.getModel(uid);\n const attributes = Object.entries(model.attributes);\n\n return attributes.reduce((acc: any, [attributeName, attribute]) => {\n switch (attribute.type) {\n case 'relation': {\n // TODO: Support polymorphic relations\n const isMorphRelation = attribute.relation.toLowerCase().startsWith('morph');\n if (isMorphRelation) {\n break;\n }\n\n // Ignore not visible fields other than createdBy and updatedBy\n const isVisible = contentTypes.isVisibleAttribute(model, attributeName);\n const isCreatorField = [CREATED_BY_ATTRIBUTE, UPDATED_BY_ATTRIBUTE].includes(attributeName);\n\n if (isVisible || isCreatorField) {\n acc[attributeName] = { select: opts.relationalFields };\n }\n\n break;\n }\n\n case 'media': {\n acc[attributeName] = { select: ['id'] };\n break;\n }\n\n case 'component': {\n const populate = getDeepPopulate(attribute.component, opts);\n acc[attributeName] = { populate };\n break;\n }\n\n case 'dynamiczone': {\n // Use fragments to populate the dynamic zone components\n const populatedComponents = (attribute.components || []).reduce(\n (acc: any, componentUID: UID.Component) => {\n acc[componentUID] = { populate: getDeepPopulate(componentUID, opts) };\n return acc;\n },\n {}\n );\n\n acc[attributeName] = { on: populatedComponents };\n break;\n }\n default:\n break;\n }\n\n return acc;\n }, {});\n};\n"],"names":["acc"],"mappings":";AAUA,MAAM,EAAE,sBAAsB,yBAAyB,aAAa;AAG7D,MAAM,kBAAkB,CAAC,KAAiB,OAAgB,OAAO;AAChE,QAAA,QAAQ,OAAO,SAAS,GAAG;AACjC,QAAM,aAAa,OAAO,QAAQ,MAAM,UAAU;AAElD,SAAO,WAAW,OAAO,CAAC,KAAU,CAAC,eAAe,SAAS,MAAM;AACjE,YAAQ,UAAU,MAAM;AAAA,MACtB,KAAK,YAAY;AAEf,cAAM,kBAAkB,UAAU,SAAS,YAAY,EAAE,WAAW,OAAO;AAC3E,YAAI,iBAAiB;AACnB;AAAA,QACF;AAGA,cAAM,YAAY,aAAa,mBAAmB,OAAO,aAAa;AACtE,cAAM,iBAAiB,CAAC,sBAAsB,oBAAoB,EAAE,SAAS,aAAa;AAE1F,YAAI,aAAa,gBAAgB;AAC/B,cAAI,aAAa,IAAI,EAAE,QAAQ,KAAK,iBAAiB;AAAA,QACvD;AAEA;AAAA,MACF;AAAA,MAEA,KAAK,SAAS;AACZ,YAAI,aAAa,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE;AACtC;AAAA,MACF;AAAA,MAEA,KAAK,aAAa;AAChB,cAAM,WAAW,gBAAgB,UAAU,WAAW,IAAI;AACtD,YAAA,aAAa,IAAI,EAAE;AACvB;AAAA,MACF;AAAA,MAEA,KAAK,eAAe;AAElB,cAAM,uBAAuB,UAAU,cAAc,CAAI,GAAA;AAAA,UACvD,CAACA,MAAU,iBAAgC;AACzCA,iBAAI,YAAY,IAAI,EAAE,UAAU,gBAAgB,cAAc,IAAI;AAC3DA,mBAAAA;AAAAA,UACT;AAAA,UACA,CAAC;AAAA,QAAA;AAGH,YAAI,aAAa,IAAI,EAAE,IAAI,oBAAoB;AAC/C;AAAA,MACF;AAAA,IAGF;AAEO,WAAA;AAAA,EACT,GAAG,CAAE,CAAA;AACP;"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { UID } from '@strapi/types';
|
|
2
|
+
/**
|
|
3
|
+
* Loads lingering relations that need to be updated when overriding a published or draft entry.
|
|
4
|
+
* This is necessary because the relations are uni-directional and the target entry is not aware of the source entry.
|
|
5
|
+
* This is not the case for bi-directional relations, where the target entry is also linked to the source entry.
|
|
6
|
+
*
|
|
7
|
+
* @param uid The content type uid
|
|
8
|
+
* @param oldEntries The old entries that are being overridden
|
|
9
|
+
* @returns An array of relations that need to be updated with the join table reference.
|
|
10
|
+
*/
|
|
11
|
+
declare const load: (uid: UID.ContentType, oldEntries: {
|
|
12
|
+
id: string;
|
|
13
|
+
locale: string;
|
|
14
|
+
}[]) => Promise<any>;
|
|
15
|
+
/**
|
|
16
|
+
* Updates uni directional relations to target the right entries when overriding published or draft entries.
|
|
17
|
+
*
|
|
18
|
+
* @param oldEntries The old entries that are being overridden
|
|
19
|
+
* @param newEntries The new entries that are overriding the old ones
|
|
20
|
+
* @param oldRelations The relations that were previously loaded with `load` @see load
|
|
21
|
+
*/
|
|
22
|
+
declare const sync: (oldEntries: {
|
|
23
|
+
id: string;
|
|
24
|
+
locale: string;
|
|
25
|
+
}[], newEntries: {
|
|
26
|
+
id: string;
|
|
27
|
+
locale: string;
|
|
28
|
+
}[], oldRelations: {
|
|
29
|
+
joinTable: any;
|
|
30
|
+
relations: any[];
|
|
31
|
+
}[]) => Promise<void>;
|
|
32
|
+
export { load, sync };
|
|
33
|
+
//# sourceMappingURL=unidirectional-relations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unidirectional-relations.d.ts","sourceRoot":"","sources":["../../../../src/services/document-service/utils/unidirectional-relations.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,GAAG,EAAU,MAAM,eAAe,CAAC;AAE5C;;;;;;;;GAQG;AACH,QAAA,MAAM,IAAI,QAAe,IAAI,WAAW,cAAc;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,EAAE,iBA2CrF,CAAC;AAEF;;;;;;GAMG;AACH,QAAA,MAAM,IAAI,eACI;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,EAAE,cAChC;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,EAAE,gBAC9B;IAAE,SAAS,EAAE,GAAG,CAAC;IAAC,SAAS,EAAE,GAAG,EAAE,CAAA;CAAE,EAAE,kBAkCrD,CAAC;AAEF,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const fp = require("lodash/fp");
|
|
4
|
+
const load = async (uid, oldEntries) => {
|
|
5
|
+
const updates = [];
|
|
6
|
+
await strapi.db.transaction(async ({ trx }) => {
|
|
7
|
+
const contentTypes = Object.values(strapi.contentTypes);
|
|
8
|
+
const components = Object.values(strapi.components);
|
|
9
|
+
for (const model of [...contentTypes, ...components]) {
|
|
10
|
+
const dbModel = strapi.db.metadata.get(model.uid);
|
|
11
|
+
for (const attribute of Object.values(dbModel.attributes)) {
|
|
12
|
+
if (attribute.type !== "relation")
|
|
13
|
+
continue;
|
|
14
|
+
if (attribute.target !== uid)
|
|
15
|
+
continue;
|
|
16
|
+
if (attribute.inversedBy || attribute.mappedBy)
|
|
17
|
+
continue;
|
|
18
|
+
const joinTable = attribute.joinTable;
|
|
19
|
+
if (!joinTable)
|
|
20
|
+
continue;
|
|
21
|
+
const { name } = joinTable.inverseJoinColumn;
|
|
22
|
+
const oldEntriesIds = oldEntries.map((entry) => entry.id);
|
|
23
|
+
const relations = await strapi.db.getConnection().select("*").from(joinTable.name).whereIn(name, oldEntriesIds).transacting(trx);
|
|
24
|
+
if (relations.length === 0)
|
|
25
|
+
continue;
|
|
26
|
+
updates.push({ joinTable, relations });
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
return updates;
|
|
31
|
+
};
|
|
32
|
+
const sync = async (oldEntries, newEntries, oldRelations) => {
|
|
33
|
+
const newEntryByLocale = fp.keyBy("locale", newEntries);
|
|
34
|
+
const oldEntriesMap = oldEntries.reduce(
|
|
35
|
+
(acc, entry) => {
|
|
36
|
+
const newEntry = newEntryByLocale[entry.locale];
|
|
37
|
+
if (!newEntry)
|
|
38
|
+
return acc;
|
|
39
|
+
acc[entry.id] = newEntry.id;
|
|
40
|
+
return acc;
|
|
41
|
+
},
|
|
42
|
+
{}
|
|
43
|
+
);
|
|
44
|
+
await strapi.db.transaction(async ({ trx }) => {
|
|
45
|
+
const con = strapi.db.getConnection();
|
|
46
|
+
for (const { joinTable, relations } of oldRelations) {
|
|
47
|
+
const newRelations = relations.map((relation) => {
|
|
48
|
+
const column = joinTable.inverseJoinColumn.name;
|
|
49
|
+
const newId = oldEntriesMap[relation[column]];
|
|
50
|
+
return { ...relation, [column]: newId };
|
|
51
|
+
});
|
|
52
|
+
await con.batchInsert(joinTable.name, newRelations).transacting(trx);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
exports.load = load;
|
|
57
|
+
exports.sync = sync;
|
|
58
|
+
//# sourceMappingURL=unidirectional-relations.js.map
|
|
@@ -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": "0.0.0-experimental.
|
|
3
|
+
"version": "0.0.0-experimental.71ed910bd859c7e558bd1c1042eaadb7d26fd22a",
|
|
4
4
|
"description": "Core of Strapi",
|
|
5
5
|
"homepage": "https://strapi.io",
|
|
6
6
|
"bugs": {
|
|
@@ -55,15 +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": "0.0.0-experimental.
|
|
59
|
-
"@strapi/database": "0.0.0-experimental.
|
|
60
|
-
"@strapi/generators": "0.0.0-experimental.
|
|
61
|
-
"@strapi/logger": "0.0.0-experimental.
|
|
58
|
+
"@strapi/admin": "0.0.0-experimental.71ed910bd859c7e558bd1c1042eaadb7d26fd22a",
|
|
59
|
+
"@strapi/database": "0.0.0-experimental.71ed910bd859c7e558bd1c1042eaadb7d26fd22a",
|
|
60
|
+
"@strapi/generators": "0.0.0-experimental.71ed910bd859c7e558bd1c1042eaadb7d26fd22a",
|
|
61
|
+
"@strapi/logger": "0.0.0-experimental.71ed910bd859c7e558bd1c1042eaadb7d26fd22a",
|
|
62
62
|
"@strapi/pack-up": "5.0.0",
|
|
63
|
-
"@strapi/permissions": "0.0.0-experimental.
|
|
64
|
-
"@strapi/types": "0.0.0-experimental.
|
|
65
|
-
"@strapi/typescript-utils": "0.0.0-experimental.
|
|
66
|
-
"@strapi/utils": "0.0.0-experimental.
|
|
63
|
+
"@strapi/permissions": "0.0.0-experimental.71ed910bd859c7e558bd1c1042eaadb7d26fd22a",
|
|
64
|
+
"@strapi/types": "0.0.0-experimental.71ed910bd859c7e558bd1c1042eaadb7d26fd22a",
|
|
65
|
+
"@strapi/typescript-utils": "0.0.0-experimental.71ed910bd859c7e558bd1c1042eaadb7d26fd22a",
|
|
66
|
+
"@strapi/utils": "0.0.0-experimental.71ed910bd859c7e558bd1c1042eaadb7d26fd22a",
|
|
67
67
|
"bcryptjs": "2.4.3",
|
|
68
68
|
"boxen": "5.1.2",
|
|
69
69
|
"chalk": "4.1.2",
|
|
@@ -93,12 +93,13 @@
|
|
|
93
93
|
"koa-static": "5.0.0",
|
|
94
94
|
"lodash": "4.17.21",
|
|
95
95
|
"mime-types": "2.1.35",
|
|
96
|
-
"node-schedule": "2.1.
|
|
96
|
+
"node-schedule": "2.1.1",
|
|
97
97
|
"open": "8.4.0",
|
|
98
98
|
"ora": "5.4.1",
|
|
99
99
|
"package-json": "7.0.0",
|
|
100
100
|
"pkg-up": "3.1.0",
|
|
101
101
|
"qs": "6.11.1",
|
|
102
|
+
"resolve.exports": "2.0.2",
|
|
102
103
|
"semver": "7.5.4",
|
|
103
104
|
"statuses": "2.0.1",
|
|
104
105
|
"typescript": "5.2.2",
|
|
@@ -123,15 +124,15 @@
|
|
|
123
124
|
"@types/lodash": "^4.14.191",
|
|
124
125
|
"@types/mime-types": "2.1.1",
|
|
125
126
|
"@types/node": "18.19.24",
|
|
126
|
-
"@types/node-schedule": "2.1.
|
|
127
|
+
"@types/node-schedule": "2.1.7",
|
|
127
128
|
"@types/statuses": "2.0.1",
|
|
128
|
-
"eslint-config-custom": "0.0.0-experimental.
|
|
129
|
+
"eslint-config-custom": "0.0.0-experimental.71ed910bd859c7e558bd1c1042eaadb7d26fd22a",
|
|
129
130
|
"supertest": "6.3.3",
|
|
130
|
-
"tsconfig": "0.0.0-experimental.
|
|
131
|
+
"tsconfig": "0.0.0-experimental.71ed910bd859c7e558bd1c1042eaadb7d26fd22a"
|
|
131
132
|
},
|
|
132
133
|
"engines": {
|
|
133
134
|
"node": ">=18.0.0 <=20.x.x",
|
|
134
135
|
"npm": ">=6.0.0"
|
|
135
136
|
},
|
|
136
|
-
"gitHead": "
|
|
137
|
+
"gitHead": "71ed910bd859c7e558bd1c1042eaadb7d26fd22a"
|
|
137
138
|
}
|