@strapi/core 5.0.0-rc.2 → 5.0.0-rc.20
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/Strapi.js +2 -2
- package/dist/Strapi.js.map +1 -1
- package/dist/configuration/get-dirs.js +2 -2
- package/dist/configuration/get-dirs.js.map +1 -1
- package/dist/configuration/index.js +2 -2
- package/dist/configuration/index.js.map +1 -1
- package/dist/core-api/controller/collection-type.js +3 -3
- package/dist/core-api/controller/collection-type.js.map +1 -1
- package/dist/core-api/controller/index.js +2 -2
- package/dist/core-api/controller/index.js.map +1 -1
- package/dist/core-api/controller/single-type.js +2 -2
- package/dist/core-api/controller/single-type.js.map +1 -1
- package/dist/core-api/controller/transform.js +8 -8
- package/dist/core-api/controller/transform.js.map +1 -1
- package/dist/core-api/service/collection-type.d.ts +2 -2
- package/dist/core-api/service/pagination.js +8 -8
- package/dist/core-api/service/pagination.js.map +1 -1
- package/dist/domain/content-type/index.js +4 -4
- package/dist/domain/content-type/index.js.map +1 -1
- package/dist/ee/index.js +3 -3
- package/dist/ee/index.js.map +1 -1
- package/dist/factories.js +4 -4
- package/dist/factories.js.map +1 -1
- package/dist/factories.mjs.map +1 -1
- package/dist/loaders/apis.js +2 -2
- package/dist/loaders/apis.js.map +1 -1
- package/dist/loaders/plugins/get-enabled-plugins.d.ts.map +1 -1
- package/dist/loaders/plugins/get-enabled-plugins.js +39 -11
- package/dist/loaders/plugins/get-enabled-plugins.js.map +1 -1
- package/dist/loaders/plugins/get-enabled-plugins.mjs +9 -3
- package/dist/loaders/plugins/get-enabled-plugins.mjs.map +1 -1
- package/dist/loaders/plugins/get-user-plugins-config.js +2 -2
- package/dist/loaders/plugins/get-user-plugins-config.js.map +1 -1
- package/dist/loaders/plugins/index.d.ts.map +1 -1
- package/dist/loaders/plugins/index.js +34 -7
- 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/body.js +2 -2
- package/dist/middlewares/body.js.map +1 -1
- package/dist/middlewares/public.js +2 -2
- package/dist/middlewares/public.js.map +1 -1
- package/dist/middlewares/query.js.map +1 -1
- package/dist/middlewares/query.mjs.map +1 -1
- package/dist/middlewares/responses.js +2 -2
- package/dist/middlewares/responses.js.map +1 -1
- package/dist/middlewares/security.d.ts.map +1 -1
- package/dist/middlewares/security.js +4 -4
- 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/middlewares/session.js +2 -2
- package/dist/middlewares/session.js.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 +50 -11
- package/dist/migrations/database/5.0.0-discard-drafts.js.map +1 -1
- package/dist/migrations/database/5.0.0-discard-drafts.mjs +51 -12
- package/dist/migrations/database/5.0.0-discard-drafts.mjs.map +1 -1
- 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/registries/apis.js +2 -2
- package/dist/registries/apis.js.map +1 -1
- package/dist/registries/components.js +2 -2
- package/dist/registries/components.js.map +1 -1
- package/dist/registries/content-types.js +3 -3
- package/dist/registries/content-types.js.map +1 -1
- package/dist/registries/controllers.js +3 -3
- package/dist/registries/controllers.js.map +1 -1
- package/dist/registries/custom-fields.js +4 -4
- package/dist/registries/custom-fields.js.map +1 -1
- package/dist/registries/hooks.js +2 -2
- package/dist/registries/hooks.js.map +1 -1
- package/dist/registries/middlewares.js +3 -3
- package/dist/registries/middlewares.js.map +1 -1
- package/dist/registries/modules.js +3 -3
- package/dist/registries/modules.js.map +1 -1
- package/dist/registries/plugins.js +2 -2
- package/dist/registries/plugins.js.map +1 -1
- package/dist/registries/policies.d.ts +1 -1
- package/dist/registries/policies.d.ts.map +1 -1
- package/dist/registries/policies.js +5 -5
- package/dist/registries/policies.js.map +1 -1
- package/dist/registries/policies.mjs +1 -1
- package/dist/registries/policies.mjs.map +1 -1
- package/dist/registries/services.js +3 -3
- package/dist/registries/services.js.map +1 -1
- package/dist/services/auth/index.js +3 -3
- package/dist/services/auth/index.js.map +1 -1
- package/dist/services/content-api/index.d.ts +10 -12
- package/dist/services/content-api/index.d.ts.map +1 -1
- package/dist/services/content-api/permissions/index.d.ts +10 -12
- package/dist/services/content-api/permissions/index.d.ts.map +1 -1
- package/dist/services/content-api/permissions/providers/action.d.ts +5 -6
- package/dist/services/content-api/permissions/providers/action.d.ts.map +1 -1
- package/dist/services/content-api/permissions/providers/condition.d.ts +5 -6
- package/dist/services/content-api/permissions/providers/condition.d.ts.map +1 -1
- package/dist/services/core-store.js +3 -3
- package/dist/services/core-store.js.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 +3 -3
- package/dist/services/cron.js.map +1 -1
- package/dist/services/cron.mjs.map +1 -1
- package/dist/services/document-service/attributes/index.js +2 -2
- package/dist/services/document-service/attributes/index.js.map +1 -1
- package/dist/services/document-service/attributes/transforms.js +3 -3
- package/dist/services/document-service/attributes/transforms.js.map +1 -1
- package/dist/services/document-service/components.js +15 -15
- package/dist/services/document-service/components.js.map +1 -1
- package/dist/services/document-service/draft-and-publish.js +16 -16
- package/dist/services/document-service/draft-and-publish.js.map +1 -1
- package/dist/services/document-service/entries.js +5 -5
- package/dist/services/document-service/entries.js.map +1 -1
- package/dist/services/document-service/internationalization.js +9 -9
- package/dist/services/document-service/internationalization.js.map +1 -1
- package/dist/services/document-service/params.js +2 -2
- package/dist/services/document-service/params.js.map +1 -1
- package/dist/services/document-service/repository.d.ts.map +1 -1
- package/dist/services/document-service/repository.js +51 -15
- 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/transform/id-transform.js +2 -2
- package/dist/services/document-service/transform/id-transform.js.map +1 -1
- package/dist/services/document-service/transform/query.js +3 -3
- package/dist/services/document-service/transform/query.js.map +1 -1
- package/dist/services/document-service/transform/relations/extract/data-ids.js +2 -2
- package/dist/services/document-service/transform/relations/extract/data-ids.js.map +1 -1
- package/dist/services/document-service/transform/relations/transform/data-ids.js +2 -2
- package/dist/services/document-service/transform/relations/transform/data-ids.js.map +1 -1
- package/dist/services/document-service/transform/relations/utils/dp.js +2 -2
- package/dist/services/document-service/transform/relations/utils/dp.js.map +1 -1
- package/dist/services/document-service/transform/relations/utils/map-relation.js +6 -6
- package/dist/services/document-service/transform/relations/utils/map-relation.js.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/dist/services/entity-validator/blocks-validator.d.ts +1 -2
- package/dist/services/entity-validator/blocks-validator.d.ts.map +1 -1
- package/dist/services/entity-validator/blocks-validator.js +4 -3
- package/dist/services/entity-validator/blocks-validator.js.map +1 -1
- package/dist/services/entity-validator/blocks-validator.mjs +3 -3
- package/dist/services/entity-validator/blocks-validator.mjs.map +1 -1
- package/dist/services/entity-validator/index.d.ts +2 -1
- package/dist/services/entity-validator/index.d.ts.map +1 -1
- package/dist/services/entity-validator/index.js +28 -33
- package/dist/services/entity-validator/index.js.map +1 -1
- package/dist/services/entity-validator/index.mjs +14 -19
- package/dist/services/entity-validator/index.mjs.map +1 -1
- package/dist/services/entity-validator/validators.d.ts +32 -23
- package/dist/services/entity-validator/validators.d.ts.map +1 -1
- package/dist/services/entity-validator/validators.js +136 -63
- package/dist/services/entity-validator/validators.js.map +1 -1
- package/dist/services/entity-validator/validators.mjs +135 -63
- package/dist/services/entity-validator/validators.mjs.map +1 -1
- package/dist/services/server/compose-endpoint.js +7 -7
- package/dist/services/server/compose-endpoint.js.map +1 -1
- package/dist/services/server/koa.js +3 -3
- package/dist/services/server/koa.js.map +1 -1
- package/dist/services/server/middleware.js +3 -3
- package/dist/services/server/middleware.js.map +1 -1
- package/dist/services/server/routing.js +2 -2
- package/dist/services/server/routing.js.map +1 -1
- package/dist/services/utils/dynamic-zones.js +5 -5
- package/dist/services/utils/dynamic-zones.js.map +1 -1
- package/dist/utils/cron.js +3 -3
- package/dist/utils/cron.js.map +1 -1
- package/dist/utils/filepath-to-prop-path.d.ts +1 -1
- package/dist/utils/filepath-to-prop-path.d.ts.map +1 -1
- package/dist/utils/filepath-to-prop-path.js +27 -6
- package/dist/utils/filepath-to-prop-path.js.map +1 -1
- package/dist/utils/filepath-to-prop-path.mjs +25 -5
- package/dist/utils/filepath-to-prop-path.mjs.map +1 -1
- package/dist/utils/is-initialized.js +3 -3
- package/dist/utils/is-initialized.js.map +1 -1
- package/dist/utils/startup-logger.js +4 -4
- package/dist/utils/startup-logger.js.map +1 -1
- package/dist/utils/startup-logger.mjs +3 -3
- package/dist/utils/startup-logger.mjs.map +1 -1
- package/dist/utils/transform-content-types-to-models.d.ts +2 -2
- package/dist/utils/transform-content-types-to-models.d.ts.map +1 -1
- package/dist/utils/transform-content-types-to-models.js +6 -5
- package/dist/utils/transform-content-types-to-models.js.map +1 -1
- package/dist/utils/transform-content-types-to-models.mjs +5 -4
- package/dist/utils/transform-content-types-to-models.mjs.map +1 -1
- package/package.json +15 -15
@@ -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,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AAC,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,O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AAc,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,4 +1,3 @@
|
|
1
1
|
import { yup } from '@strapi/utils';
|
2
|
-
declare const
|
3
|
-
export default _default;
|
2
|
+
export declare const blocksValidator: () => yup.ArraySchema<any, import("yup/lib/types").AnyObject, any[] | undefined, any[] | undefined>;
|
4
3
|
//# sourceMappingURL=blocks-validator.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"blocks-validator.d.ts","sourceRoot":"","sources":["../../../src/services/entity-validator/blocks-validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;
|
1
|
+
{"version":3,"file":"blocks-validator.d.ts","sourceRoot":"","sources":["../../../src/services/entity-validator/blocks-validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAwKpC,eAAO,MAAM,eAAe,qGAA8B,CAAC"}
|
@@ -1,4 +1,5 @@
|
|
1
1
|
"use strict";
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
2
3
|
const strapiUtils = require("@strapi/utils");
|
3
4
|
const textNodeValidator = strapiUtils.yup.object().shape({
|
4
5
|
type: strapiUtils.yup.string().equals(["text"]).required(),
|
@@ -121,7 +122,7 @@ const blockNodeValidator = strapiUtils.yup.lazy((value) => {
|
|
121
122
|
});
|
122
123
|
}
|
123
124
|
});
|
124
|
-
const
|
125
|
-
const blocksValidator
|
126
|
-
|
125
|
+
const blocksValidatorSchema = strapiUtils.yup.array().of(blockNodeValidator);
|
126
|
+
const blocksValidator = () => blocksValidatorSchema;
|
127
|
+
exports.blocksValidator = blocksValidator;
|
127
128
|
//# sourceMappingURL=blocks-validator.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"blocks-validator.js","sources":["../../../src/services/entity-validator/blocks-validator.ts"],"sourcesContent":["import { yup } from '@strapi/utils';\n\nconst textNodeValidator = yup.object().shape({\n type: yup.string().equals(['text']).required(),\n text: yup\n .string()\n .test(\n 'is-valid-text',\n 'Text must be defined with at least an empty string',\n (text: unknown) => {\n return typeof text === 'string' || text === '';\n }\n ),\n bold: yup.boolean(),\n italic: yup.boolean(),\n underline: yup.boolean(),\n strikethrough: yup.boolean(),\n code: yup.boolean(),\n});\n\nconst checkValidLink = (link: string) => {\n try {\n // eslint-disable-next-line no-new\n new URL(link.startsWith('/') ? `https://strapi.io${link}` : link);\n } catch (error) {\n return false;\n }\n return true;\n};\n\nconst linkNodeValidator = yup.object().shape({\n type: yup.string().equals(['link']).required(),\n url: yup\n .string()\n .test('invalid-url', 'Please specify a valid link.', (value) => checkValidLink(value ?? '')),\n children: yup.array().of(textNodeValidator).required(),\n});\n\n// TODO: remove any with a correct Type\nconst inlineNodeValidator: any = yup.lazy((value: { type: string }) => {\n switch (value.type) {\n case 'text':\n return textNodeValidator;\n case 'link':\n return linkNodeValidator;\n default:\n return yup.mixed().test('invalid-type', 'Inline node must be Text or Link', () => {\n return false;\n });\n }\n});\n\nconst paragraphNodeValidator = yup.object().shape({\n type: yup.string().equals(['paragraph']).required(),\n children: yup\n .array()\n .of(inlineNodeValidator)\n .min(1, 'Paragraph node children must have at least one Text or Link node')\n .required(),\n});\n\nconst headingNodeValidator = yup.object().shape({\n type: yup.string().equals(['heading']).required(),\n level: yup.number().oneOf([1, 2, 3, 4, 5, 6]).required(),\n children: yup\n .array()\n .of(inlineNodeValidator)\n .min(1, 'Heading node children must have at least one Text or Link node')\n .required(),\n});\n\nconst quoteNodeValidator = yup.object().shape({\n type: yup.string().equals(['quote']).required(),\n children: yup\n .array()\n .of(inlineNodeValidator)\n .min(1, 'Quote node children must have at least one Text or Link node')\n .required(),\n});\n\nconst codeBlockValidator = yup.object().shape({\n type: yup.string().equals(['code']).required(),\n syntax: yup.string().nullable(),\n children: yup\n .array()\n .of(textNodeValidator)\n .min(1, 'Quote node children must have at least one Text or Link node')\n .required(),\n});\n\nconst listItemNode = yup.object().shape({\n type: yup.string().equals(['list-item']).required(),\n children: yup.array().of(inlineNodeValidator).required(),\n});\n\n// Allow children to be either a listItemNode or a listNode itself\n// @ts-expect-error - listChildrenValidator needs a type\nconst listChildrenValidator = yup.lazy((value: { type: string }) => {\n switch (value.type) {\n case 'list':\n return listNodeValidator;\n case 'list-item':\n return listItemNode;\n default:\n return yup.mixed().test('invalid-type', 'Inline node must be list-item or list', () => {\n return false;\n });\n }\n});\n\n// @ts-expect-error - listNodeValidator needs a type\nconst listNodeValidator = yup.object().shape({\n type: yup.string().equals(['list']).required(),\n format: yup.string().equals(['ordered', 'unordered']).required(),\n children: yup\n .array()\n .of(listChildrenValidator)\n .min(1, 'List node children must have at least one ListItem or ListNode')\n .required(),\n});\n\nconst imageNodeValidator = yup.object().shape({\n type: yup.string().equals(['image']).required(),\n image: yup.object().shape({\n name: yup.string().required(),\n alternativeText: yup.string().nullable(),\n url: yup.string().required(),\n caption: yup.string().nullable(),\n width: yup.number().required(),\n height: yup.number().required(),\n formats: yup.object().required(),\n hash: yup.string().required(),\n ext: yup.string().required(),\n mime: yup.string().required(),\n size: yup.number().required(),\n previewUrl: yup.string().nullable(),\n provider: yup.string().required(),\n provider_metadata: yup.mixed().nullable(),\n createdAt: yup.string().required(),\n updatedAt: yup.string().required(),\n }),\n children: yup.array().of(inlineNodeValidator).required(),\n});\n\n// TODO: remove the any and replace with a correct Type\nconst blockNodeValidator: any = yup.lazy((value: { type: string }) => {\n switch (value.type) {\n case 'paragraph':\n return paragraphNodeValidator;\n case 'heading':\n return headingNodeValidator;\n case 'quote':\n return quoteNodeValidator;\n case 'list':\n return listNodeValidator;\n case 'image':\n return imageNodeValidator;\n case 'code':\n return codeBlockValidator;\n default:\n return yup.mixed().test('invalid-type', 'Block node is of invalid type', () => {\n return false;\n });\n }\n});\n\nconst
|
1
|
+
{"version":3,"file":"blocks-validator.js","sources":["../../../src/services/entity-validator/blocks-validator.ts"],"sourcesContent":["import { yup } from '@strapi/utils';\n\nconst textNodeValidator = yup.object().shape({\n type: yup.string().equals(['text']).required(),\n text: yup\n .string()\n .test(\n 'is-valid-text',\n 'Text must be defined with at least an empty string',\n (text: unknown) => {\n return typeof text === 'string' || text === '';\n }\n ),\n bold: yup.boolean(),\n italic: yup.boolean(),\n underline: yup.boolean(),\n strikethrough: yup.boolean(),\n code: yup.boolean(),\n});\n\nconst checkValidLink = (link: string) => {\n try {\n // eslint-disable-next-line no-new\n new URL(link.startsWith('/') ? `https://strapi.io${link}` : link);\n } catch (error) {\n return false;\n }\n return true;\n};\n\nconst linkNodeValidator = yup.object().shape({\n type: yup.string().equals(['link']).required(),\n url: yup\n .string()\n .test('invalid-url', 'Please specify a valid link.', (value) => checkValidLink(value ?? '')),\n children: yup.array().of(textNodeValidator).required(),\n});\n\n// TODO: remove any with a correct Type\nconst inlineNodeValidator: any = yup.lazy((value: { type: string }) => {\n switch (value.type) {\n case 'text':\n return textNodeValidator;\n case 'link':\n return linkNodeValidator;\n default:\n return yup.mixed().test('invalid-type', 'Inline node must be Text or Link', () => {\n return false;\n });\n }\n});\n\nconst paragraphNodeValidator = yup.object().shape({\n type: yup.string().equals(['paragraph']).required(),\n children: yup\n .array()\n .of(inlineNodeValidator)\n .min(1, 'Paragraph node children must have at least one Text or Link node')\n .required(),\n});\n\nconst headingNodeValidator = yup.object().shape({\n type: yup.string().equals(['heading']).required(),\n level: yup.number().oneOf([1, 2, 3, 4, 5, 6]).required(),\n children: yup\n .array()\n .of(inlineNodeValidator)\n .min(1, 'Heading node children must have at least one Text or Link node')\n .required(),\n});\n\nconst quoteNodeValidator = yup.object().shape({\n type: yup.string().equals(['quote']).required(),\n children: yup\n .array()\n .of(inlineNodeValidator)\n .min(1, 'Quote node children must have at least one Text or Link node')\n .required(),\n});\n\nconst codeBlockValidator = yup.object().shape({\n type: yup.string().equals(['code']).required(),\n syntax: yup.string().nullable(),\n children: yup\n .array()\n .of(textNodeValidator)\n .min(1, 'Quote node children must have at least one Text or Link node')\n .required(),\n});\n\nconst listItemNode = yup.object().shape({\n type: yup.string().equals(['list-item']).required(),\n children: yup.array().of(inlineNodeValidator).required(),\n});\n\n// Allow children to be either a listItemNode or a listNode itself\n// @ts-expect-error - listChildrenValidator needs a type\nconst listChildrenValidator = yup.lazy((value: { type: string }) => {\n switch (value.type) {\n case 'list':\n return listNodeValidator;\n case 'list-item':\n return listItemNode;\n default:\n return yup.mixed().test('invalid-type', 'Inline node must be list-item or list', () => {\n return false;\n });\n }\n});\n\n// @ts-expect-error - listNodeValidator needs a type\nconst listNodeValidator = yup.object().shape({\n type: yup.string().equals(['list']).required(),\n format: yup.string().equals(['ordered', 'unordered']).required(),\n children: yup\n .array()\n .of(listChildrenValidator)\n .min(1, 'List node children must have at least one ListItem or ListNode')\n .required(),\n});\n\nconst imageNodeValidator = yup.object().shape({\n type: yup.string().equals(['image']).required(),\n image: yup.object().shape({\n name: yup.string().required(),\n alternativeText: yup.string().nullable(),\n url: yup.string().required(),\n caption: yup.string().nullable(),\n width: yup.number().required(),\n height: yup.number().required(),\n formats: yup.object().required(),\n hash: yup.string().required(),\n ext: yup.string().required(),\n mime: yup.string().required(),\n size: yup.number().required(),\n previewUrl: yup.string().nullable(),\n provider: yup.string().required(),\n provider_metadata: yup.mixed().nullable(),\n createdAt: yup.string().required(),\n updatedAt: yup.string().required(),\n }),\n children: yup.array().of(inlineNodeValidator).required(),\n});\n\n// TODO: remove the any and replace with a correct Type\nconst blockNodeValidator: any = yup.lazy((value: { type: string }) => {\n switch (value.type) {\n case 'paragraph':\n return paragraphNodeValidator;\n case 'heading':\n return headingNodeValidator;\n case 'quote':\n return quoteNodeValidator;\n case 'list':\n return listNodeValidator;\n case 'image':\n return imageNodeValidator;\n case 'code':\n return codeBlockValidator;\n default:\n return yup.mixed().test('invalid-type', 'Block node is of invalid type', () => {\n return false;\n });\n }\n});\n\nconst blocksValidatorSchema = yup.array().of(blockNodeValidator);\n\nexport const blocksValidator = () => blocksValidatorSchema;\n"],"names":["yup"],"mappings":";;;AAEA,MAAM,oBAAoBA,YAAA,IAAI,OAAO,EAAE,MAAM;AAAA,EAC3C,MAAMA,gBAAI,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,SAAS;AAAA,EAC7C,MAAMA,YAAAA,IACH,OAAA,EACA;AAAA,IACC;AAAA,IACA;AAAA,IACA,CAAC,SAAkB;AACV,aAAA,OAAO,SAAS,YAAY,SAAS;AAAA,IAC9C;AAAA,EACF;AAAA,EACF,MAAMA,gBAAI,QAAQ;AAAA,EAClB,QAAQA,gBAAI,QAAQ;AAAA,EACpB,WAAWA,gBAAI,QAAQ;AAAA,EACvB,eAAeA,gBAAI,QAAQ;AAAA,EAC3B,MAAMA,gBAAI,QAAQ;AACpB,CAAC;AAED,MAAM,iBAAiB,CAAC,SAAiB;AACnC,MAAA;AAEE,QAAA,IAAI,KAAK,WAAW,GAAG,IAAI,oBAAoB,IAAI,KAAK,IAAI;AAAA,WACzD,OAAO;AACP,WAAA;AAAA,EACT;AACO,SAAA;AACT;AAEA,MAAM,oBAAoBA,YAAA,IAAI,OAAO,EAAE,MAAM;AAAA,EAC3C,MAAMA,gBAAI,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,SAAS;AAAA,EAC7C,KAAKA,YAAA,IACF,OAAO,EACP,KAAK,eAAe,gCAAgC,CAAC,UAAU,eAAe,SAAS,EAAE,CAAC;AAAA,EAC7F,UAAUA,YAAI,IAAA,MAAA,EAAQ,GAAG,iBAAiB,EAAE,SAAS;AACvD,CAAC;AAGD,MAAM,sBAA2BA,YAAA,IAAI,KAAK,CAAC,UAA4B;AACrE,UAAQ,MAAM,MAAM;AAAA,IAClB,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAAA;AAAA,IACT;AAC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AC9B,SAASA,YAAA,IAAI,OAAO,EAAE,SAAS;AAAA,IAC/B,MAAMA,YAAA,IAAI,OAAO,EAAE,SAAS;AAAA,IAC5B,KAAKA,YAAA,IAAI,OAAO,EAAE,SAAS;AAAA,IAC3B,MAAMA,YAAA,IAAI,OAAO,EAAE,SAAS;AAAA,IAC5B,MAAMA,YAAA,IAAI,OAAO,EAAE,SAAS;AAAA,IAC5B,YAAYA,YAAA,IAAI,OAAO,EAAE,SAAS;AAAA,IAClC,UAAUA,YAAA,IAAI,OAAO,EAAE,SAAS;AAAA,IAChC,mBAAmBA,YAAA,IAAI,MAAM,EAAE,SAAS;AAAA,IACxC,WAAWA,YAAA,IAAI,OAAO,EAAE,SAAS;AAAA,IACjC,WAAWA,YAAA,IAAI,OAAO,EAAE,SAAS;AAAA,EAAA,CAClC;AAAA,EACD,UAAUA,YAAI,IAAA,MAAA,EAAQ,GAAG,mBAAmB,EAAE,SAAS;AACzD,CAAC;AAGD,MAAM,qBAA0BA,YAAA,IAAI,KAAK,CAAC,UAA4B;AACpE,UAAQ,MAAM,MAAM;AAAA,IAClB,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAAA;AAAA,IACT;AACE,aAAOA,YAAAA,IAAI,MAAM,EAAE,KAAK,gBAAgB,iCAAiC,MAAM;AACtE,eAAA;AAAA,MAAA,CACR;AAAA,EACL;AACF,CAAC;AAED,MAAM,wBAAwBA,YAAAA,IAAI,MAAM,EAAE,GAAG,kBAAkB;AAExD,MAAM,kBAAkB,MAAM;;"}
|
@@ -120,9 +120,9 @@ const blockNodeValidator = yup.lazy((value) => {
|
|
120
120
|
});
|
121
121
|
}
|
122
122
|
});
|
123
|
-
const
|
124
|
-
const blocksValidator
|
123
|
+
const blocksValidatorSchema = yup.array().of(blockNodeValidator);
|
124
|
+
const blocksValidator = () => blocksValidatorSchema;
|
125
125
|
export {
|
126
|
-
blocksValidator
|
126
|
+
blocksValidator
|
127
127
|
};
|
128
128
|
//# sourceMappingURL=blocks-validator.mjs.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"blocks-validator.mjs","sources":["../../../src/services/entity-validator/blocks-validator.ts"],"sourcesContent":["import { yup } from '@strapi/utils';\n\nconst textNodeValidator = yup.object().shape({\n type: yup.string().equals(['text']).required(),\n text: yup\n .string()\n .test(\n 'is-valid-text',\n 'Text must be defined with at least an empty string',\n (text: unknown) => {\n return typeof text === 'string' || text === '';\n }\n ),\n bold: yup.boolean(),\n italic: yup.boolean(),\n underline: yup.boolean(),\n strikethrough: yup.boolean(),\n code: yup.boolean(),\n});\n\nconst checkValidLink = (link: string) => {\n try {\n // eslint-disable-next-line no-new\n new URL(link.startsWith('/') ? `https://strapi.io${link}` : link);\n } catch (error) {\n return false;\n }\n return true;\n};\n\nconst linkNodeValidator = yup.object().shape({\n type: yup.string().equals(['link']).required(),\n url: yup\n .string()\n .test('invalid-url', 'Please specify a valid link.', (value) => checkValidLink(value ?? '')),\n children: yup.array().of(textNodeValidator).required(),\n});\n\n// TODO: remove any with a correct Type\nconst inlineNodeValidator: any = yup.lazy((value: { type: string }) => {\n switch (value.type) {\n case 'text':\n return textNodeValidator;\n case 'link':\n return linkNodeValidator;\n default:\n return yup.mixed().test('invalid-type', 'Inline node must be Text or Link', () => {\n return false;\n });\n }\n});\n\nconst paragraphNodeValidator = yup.object().shape({\n type: yup.string().equals(['paragraph']).required(),\n children: yup\n .array()\n .of(inlineNodeValidator)\n .min(1, 'Paragraph node children must have at least one Text or Link node')\n .required(),\n});\n\nconst headingNodeValidator = yup.object().shape({\n type: yup.string().equals(['heading']).required(),\n level: yup.number().oneOf([1, 2, 3, 4, 5, 6]).required(),\n children: yup\n .array()\n .of(inlineNodeValidator)\n .min(1, 'Heading node children must have at least one Text or Link node')\n .required(),\n});\n\nconst quoteNodeValidator = yup.object().shape({\n type: yup.string().equals(['quote']).required(),\n children: yup\n .array()\n .of(inlineNodeValidator)\n .min(1, 'Quote node children must have at least one Text or Link node')\n .required(),\n});\n\nconst codeBlockValidator = yup.object().shape({\n type: yup.string().equals(['code']).required(),\n syntax: yup.string().nullable(),\n children: yup\n .array()\n .of(textNodeValidator)\n .min(1, 'Quote node children must have at least one Text or Link node')\n .required(),\n});\n\nconst listItemNode = yup.object().shape({\n type: yup.string().equals(['list-item']).required(),\n children: yup.array().of(inlineNodeValidator).required(),\n});\n\n// Allow children to be either a listItemNode or a listNode itself\n// @ts-expect-error - listChildrenValidator needs a type\nconst listChildrenValidator = yup.lazy((value: { type: string }) => {\n switch (value.type) {\n case 'list':\n return listNodeValidator;\n case 'list-item':\n return listItemNode;\n default:\n return yup.mixed().test('invalid-type', 'Inline node must be list-item or list', () => {\n return false;\n });\n }\n});\n\n// @ts-expect-error - listNodeValidator needs a type\nconst listNodeValidator = yup.object().shape({\n type: yup.string().equals(['list']).required(),\n format: yup.string().equals(['ordered', 'unordered']).required(),\n children: yup\n .array()\n .of(listChildrenValidator)\n .min(1, 'List node children must have at least one ListItem or ListNode')\n .required(),\n});\n\nconst imageNodeValidator = yup.object().shape({\n type: yup.string().equals(['image']).required(),\n image: yup.object().shape({\n name: yup.string().required(),\n alternativeText: yup.string().nullable(),\n url: yup.string().required(),\n caption: yup.string().nullable(),\n width: yup.number().required(),\n height: yup.number().required(),\n formats: yup.object().required(),\n hash: yup.string().required(),\n ext: yup.string().required(),\n mime: yup.string().required(),\n size: yup.number().required(),\n previewUrl: yup.string().nullable(),\n provider: yup.string().required(),\n provider_metadata: yup.mixed().nullable(),\n createdAt: yup.string().required(),\n updatedAt: yup.string().required(),\n }),\n children: yup.array().of(inlineNodeValidator).required(),\n});\n\n// TODO: remove the any and replace with a correct Type\nconst blockNodeValidator: any = yup.lazy((value: { type: string }) => {\n switch (value.type) {\n case 'paragraph':\n return paragraphNodeValidator;\n case 'heading':\n return headingNodeValidator;\n case 'quote':\n return quoteNodeValidator;\n case 'list':\n return listNodeValidator;\n case 'image':\n return imageNodeValidator;\n case 'code':\n return codeBlockValidator;\n default:\n return yup.mixed().test('invalid-type', 'Block node is of invalid type', () => {\n return false;\n });\n }\n});\n\nconst
|
1
|
+
{"version":3,"file":"blocks-validator.mjs","sources":["../../../src/services/entity-validator/blocks-validator.ts"],"sourcesContent":["import { yup } from '@strapi/utils';\n\nconst textNodeValidator = yup.object().shape({\n type: yup.string().equals(['text']).required(),\n text: yup\n .string()\n .test(\n 'is-valid-text',\n 'Text must be defined with at least an empty string',\n (text: unknown) => {\n return typeof text === 'string' || text === '';\n }\n ),\n bold: yup.boolean(),\n italic: yup.boolean(),\n underline: yup.boolean(),\n strikethrough: yup.boolean(),\n code: yup.boolean(),\n});\n\nconst checkValidLink = (link: string) => {\n try {\n // eslint-disable-next-line no-new\n new URL(link.startsWith('/') ? `https://strapi.io${link}` : link);\n } catch (error) {\n return false;\n }\n return true;\n};\n\nconst linkNodeValidator = yup.object().shape({\n type: yup.string().equals(['link']).required(),\n url: yup\n .string()\n .test('invalid-url', 'Please specify a valid link.', (value) => checkValidLink(value ?? '')),\n children: yup.array().of(textNodeValidator).required(),\n});\n\n// TODO: remove any with a correct Type\nconst inlineNodeValidator: any = yup.lazy((value: { type: string }) => {\n switch (value.type) {\n case 'text':\n return textNodeValidator;\n case 'link':\n return linkNodeValidator;\n default:\n return yup.mixed().test('invalid-type', 'Inline node must be Text or Link', () => {\n return false;\n });\n }\n});\n\nconst paragraphNodeValidator = yup.object().shape({\n type: yup.string().equals(['paragraph']).required(),\n children: yup\n .array()\n .of(inlineNodeValidator)\n .min(1, 'Paragraph node children must have at least one Text or Link node')\n .required(),\n});\n\nconst headingNodeValidator = yup.object().shape({\n type: yup.string().equals(['heading']).required(),\n level: yup.number().oneOf([1, 2, 3, 4, 5, 6]).required(),\n children: yup\n .array()\n .of(inlineNodeValidator)\n .min(1, 'Heading node children must have at least one Text or Link node')\n .required(),\n});\n\nconst quoteNodeValidator = yup.object().shape({\n type: yup.string().equals(['quote']).required(),\n children: yup\n .array()\n .of(inlineNodeValidator)\n .min(1, 'Quote node children must have at least one Text or Link node')\n .required(),\n});\n\nconst codeBlockValidator = yup.object().shape({\n type: yup.string().equals(['code']).required(),\n syntax: yup.string().nullable(),\n children: yup\n .array()\n .of(textNodeValidator)\n .min(1, 'Quote node children must have at least one Text or Link node')\n .required(),\n});\n\nconst listItemNode = yup.object().shape({\n type: yup.string().equals(['list-item']).required(),\n children: yup.array().of(inlineNodeValidator).required(),\n});\n\n// Allow children to be either a listItemNode or a listNode itself\n// @ts-expect-error - listChildrenValidator needs a type\nconst listChildrenValidator = yup.lazy((value: { type: string }) => {\n switch (value.type) {\n case 'list':\n return listNodeValidator;\n case 'list-item':\n return listItemNode;\n default:\n return yup.mixed().test('invalid-type', 'Inline node must be list-item or list', () => {\n return false;\n });\n }\n});\n\n// @ts-expect-error - listNodeValidator needs a type\nconst listNodeValidator = yup.object().shape({\n type: yup.string().equals(['list']).required(),\n format: yup.string().equals(['ordered', 'unordered']).required(),\n children: yup\n .array()\n .of(listChildrenValidator)\n .min(1, 'List node children must have at least one ListItem or ListNode')\n .required(),\n});\n\nconst imageNodeValidator = yup.object().shape({\n type: yup.string().equals(['image']).required(),\n image: yup.object().shape({\n name: yup.string().required(),\n alternativeText: yup.string().nullable(),\n url: yup.string().required(),\n caption: yup.string().nullable(),\n width: yup.number().required(),\n height: yup.number().required(),\n formats: yup.object().required(),\n hash: yup.string().required(),\n ext: yup.string().required(),\n mime: yup.string().required(),\n size: yup.number().required(),\n previewUrl: yup.string().nullable(),\n provider: yup.string().required(),\n provider_metadata: yup.mixed().nullable(),\n createdAt: yup.string().required(),\n updatedAt: yup.string().required(),\n }),\n children: yup.array().of(inlineNodeValidator).required(),\n});\n\n// TODO: remove the any and replace with a correct Type\nconst blockNodeValidator: any = yup.lazy((value: { type: string }) => {\n switch (value.type) {\n case 'paragraph':\n return paragraphNodeValidator;\n case 'heading':\n return headingNodeValidator;\n case 'quote':\n return quoteNodeValidator;\n case 'list':\n return listNodeValidator;\n case 'image':\n return imageNodeValidator;\n case 'code':\n return codeBlockValidator;\n default:\n return yup.mixed().test('invalid-type', 'Block node is of invalid type', () => {\n return false;\n });\n }\n});\n\nconst blocksValidatorSchema = yup.array().of(blockNodeValidator);\n\nexport const blocksValidator = () => blocksValidatorSchema;\n"],"names":[],"mappings":";AAEA,MAAM,oBAAoB,IAAI,OAAO,EAAE,MAAM;AAAA,EAC3C,MAAM,IAAI,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,SAAS;AAAA,EAC7C,MAAM,IACH,OAAA,EACA;AAAA,IACC;AAAA,IACA;AAAA,IACA,CAAC,SAAkB;AACV,aAAA,OAAO,SAAS,YAAY,SAAS;AAAA,IAC9C;AAAA,EACF;AAAA,EACF,MAAM,IAAI,QAAQ;AAAA,EAClB,QAAQ,IAAI,QAAQ;AAAA,EACpB,WAAW,IAAI,QAAQ;AAAA,EACvB,eAAe,IAAI,QAAQ;AAAA,EAC3B,MAAM,IAAI,QAAQ;AACpB,CAAC;AAED,MAAM,iBAAiB,CAAC,SAAiB;AACnC,MAAA;AAEE,QAAA,IAAI,KAAK,WAAW,GAAG,IAAI,oBAAoB,IAAI,KAAK,IAAI;AAAA,WACzD,OAAO;AACP,WAAA;AAAA,EACT;AACO,SAAA;AACT;AAEA,MAAM,oBAAoB,IAAI,OAAO,EAAE,MAAM;AAAA,EAC3C,MAAM,IAAI,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,SAAS;AAAA,EAC7C,KAAK,IACF,OAAO,EACP,KAAK,eAAe,gCAAgC,CAAC,UAAU,eAAe,SAAS,EAAE,CAAC;AAAA,EAC7F,UAAU,IAAI,MAAA,EAAQ,GAAG,iBAAiB,EAAE,SAAS;AACvD,CAAC;AAGD,MAAM,sBAA2B,IAAI,KAAK,CAAC,UAA4B;AACrE,UAAQ,MAAM,MAAM;AAAA,IAClB,KA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AAO,EAAE,SAAS;AAAA,IAC5B,MAAM,IAAI,OAAO,EAAE,SAAS;AAAA,IAC5B,YAAY,IAAI,OAAO,EAAE,SAAS;AAAA,IAClC,UAAU,IAAI,OAAO,EAAE,SAAS;AAAA,IAChC,mBAAmB,IAAI,MAAM,EAAE,SAAS;AAAA,IACxC,WAAW,IAAI,OAAO,EAAE,SAAS;AAAA,IACjC,WAAW,IAAI,OAAO,EAAE,SAAS;AAAA,EAAA,CAClC;AAAA,EACD,UAAU,IAAI,MAAA,EAAQ,GAAG,mBAAmB,EAAE,SAAS;AACzD,CAAC;AAGD,MAAM,qBAA0B,IAAI,KAAK,CAAC,UAA4B;AACpE,UAAQ,MAAM,MAAM;AAAA,IAClB,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAAA;AAAA,IACT;AACE,aAAO,IAAI,MAAM,EAAE,KAAK,gBAAgB,iCAAiC,MAAM;AACtE,eAAA;AAAA,MAAA,CACR;AAAA,EACL;AACF,CAAC;AAED,MAAM,wBAAwB,IAAI,MAAM,EAAE,GAAG,kBAAkB;AAExD,MAAM,kBAAkB,MAAM;"}
|
@@ -2,7 +2,7 @@
|
|
2
2
|
* Entity validator
|
3
3
|
* Module that will validate input data for entity creation or edition
|
4
4
|
*/
|
5
|
-
import { Modules, Struct } from '@strapi/types';
|
5
|
+
import { Modules, Struct, Schema } from '@strapi/types';
|
6
6
|
export type ComponentContext = {
|
7
7
|
parentContent: {
|
8
8
|
model: Struct.Schema;
|
@@ -11,6 +11,7 @@ export type ComponentContext = {
|
|
11
11
|
};
|
12
12
|
pathToComponent: string[];
|
13
13
|
repeatableData: Modules.EntityValidator.Entity[];
|
14
|
+
fullDynamicZoneContent?: Schema.Attribute.Value<Schema.Attribute.DynamicZone>;
|
14
15
|
};
|
15
16
|
interface ValidatorContext {
|
16
17
|
isDraft?: boolean;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/entity-validator/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAAE,OAAO,EAAO,MAAM,
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/entity-validator/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAAE,OAAO,EAAO,MAAM,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAa7D,MAAM,MAAM,gBAAgB,GAAG;IAC7B,aAAa,EAAE;QAEb,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC;QAErB,EAAE,CAAC,EAAE,MAAM,CAAC;QAGZ,OAAO,CAAC,EAAE,gBAAgB,CAAC;KAC5B,CAAC;IAEF,eAAe,EAAE,MAAM,EAAE,CAAC;IAG1B,cAAc,EAAE,OAAO,CAAC,eAAe,CAAC,MAAM,EAAE,CAAC;IACjD,sBAAsB,CAAC,EAAE,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;CAC/E,CAAC;AAWF,UAAU,gBAAgB;IACxB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB;AA+gBD,QAAA,MAAM,eAAe,EAAE,OAAO,CAAC,eAAe,CAAC,eAG9C,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
|
-
const _
|
3
|
-
const
|
2
|
+
const _ = require("lodash");
|
3
|
+
const fp = require("lodash/fp");
|
4
4
|
const strapiUtils = require("@strapi/utils");
|
5
5
|
const validators = require("./validators.js");
|
6
6
|
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
@@ -98,7 +98,7 @@ const createDzValidator = (createOrUpdate) => ({ attr, updatedAttribute, compone
|
|
98
98
|
let validator;
|
99
99
|
validator = yup.array().of(
|
100
100
|
yup.lazy((item) => {
|
101
|
-
const model = strapi.getModel(
|
101
|
+
const model = strapi.getModel(fp.prop("__component", item));
|
102
102
|
const schema = yup.object().shape({
|
103
103
|
__component: yup.string().required().oneOf(Object.keys(strapi.components))
|
104
104
|
}).notNull();
|
@@ -131,8 +131,8 @@ const createRelationValidator = ({
|
|
131
131
|
};
|
132
132
|
const createScalarAttributeValidator = (createOrUpdate) => (metas, options) => {
|
133
133
|
let validator;
|
134
|
-
if (
|
135
|
-
validator = validators[metas.attr.type](metas, options);
|
134
|
+
if (fp.has(metas.attr.type, validators.Validators)) {
|
135
|
+
validator = validators.Validators[metas.attr.type](metas, options);
|
136
136
|
} else {
|
137
137
|
validator = yup.mixed();
|
138
138
|
}
|
@@ -149,14 +149,14 @@ const createAttributeValidator = (createOrUpdate) => (metas, options) => {
|
|
149
149
|
} else if (isScalarAttribute(metas.attr)) {
|
150
150
|
validator = createScalarAttributeValidator(createOrUpdate)(metas, options);
|
151
151
|
} else {
|
152
|
-
if (metas.attr.type === "component") {
|
152
|
+
if (metas.attr.type === "component" && metas.componentContext) {
|
153
153
|
const pathToComponent = [
|
154
154
|
...metas?.componentContext?.pathToComponent ?? [],
|
155
155
|
metas.updatedAttribute.name
|
156
156
|
];
|
157
157
|
const repeatableData = metas.attr.repeatable && pathToComponent.length === 1 ? metas.updatedAttribute.value : metas.componentContext?.repeatableData;
|
158
158
|
const newComponentContext = {
|
159
|
-
...metas
|
159
|
+
...metas.componentContext,
|
160
160
|
pathToComponent,
|
161
161
|
repeatableData
|
162
162
|
};
|
@@ -168,19 +168,14 @@ const createAttributeValidator = (createOrUpdate) => (metas, options) => {
|
|
168
168
|
},
|
169
169
|
options
|
170
170
|
);
|
171
|
-
} else if (metas.attr.type === "dynamiczone") {
|
172
|
-
const pathToComponent = [
|
173
|
-
...metas?.componentContext?.pathToComponent ?? [],
|
174
|
-
metas.updatedAttribute.name
|
175
|
-
];
|
171
|
+
} else if (metas.attr.type === "dynamiczone" && metas.componentContext) {
|
176
172
|
const newComponentContext = {
|
177
|
-
...metas
|
178
|
-
|
173
|
+
...metas.componentContext,
|
174
|
+
fullDynamicZoneContent: metas.updatedAttribute.value,
|
175
|
+
pathToComponent: [...metas.componentContext.pathToComponent, metas.updatedAttribute.name]
|
179
176
|
};
|
180
|
-
|
181
|
-
|
182
|
-
options
|
183
|
-
);
|
177
|
+
Object.assign(metas, { componentContext: newComponentContext });
|
178
|
+
validator = createDzValidator(createOrUpdate)(metas, options);
|
184
179
|
} else if (metas.attr.type === "relation") {
|
185
180
|
validator = createRelationValidator({
|
186
181
|
attr: metas.attr,
|
@@ -198,7 +193,7 @@ const createModelValidator = (createOrUpdate) => ({ componentContext, model, dat
|
|
198
193
|
(validators2, attributeName) => {
|
199
194
|
const metas = {
|
200
195
|
attr: model.attributes[attributeName],
|
201
|
-
updatedAttribute: { name: attributeName, value:
|
196
|
+
updatedAttribute: { name: attributeName, value: fp.prop(attributeName, data) },
|
202
197
|
model,
|
203
198
|
entity,
|
204
199
|
componentContext
|
@@ -213,7 +208,7 @@ const createModelValidator = (createOrUpdate) => ({ componentContext, model, dat
|
|
213
208
|
};
|
214
209
|
const createValidateEntity = (createOrUpdate) => {
|
215
210
|
return async (model, data, options, entity) => {
|
216
|
-
if (!
|
211
|
+
if (!fp.isObject(data)) {
|
217
212
|
const { displayName } = model.info;
|
218
213
|
throw new ValidationError(
|
219
214
|
`Invalid payload submitted for the ${createOrUpdate} of an entity of type ${displayName}. Expected an object, but got ${typeof data}`
|
@@ -269,7 +264,7 @@ const buildRelationsStore = ({
|
|
269
264
|
if (!uid) {
|
270
265
|
throw new ValidationError(`Cannot build relations store: "uid" is undefined`);
|
271
266
|
}
|
272
|
-
if (
|
267
|
+
if (fp.isEmpty(data)) {
|
273
268
|
return {};
|
274
269
|
}
|
275
270
|
const currentModel = strapi.getModel(uid);
|
@@ -277,7 +272,7 @@ const buildRelationsStore = ({
|
|
277
272
|
(result, attributeName) => {
|
278
273
|
const attribute = currentModel.attributes[attributeName];
|
279
274
|
const value = data[attributeName];
|
280
|
-
if (_
|
275
|
+
if (_.isNil(value)) {
|
281
276
|
return result;
|
282
277
|
}
|
283
278
|
switch (attribute.type) {
|
@@ -293,16 +288,16 @@ const buildRelationsStore = ({
|
|
293
288
|
let source;
|
294
289
|
if (Array.isArray(value)) {
|
295
290
|
source = value;
|
296
|
-
} else if (
|
297
|
-
if ("connect" in value && !_
|
291
|
+
} else if (fp.isObject(value)) {
|
292
|
+
if ("connect" in value && !_.isNil(value.connect)) {
|
298
293
|
source = value.connect;
|
299
|
-
} else if ("set" in value && !_
|
294
|
+
} else if ("set" in value && !_.isNil(value.set)) {
|
300
295
|
source = value.set;
|
301
296
|
} else {
|
302
297
|
source = [];
|
303
298
|
}
|
304
299
|
} else {
|
305
|
-
source = _
|
300
|
+
source = _.castArray(value);
|
306
301
|
}
|
307
302
|
const idArray = source.map((v) => ({
|
308
303
|
id: typeof v === "object" ? v.id : v
|
@@ -312,20 +307,20 @@ const buildRelationsStore = ({
|
|
312
307
|
break;
|
313
308
|
}
|
314
309
|
case "component": {
|
315
|
-
return _
|
310
|
+
return _.castArray(value).reduce((relationsStore, componentValue) => {
|
316
311
|
if (!attribute.component) {
|
317
312
|
throw new ValidationError(
|
318
313
|
`Cannot build relations store from component, component identifier is undefined`
|
319
314
|
);
|
320
315
|
}
|
321
|
-
return _
|
316
|
+
return _.mergeWith(
|
322
317
|
relationsStore,
|
323
318
|
buildRelationsStore({
|
324
319
|
uid: attribute.component,
|
325
320
|
data: componentValue
|
326
321
|
}),
|
327
322
|
(objValue, srcValue) => {
|
328
|
-
if (_
|
323
|
+
if (_.isArray(objValue)) {
|
329
324
|
return objValue.concat(srcValue);
|
330
325
|
}
|
331
326
|
}
|
@@ -333,21 +328,21 @@ const buildRelationsStore = ({
|
|
333
328
|
}, result);
|
334
329
|
}
|
335
330
|
case "dynamiczone": {
|
336
|
-
return _
|
331
|
+
return _.castArray(value).reduce((relationsStore, dzValue) => {
|
337
332
|
const value2 = dzValue;
|
338
333
|
if (!value2.__component) {
|
339
334
|
throw new ValidationError(
|
340
335
|
`Cannot build relations store from dynamiczone, component identifier is undefined`
|
341
336
|
);
|
342
337
|
}
|
343
|
-
return _
|
338
|
+
return _.mergeWith(
|
344
339
|
relationsStore,
|
345
340
|
buildRelationsStore({
|
346
341
|
uid: value2.__component,
|
347
342
|
data: value2
|
348
343
|
}),
|
349
344
|
(objValue, srcValue) => {
|
350
|
-
if (_
|
345
|
+
if (_.isArray(objValue)) {
|
351
346
|
return objValue.concat(srcValue);
|
352
347
|
}
|
353
348
|
}
|
@@ -364,7 +359,7 @@ const checkRelationsExist = async (relationsStore = {}) => {
|
|
364
359
|
const promises = [];
|
365
360
|
for (const [key, value] of Object.entries(relationsStore)) {
|
366
361
|
const evaluate = async () => {
|
367
|
-
const uniqueValues = _
|
362
|
+
const uniqueValues = _.uniqBy(value, `id`);
|
368
363
|
const count = await strapi.db.query(key).count({
|
369
364
|
where: {
|
370
365
|
id: {
|