@strapi/core 0.0.0-experimental.4abe3ba72a976dd31453f1c69d10d4d72ab079af → 0.0.0-experimental.4da52d54a4257f3b2c655670b4528aec55c4b1c9
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/ee/index.d.ts.map +1 -1
- package/dist/ee/index.js +1 -6
- package/dist/ee/index.js.map +1 -1
- package/dist/ee/index.mjs +1 -6
- package/dist/ee/index.mjs.map +1 -1
- package/dist/loaders/plugins/get-enabled-plugins.js +1 -1
- package/dist/loaders/plugins/get-enabled-plugins.js.map +1 -1
- package/dist/loaders/plugins/get-enabled-plugins.mjs +1 -1
- package/dist/loaders/plugins/get-enabled-plugins.mjs.map +1 -1
- package/dist/migrations/database/5.0.0-discard-drafts.d.ts.map +1 -1
- package/dist/migrations/database/5.0.0-discard-drafts.js +1 -13
- package/dist/migrations/database/5.0.0-discard-drafts.js.map +1 -1
- package/dist/migrations/database/5.0.0-discard-drafts.mjs +1 -13
- package/dist/migrations/database/5.0.0-discard-drafts.mjs.map +1 -1
- package/dist/services/cron.js +4 -9
- package/dist/services/cron.js.map +1 -1
- package/dist/services/cron.mjs +4 -9
- package/dist/services/cron.mjs.map +1 -1
- package/dist/services/document-service/common.d.ts +1 -1
- package/dist/services/document-service/common.d.ts.map +1 -1
- package/dist/services/document-service/common.js.map +1 -1
- package/dist/services/document-service/common.mjs.map +1 -1
- package/dist/services/document-service/entries.d.ts +2 -2
- package/dist/services/document-service/entries.d.ts.map +1 -1
- package/dist/services/document-service/entries.js +7 -6
- package/dist/services/document-service/entries.js.map +1 -1
- package/dist/services/document-service/entries.mjs +2 -1
- package/dist/services/document-service/entries.mjs.map +1 -1
- package/dist/services/document-service/index.d.ts +1 -2
- package/dist/services/document-service/index.d.ts.map +1 -1
- package/dist/services/document-service/index.js +2 -3
- package/dist/services/document-service/index.js.map +1 -1
- package/dist/services/document-service/index.mjs +2 -3
- package/dist/services/document-service/index.mjs.map +1 -1
- package/dist/services/document-service/repository.d.ts.map +1 -1
- package/dist/services/document-service/repository.js +6 -21
- package/dist/services/document-service/repository.js.map +1 -1
- package/dist/services/document-service/repository.mjs +6 -21
- package/dist/services/document-service/repository.mjs.map +1 -1
- package/dist/services/document-service/transform/id-map.d.ts.map +1 -1
- package/dist/services/document-service/transform/id-map.js +4 -13
- package/dist/services/document-service/transform/id-map.js.map +1 -1
- package/dist/services/document-service/transform/id-map.mjs +5 -14
- package/dist/services/document-service/transform/id-map.mjs.map +1 -1
- package/dist/services/document-service/utils/unidirectional-relations.d.ts +8 -11
- package/dist/services/document-service/utils/unidirectional-relations.d.ts.map +1 -1
- package/dist/services/document-service/utils/unidirectional-relations.js +16 -27
- package/dist/services/document-service/utils/unidirectional-relations.js.map +1 -1
- package/dist/services/document-service/utils/unidirectional-relations.mjs +17 -28
- package/dist/services/document-service/utils/unidirectional-relations.mjs.map +1 -1
- package/dist/utils/transform-content-types-to-models.d.ts +21 -325
- package/dist/utils/transform-content-types-to-models.d.ts.map +1 -1
- package/package.json +14 -14
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"id-map.js","sources":["../../../../src/services/document-service/transform/id-map.ts"],"sourcesContent":["import { Core, Data
|
|
1
|
+
{"version":3,"file":"id-map.js","sources":["../../../../src/services/document-service/transform/id-map.ts"],"sourcesContent":["import { Core, Data } from '@strapi/types';\nimport { async } from '@strapi/utils';\n\n/**\n * TODO: Find a better way to encode keys than this\n * This converts an object into a string by joining its keys and values,\n * so it can be used as a key in a Map.\n *\n * @example\n * const obj = { a: 1, b: 2 };\n * const key = encodeKey(obj);\n * ^ \"a:::1&&b:::2\"\n */\nconst encodeKey = (obj: any) => {\n // Sort keys to always keep the same order when encoding\n const keys = Object.keys(obj).sort();\n return keys.map((key) => `${key}:::${obj[key]}`).join('&&');\n};\n\ninterface KeyFields {\n uid: string;\n documentId: Data.ID;\n locale?: string | null;\n status?: 'draft' | 'published';\n}\n\nexport interface IdMap {\n loadedIds: Map<string, string>;\n toLoadIds: Map<string, KeyFields>;\n // Make the Keys type to be the params of add\n add(keys: KeyFields): void;\n load(): Promise<void>;\n get(keys: KeyFields): string | undefined;\n clear(): void;\n}\n\n/**\n * Holds a registry of document ids and their corresponding entity ids.\n */\nconst createIdMap = ({ strapi }: { strapi: Core.Strapi }): IdMap => {\n const loadedIds = new Map();\n const toLoadIds = new Map();\n\n return {\n loadedIds,\n toLoadIds,\n /**\n * Register a new document id and its corresponding entity id.\n */\n add(keyFields: KeyFields) {\n const key = encodeKey({ status: 'published', locale: null, ...keyFields });\n\n // If the id is already loaded, do nothing\n if (loadedIds.has(key)) return;\n // If the id is already in the toLoadIds, do nothing\n if (toLoadIds.has(key)) return;\n\n // Add the id to the toLoadIds\n toLoadIds.set(key, keyFields);\n },\n\n /**\n * Load all ids from the registry.\n */\n async load() {\n // Document Id to Entry Id queries are batched by its uid and locale\n // TODO: Add publication state too\n const loadIdValues = Array.from(toLoadIds.values());\n\n // 1. Group ids to query together\n const idsByUidAndLocale = loadIdValues.reduce((acc, { documentId, ...rest }) => {\n const key = encodeKey(rest);\n const ids = acc[key] || { ...rest, documentIds: [] };\n ids.documentIds.push(documentId);\n return { ...acc, [key]: ids };\n }, {});\n\n // 2. Query ids\n await async.map(\n Object.values(idsByUidAndLocale),\n async ({ uid, locale, documentIds, status }: any) => {\n const findParams = {\n select: ['id', 'documentId', 'locale', 'publishedAt'],\n where: {\n documentId: { $in: documentIds },\n locale: locale || null,\n publishedAt: status === 'draft' ? null : { $ne: null },\n },\n } as any;\n\n const result = await strapi?.db?.query(uid).findMany(findParams);\n\n // 3. Store result in loadedIds\n result?.forEach(({ documentId, id, locale, publishedAt }: any) => {\n const key = encodeKey({\n documentId,\n uid,\n locale,\n status: publishedAt ? 'published' : 'draft',\n });\n loadedIds.set(key, id);\n });\n }\n );\n\n // 4. Clear toLoadIds\n toLoadIds.clear();\n },\n\n /**\n * Get the entity id for a given document id.\n */\n get(keys: KeyFields) {\n const key = encodeKey({ status: 'published', locale: null, ...keys });\n return loadedIds.get(key);\n },\n\n /**\n * Clear the registry.\n */\n clear() {\n loadedIds.clear();\n toLoadIds.clear();\n },\n };\n};\n\nexport { createIdMap };\n"],"names":["async","locale"],"mappings":";;;AAaA,MAAM,YAAY,CAAC,QAAa;AAE9B,QAAM,OAAO,OAAO,KAAK,GAAG,EAAE,KAAK;AACnC,SAAO,KAAK,IAAI,CAAC,QAAQ,GAAG,GAAG,MAAM,IAAI,GAAG,CAAC,EAAE,EAAE,KAAK,IAAI;AAC5D;AAsBA,MAAM,cAAc,CAAC,EAAE,aAA6C;AAC5D,QAAA,gCAAgB;AAChB,QAAA,gCAAgB;AAEf,SAAA;AAAA,IACL;AAAA,IACA;AAAA;AAAA;AAAA;AAAA,IAIA,IAAI,WAAsB;AAClB,YAAA,MAAM,UAAU,EAAE,QAAQ,aAAa,QAAQ,MAAM,GAAG,UAAA,CAAW;AAGrE,UAAA,UAAU,IAAI,GAAG;AAAG;AAEpB,UAAA,UAAU,IAAI,GAAG;AAAG;AAGd,gBAAA,IAAI,KAAK,SAAS;AAAA,IAC9B;AAAA;AAAA;AAAA;AAAA,IAKA,MAAM,OAAO;AAGX,YAAM,eAAe,MAAM,KAAK,UAAU,OAAQ,CAAA;AAG5C,YAAA,oBAAoB,aAAa,OAAO,CAAC,KAAK,EAAE,YAAY,GAAG,WAAW;AACxE,cAAA,MAAM,UAAU,IAAI;AACpB,cAAA,MAAM,IAAI,GAAG,KAAK,EAAE,GAAG,MAAM,aAAa,CAAA;AAC5C,YAAA,YAAY,KAAK,UAAU;AAC/B,eAAO,EAAE,GAAG,KAAK,CAAC,GAAG,GAAG,IAAI;AAAA,MAC9B,GAAG,CAAE,CAAA;AAGL,YAAMA,YAAM,MAAA;AAAA,QACV,OAAO,OAAO,iBAAiB;AAAA,QAC/B,OAAO,EAAE,KAAK,QAAQ,aAAa,aAAkB;AACnD,gBAAM,aAAa;AAAA,YACjB,QAAQ,CAAC,MAAM,cAAc,UAAU,aAAa;AAAA,YACpD,OAAO;AAAA,cACL,YAAY,EAAE,KAAK,YAAY;AAAA,cAC/B,QAAQ,UAAU;AAAA,cAClB,aAAa,WAAW,UAAU,OAAO,EAAE,KAAK,KAAK;AAAA,YACvD;AAAA,UAAA;AAGI,gBAAA,SAAS,MAAM,QAAQ,IAAI,MAAM,GAAG,EAAE,SAAS,UAAU;AAGvD,kBAAA,QAAQ,CAAC,EAAE,YAAY,IAAI,QAAAC,SAAQ,kBAAuB;AAChE,kBAAM,MAAM,UAAU;AAAA,cACpB;AAAA,cACA;AAAA,cACA,QAAAA;AAAAA,cACA,QAAQ,cAAc,cAAc;AAAA,YAAA,CACrC;AACS,sBAAA,IAAI,KAAK,EAAE;AAAA,UAAA,CACtB;AAAA,QACH;AAAA,MAAA;AAIF,gBAAU,MAAM;AAAA,IAClB;AAAA;AAAA;AAAA;AAAA,IAKA,IAAI,MAAiB;AACb,YAAA,MAAM,UAAU,EAAE,QAAQ,aAAa,QAAQ,MAAM,GAAG,KAAA,CAAM;AAC7D,aAAA,UAAU,IAAI,GAAG;AAAA,IAC1B;AAAA;AAAA;AAAA;AAAA,IAKA,QAAQ;AACN,gBAAU,MAAM;AAChB,gBAAU,MAAM;AAAA,IAClB;AAAA,EAAA;AAEJ;;"}
|
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
import { async
|
|
2
|
-
const hasDraftAndPublish = (uid) => {
|
|
3
|
-
const model = strapi.getModel(uid);
|
|
4
|
-
return contentTypes.hasDraftAndPublish(model);
|
|
5
|
-
};
|
|
1
|
+
import { async } from "@strapi/utils";
|
|
6
2
|
const encodeKey = (obj) => {
|
|
7
|
-
if (!hasDraftAndPublish(obj.uid)) {
|
|
8
|
-
delete obj.status;
|
|
9
|
-
}
|
|
10
3
|
const keys = Object.keys(obj).sort();
|
|
11
4
|
return keys.map((key) => `${key}:::${obj[key]}`).join("&&");
|
|
12
5
|
};
|
|
13
|
-
const createIdMap = ({ strapi
|
|
6
|
+
const createIdMap = ({ strapi }) => {
|
|
14
7
|
const loadedIds = /* @__PURE__ */ new Map();
|
|
15
8
|
const toLoadIds = /* @__PURE__ */ new Map();
|
|
16
9
|
return {
|
|
@@ -45,13 +38,11 @@ const createIdMap = ({ strapi: strapi2 }) => {
|
|
|
45
38
|
select: ["id", "documentId", "locale", "publishedAt"],
|
|
46
39
|
where: {
|
|
47
40
|
documentId: { $in: documentIds },
|
|
48
|
-
locale: locale || null
|
|
41
|
+
locale: locale || null,
|
|
42
|
+
publishedAt: status === "draft" ? null : { $ne: null }
|
|
49
43
|
}
|
|
50
44
|
};
|
|
51
|
-
|
|
52
|
-
findParams.where.publishedAt = status === "draft" ? null : { $ne: null };
|
|
53
|
-
}
|
|
54
|
-
const result = await strapi2?.db?.query(uid).findMany(findParams);
|
|
45
|
+
const result = await strapi?.db?.query(uid).findMany(findParams);
|
|
55
46
|
result?.forEach(({ documentId, id, locale: locale2, publishedAt }) => {
|
|
56
47
|
const key = encodeKey({
|
|
57
48
|
documentId,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"id-map.mjs","sources":["../../../../src/services/document-service/transform/id-map.ts"],"sourcesContent":["import { Core, Data
|
|
1
|
+
{"version":3,"file":"id-map.mjs","sources":["../../../../src/services/document-service/transform/id-map.ts"],"sourcesContent":["import { Core, Data } from '@strapi/types';\nimport { async } from '@strapi/utils';\n\n/**\n * TODO: Find a better way to encode keys than this\n * This converts an object into a string by joining its keys and values,\n * so it can be used as a key in a Map.\n *\n * @example\n * const obj = { a: 1, b: 2 };\n * const key = encodeKey(obj);\n * ^ \"a:::1&&b:::2\"\n */\nconst encodeKey = (obj: any) => {\n // Sort keys to always keep the same order when encoding\n const keys = Object.keys(obj).sort();\n return keys.map((key) => `${key}:::${obj[key]}`).join('&&');\n};\n\ninterface KeyFields {\n uid: string;\n documentId: Data.ID;\n locale?: string | null;\n status?: 'draft' | 'published';\n}\n\nexport interface IdMap {\n loadedIds: Map<string, string>;\n toLoadIds: Map<string, KeyFields>;\n // Make the Keys type to be the params of add\n add(keys: KeyFields): void;\n load(): Promise<void>;\n get(keys: KeyFields): string | undefined;\n clear(): void;\n}\n\n/**\n * Holds a registry of document ids and their corresponding entity ids.\n */\nconst createIdMap = ({ strapi }: { strapi: Core.Strapi }): IdMap => {\n const loadedIds = new Map();\n const toLoadIds = new Map();\n\n return {\n loadedIds,\n toLoadIds,\n /**\n * Register a new document id and its corresponding entity id.\n */\n add(keyFields: KeyFields) {\n const key = encodeKey({ status: 'published', locale: null, ...keyFields });\n\n // If the id is already loaded, do nothing\n if (loadedIds.has(key)) return;\n // If the id is already in the toLoadIds, do nothing\n if (toLoadIds.has(key)) return;\n\n // Add the id to the toLoadIds\n toLoadIds.set(key, keyFields);\n },\n\n /**\n * Load all ids from the registry.\n */\n async load() {\n // Document Id to Entry Id queries are batched by its uid and locale\n // TODO: Add publication state too\n const loadIdValues = Array.from(toLoadIds.values());\n\n // 1. Group ids to query together\n const idsByUidAndLocale = loadIdValues.reduce((acc, { documentId, ...rest }) => {\n const key = encodeKey(rest);\n const ids = acc[key] || { ...rest, documentIds: [] };\n ids.documentIds.push(documentId);\n return { ...acc, [key]: ids };\n }, {});\n\n // 2. Query ids\n await async.map(\n Object.values(idsByUidAndLocale),\n async ({ uid, locale, documentIds, status }: any) => {\n const findParams = {\n select: ['id', 'documentId', 'locale', 'publishedAt'],\n where: {\n documentId: { $in: documentIds },\n locale: locale || null,\n publishedAt: status === 'draft' ? null : { $ne: null },\n },\n } as any;\n\n const result = await strapi?.db?.query(uid).findMany(findParams);\n\n // 3. Store result in loadedIds\n result?.forEach(({ documentId, id, locale, publishedAt }: any) => {\n const key = encodeKey({\n documentId,\n uid,\n locale,\n status: publishedAt ? 'published' : 'draft',\n });\n loadedIds.set(key, id);\n });\n }\n );\n\n // 4. Clear toLoadIds\n toLoadIds.clear();\n },\n\n /**\n * Get the entity id for a given document id.\n */\n get(keys: KeyFields) {\n const key = encodeKey({ status: 'published', locale: null, ...keys });\n return loadedIds.get(key);\n },\n\n /**\n * Clear the registry.\n */\n clear() {\n loadedIds.clear();\n toLoadIds.clear();\n },\n };\n};\n\nexport { createIdMap };\n"],"names":["locale"],"mappings":";AAaA,MAAM,YAAY,CAAC,QAAa;AAE9B,QAAM,OAAO,OAAO,KAAK,GAAG,EAAE,KAAK;AACnC,SAAO,KAAK,IAAI,CAAC,QAAQ,GAAG,GAAG,MAAM,IAAI,GAAG,CAAC,EAAE,EAAE,KAAK,IAAI;AAC5D;AAsBA,MAAM,cAAc,CAAC,EAAE,aAA6C;AAC5D,QAAA,gCAAgB;AAChB,QAAA,gCAAgB;AAEf,SAAA;AAAA,IACL;AAAA,IACA;AAAA;AAAA;AAAA;AAAA,IAIA,IAAI,WAAsB;AAClB,YAAA,MAAM,UAAU,EAAE,QAAQ,aAAa,QAAQ,MAAM,GAAG,UAAA,CAAW;AAGrE,UAAA,UAAU,IAAI,GAAG;AAAG;AAEpB,UAAA,UAAU,IAAI,GAAG;AAAG;AAGd,gBAAA,IAAI,KAAK,SAAS;AAAA,IAC9B;AAAA;AAAA;AAAA;AAAA,IAKA,MAAM,OAAO;AAGX,YAAM,eAAe,MAAM,KAAK,UAAU,OAAQ,CAAA;AAG5C,YAAA,oBAAoB,aAAa,OAAO,CAAC,KAAK,EAAE,YAAY,GAAG,WAAW;AACxE,cAAA,MAAM,UAAU,IAAI;AACpB,cAAA,MAAM,IAAI,GAAG,KAAK,EAAE,GAAG,MAAM,aAAa,CAAA;AAC5C,YAAA,YAAY,KAAK,UAAU;AAC/B,eAAO,EAAE,GAAG,KAAK,CAAC,GAAG,GAAG,IAAI;AAAA,MAC9B,GAAG,CAAE,CAAA;AAGL,YAAM,MAAM;AAAA,QACV,OAAO,OAAO,iBAAiB;AAAA,QAC/B,OAAO,EAAE,KAAK,QAAQ,aAAa,aAAkB;AACnD,gBAAM,aAAa;AAAA,YACjB,QAAQ,CAAC,MAAM,cAAc,UAAU,aAAa;AAAA,YACpD,OAAO;AAAA,cACL,YAAY,EAAE,KAAK,YAAY;AAAA,cAC/B,QAAQ,UAAU;AAAA,cAClB,aAAa,WAAW,UAAU,OAAO,EAAE,KAAK,KAAK;AAAA,YACvD;AAAA,UAAA;AAGI,gBAAA,SAAS,MAAM,QAAQ,IAAI,MAAM,GAAG,EAAE,SAAS,UAAU;AAGvD,kBAAA,QAAQ,CAAC,EAAE,YAAY,IAAI,QAAAA,SAAQ,kBAAuB;AAChE,kBAAM,MAAM,UAAU;AAAA,cACpB;AAAA,cACA;AAAA,cACA,QAAAA;AAAAA,cACA,QAAQ,cAAc,cAAc;AAAA,YAAA,CACrC;AACS,sBAAA,IAAI,KAAK,EAAE;AAAA,UAAA,CACtB;AAAA,QACH;AAAA,MAAA;AAIF,gBAAU,MAAM;AAAA,IAClB;AAAA;AAAA;AAAA;AAAA,IAKA,IAAI,MAAiB;AACb,YAAA,MAAM,UAAU,EAAE,QAAQ,aAAa,QAAQ,MAAM,GAAG,KAAA,CAAM;AAC7D,aAAA,UAAU,IAAI,GAAG;AAAA,IAC1B;AAAA;AAAA;AAAA;AAAA,IAKA,QAAQ;AACN,gBAAU,MAAM;AAChB,gBAAU,MAAM;AAAA,IAClB;AAAA,EAAA;AAEJ;"}
|
|
@@ -1,20 +1,17 @@
|
|
|
1
1
|
import { UID } from '@strapi/types';
|
|
2
|
-
interface LoadContext {
|
|
3
|
-
oldVersions: {
|
|
4
|
-
id: string;
|
|
5
|
-
locale: string;
|
|
6
|
-
}[];
|
|
7
|
-
newVersions: {
|
|
8
|
-
id: string;
|
|
9
|
-
locale: string;
|
|
10
|
-
}[];
|
|
11
|
-
}
|
|
12
2
|
/**
|
|
13
3
|
* Loads lingering relations that need to be updated when overriding a published or draft entry.
|
|
14
4
|
* This is necessary because the relations are uni-directional and the target entry is not aware of the source entry.
|
|
15
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.
|
|
16
10
|
*/
|
|
17
|
-
declare const load: (uid: UID.ContentType,
|
|
11
|
+
declare const load: (uid: UID.ContentType, oldEntries: {
|
|
12
|
+
id: string;
|
|
13
|
+
locale: string;
|
|
14
|
+
}[]) => Promise<any>;
|
|
18
15
|
/**
|
|
19
16
|
* Updates uni directional relations to target the right entries when overriding published or draft entries.
|
|
20
17
|
*
|
|
@@ -1 +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
|
|
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"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const fp = require("lodash/fp");
|
|
4
|
-
const load = async (uid,
|
|
4
|
+
const load = async (uid, oldEntries) => {
|
|
5
5
|
const updates = [];
|
|
6
6
|
await strapi.db.transaction(async ({ trx }) => {
|
|
7
7
|
const contentTypes = Object.values(strapi.contentTypes);
|
|
@@ -9,33 +9,21 @@ const load = async (uid, { oldVersions, newVersions }) => {
|
|
|
9
9
|
for (const model of [...contentTypes, ...components]) {
|
|
10
10
|
const dbModel = strapi.db.metadata.get(model.uid);
|
|
11
11
|
for (const attribute of Object.values(dbModel.attributes)) {
|
|
12
|
-
if (attribute.type !== "relation"
|
|
12
|
+
if (attribute.type !== "relation")
|
|
13
|
+
continue;
|
|
14
|
+
if (attribute.target !== uid)
|
|
15
|
+
continue;
|
|
16
|
+
if (attribute.inversedBy || attribute.mappedBy)
|
|
13
17
|
continue;
|
|
14
|
-
}
|
|
15
18
|
const joinTable = attribute.joinTable;
|
|
16
|
-
if (!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)
|
|
17
25
|
continue;
|
|
18
|
-
}
|
|
19
|
-
const { name: sourceColumnName } = joinTable.joinColumn;
|
|
20
|
-
const { name: targetColumnName } = joinTable.inverseJoinColumn;
|
|
21
|
-
const ids = oldVersions.map((entry) => entry.id);
|
|
22
|
-
const oldVersionsRelations = await strapi.db.getConnection().select("*").from(joinTable.name).whereIn(targetColumnName, ids).transacting(trx);
|
|
23
|
-
if (oldVersionsRelations.length > 0) {
|
|
24
|
-
updates.push({ joinTable, relations: oldVersionsRelations });
|
|
25
|
-
}
|
|
26
|
-
if (!model.options?.draftAndPublish) {
|
|
27
|
-
const ids2 = newVersions.map((entry) => entry.id);
|
|
28
|
-
const newVersionsRelations = await strapi.db.getConnection().select("*").from(joinTable.name).whereIn(targetColumnName, ids2).transacting(trx);
|
|
29
|
-
if (newVersionsRelations.length > 0) {
|
|
30
|
-
const discardToAdd = newVersionsRelations.filter((relation) => {
|
|
31
|
-
const matchingOldVerion = oldVersionsRelations.find((oldRelation) => {
|
|
32
|
-
return oldRelation[sourceColumnName] === relation[sourceColumnName];
|
|
33
|
-
});
|
|
34
|
-
return !matchingOldVerion;
|
|
35
|
-
}).map(fp.omit("id"));
|
|
36
|
-
updates.push({ joinTable, relations: discardToAdd });
|
|
37
|
-
}
|
|
38
|
-
}
|
|
26
|
+
updates.push({ joinTable, relations });
|
|
39
27
|
}
|
|
40
28
|
}
|
|
41
29
|
});
|
|
@@ -54,13 +42,14 @@ const sync = async (oldEntries, newEntries, oldRelations) => {
|
|
|
54
42
|
{}
|
|
55
43
|
);
|
|
56
44
|
await strapi.db.transaction(async ({ trx }) => {
|
|
45
|
+
const con = strapi.db.getConnection();
|
|
57
46
|
for (const { joinTable, relations } of oldRelations) {
|
|
58
|
-
const column = joinTable.inverseJoinColumn.name;
|
|
59
47
|
const newRelations = relations.map((relation) => {
|
|
48
|
+
const column = joinTable.inverseJoinColumn.name;
|
|
60
49
|
const newId = oldEntriesMap[relation[column]];
|
|
61
50
|
return { ...relation, [column]: newId };
|
|
62
51
|
});
|
|
63
|
-
await
|
|
52
|
+
await con.batchInsert(joinTable.name, newRelations).transacting(trx);
|
|
64
53
|
}
|
|
65
54
|
});
|
|
66
55
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unidirectional-relations.js","sources":["../../../../src/services/document-service/utils/unidirectional-relations.ts"],"sourcesContent":["/* eslint-disable no-continue */\nimport { keyBy
|
|
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;;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
const load = async (uid,
|
|
1
|
+
import { keyBy } from "lodash/fp";
|
|
2
|
+
const load = async (uid, oldEntries) => {
|
|
3
3
|
const updates = [];
|
|
4
4
|
await strapi.db.transaction(async ({ trx }) => {
|
|
5
5
|
const contentTypes = Object.values(strapi.contentTypes);
|
|
@@ -7,33 +7,21 @@ const load = async (uid, { oldVersions, newVersions }) => {
|
|
|
7
7
|
for (const model of [...contentTypes, ...components]) {
|
|
8
8
|
const dbModel = strapi.db.metadata.get(model.uid);
|
|
9
9
|
for (const attribute of Object.values(dbModel.attributes)) {
|
|
10
|
-
if (attribute.type !== "relation"
|
|
10
|
+
if (attribute.type !== "relation")
|
|
11
|
+
continue;
|
|
12
|
+
if (attribute.target !== uid)
|
|
13
|
+
continue;
|
|
14
|
+
if (attribute.inversedBy || attribute.mappedBy)
|
|
11
15
|
continue;
|
|
12
|
-
}
|
|
13
16
|
const joinTable = attribute.joinTable;
|
|
14
|
-
if (!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)
|
|
15
23
|
continue;
|
|
16
|
-
}
|
|
17
|
-
const { name: sourceColumnName } = joinTable.joinColumn;
|
|
18
|
-
const { name: targetColumnName } = joinTable.inverseJoinColumn;
|
|
19
|
-
const ids = oldVersions.map((entry) => entry.id);
|
|
20
|
-
const oldVersionsRelations = await strapi.db.getConnection().select("*").from(joinTable.name).whereIn(targetColumnName, ids).transacting(trx);
|
|
21
|
-
if (oldVersionsRelations.length > 0) {
|
|
22
|
-
updates.push({ joinTable, relations: oldVersionsRelations });
|
|
23
|
-
}
|
|
24
|
-
if (!model.options?.draftAndPublish) {
|
|
25
|
-
const ids2 = newVersions.map((entry) => entry.id);
|
|
26
|
-
const newVersionsRelations = await strapi.db.getConnection().select("*").from(joinTable.name).whereIn(targetColumnName, ids2).transacting(trx);
|
|
27
|
-
if (newVersionsRelations.length > 0) {
|
|
28
|
-
const discardToAdd = newVersionsRelations.filter((relation) => {
|
|
29
|
-
const matchingOldVerion = oldVersionsRelations.find((oldRelation) => {
|
|
30
|
-
return oldRelation[sourceColumnName] === relation[sourceColumnName];
|
|
31
|
-
});
|
|
32
|
-
return !matchingOldVerion;
|
|
33
|
-
}).map(omit("id"));
|
|
34
|
-
updates.push({ joinTable, relations: discardToAdd });
|
|
35
|
-
}
|
|
36
|
-
}
|
|
24
|
+
updates.push({ joinTable, relations });
|
|
37
25
|
}
|
|
38
26
|
}
|
|
39
27
|
});
|
|
@@ -52,13 +40,14 @@ const sync = async (oldEntries, newEntries, oldRelations) => {
|
|
|
52
40
|
{}
|
|
53
41
|
);
|
|
54
42
|
await strapi.db.transaction(async ({ trx }) => {
|
|
43
|
+
const con = strapi.db.getConnection();
|
|
55
44
|
for (const { joinTable, relations } of oldRelations) {
|
|
56
|
-
const column = joinTable.inverseJoinColumn.name;
|
|
57
45
|
const newRelations = relations.map((relation) => {
|
|
46
|
+
const column = joinTable.inverseJoinColumn.name;
|
|
58
47
|
const newId = oldEntriesMap[relation[column]];
|
|
59
48
|
return { ...relation, [column]: newId };
|
|
60
49
|
});
|
|
61
|
-
await
|
|
50
|
+
await con.batchInsert(joinTable.name, newRelations).transacting(trx);
|
|
62
51
|
}
|
|
63
52
|
});
|
|
64
53
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unidirectional-relations.mjs","sources":["../../../../src/services/document-service/utils/unidirectional-relations.ts"],"sourcesContent":["/* eslint-disable no-continue */\nimport { keyBy
|
|
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;"}
|