@strapi/core 0.0.0-experimental.a407f3bc8fb79a53cf7975140864526b6ddbac4b → 0.0.0-experimental.fc1ac2acd58c8a5a858679956b6d102ac5ee4011
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.d.ts.map +1 -1
- package/dist/Strapi.js +4 -1
- package/dist/Strapi.js.map +1 -1
- package/dist/Strapi.mjs +4 -1
- package/dist/Strapi.mjs.map +1 -1
- package/dist/configuration/index.d.ts.map +1 -1
- package/dist/configuration/index.js +4 -4
- package/dist/configuration/index.js.map +1 -1
- package/dist/configuration/index.mjs +1 -1
- package/dist/configuration/index.mjs.map +1 -1
- package/dist/configuration/urls.d.ts +8 -0
- package/dist/configuration/urls.d.ts.map +1 -0
- package/dist/configuration/urls.js +68 -0
- package/dist/configuration/urls.js.map +1 -0
- package/dist/configuration/urls.mjs +66 -0
- package/dist/configuration/urls.mjs.map +1 -0
- package/dist/core-api/controller/index.d.ts.map +1 -1
- package/dist/core-api/controller/index.js +6 -1
- package/dist/core-api/controller/index.js.map +1 -1
- package/dist/core-api/controller/index.mjs +6 -1
- package/dist/core-api/controller/index.mjs.map +1 -1
- package/dist/core-api/controller/transform.d.ts +8 -7
- package/dist/core-api/controller/transform.d.ts.map +1 -1
- package/dist/core-api/controller/transform.js +18 -9
- package/dist/core-api/controller/transform.js.map +1 -1
- package/dist/core-api/controller/transform.mjs +18 -9
- package/dist/core-api/controller/transform.mjs.map +1 -1
- package/dist/core-api/service/single-type.d.ts +1 -1
- package/dist/core-api/service/single-type.d.ts.map +1 -1
- package/dist/core-api/service/single-type.js +3 -4
- package/dist/core-api/service/single-type.js.map +1 -1
- package/dist/core-api/service/single-type.mjs +3 -4
- package/dist/core-api/service/single-type.mjs.map +1 -1
- package/dist/domain/content-type/index.d.ts.map +1 -1
- package/dist/domain/content-type/index.js +3 -0
- package/dist/domain/content-type/index.js.map +1 -1
- package/dist/domain/content-type/index.mjs +3 -0
- package/dist/domain/content-type/index.mjs.map +1 -1
- package/dist/domain/content-type/validator.d.ts.map +1 -1
- package/dist/domain/content-type/validator.js +1 -1
- package/dist/domain/content-type/validator.js.map +1 -1
- package/dist/domain/content-type/validator.mjs +2 -2
- package/dist/domain/content-type/validator.mjs.map +1 -1
- package/dist/domain/module/index.d.ts.map +1 -1
- package/dist/domain/module/index.js +2 -3
- package/dist/domain/module/index.js.map +1 -1
- package/dist/domain/module/index.mjs +2 -3
- package/dist/domain/module/index.mjs.map +1 -1
- package/dist/loaders/apis.js +1 -1
- package/dist/loaders/apis.js.map +1 -1
- package/dist/loaders/apis.mjs +2 -2
- package/dist/loaders/apis.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 +2 -2
- package/dist/loaders/plugins/get-enabled-plugins.mjs.map +1 -1
- package/dist/migrations/draft-publish.d.ts +17 -0
- package/dist/migrations/draft-publish.d.ts.map +1 -0
- package/dist/migrations/draft-publish.js +59 -0
- package/dist/migrations/draft-publish.js.map +1 -0
- package/dist/migrations/draft-publish.mjs +59 -0
- package/dist/migrations/draft-publish.mjs.map +1 -0
- package/dist/registries/config.d.ts +2 -2
- package/dist/registries/config.d.ts.map +1 -1
- package/dist/registries/config.js +14 -6
- package/dist/registries/config.js.map +1 -1
- package/dist/registries/config.mjs +15 -5
- package/dist/registries/config.mjs.map +1 -1
- package/dist/services/document-service/common.d.ts +2 -2
- 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/draft-and-publish.d.ts +9 -23
- package/dist/services/document-service/draft-and-publish.d.ts.map +1 -1
- package/dist/services/document-service/draft-and-publish.js +37 -9
- package/dist/services/document-service/draft-and-publish.js.map +1 -1
- package/dist/services/document-service/draft-and-publish.mjs +38 -10
- package/dist/services/document-service/draft-and-publish.mjs.map +1 -1
- package/dist/services/document-service/index.js +5 -5
- package/dist/services/document-service/index.js.map +1 -1
- package/dist/services/document-service/index.mjs +1 -1
- package/dist/services/document-service/index.mjs.map +1 -1
- package/dist/services/document-service/repository.d.ts +3 -0
- package/dist/services/document-service/repository.d.ts.map +1 -0
- package/dist/services/document-service/repository.js +304 -0
- package/dist/services/document-service/repository.js.map +1 -0
- package/dist/services/document-service/repository.mjs +304 -0
- package/dist/services/document-service/repository.mjs.map +1 -0
- package/dist/services/document-service/transform/id-map.d.ts +1 -1
- package/dist/services/document-service/transform/id-map.d.ts.map +1 -1
- package/dist/services/document-service/transform/id-map.js +15 -9
- package/dist/services/document-service/transform/id-map.js.map +1 -1
- package/dist/services/document-service/transform/id-map.mjs +16 -10
- package/dist/services/document-service/transform/id-map.mjs.map +1 -1
- package/dist/services/document-service/transform/id-transform.d.ts +4 -18
- package/dist/services/document-service/transform/id-transform.d.ts.map +1 -1
- package/dist/services/document-service/transform/id-transform.js +18 -12
- package/dist/services/document-service/transform/id-transform.js.map +1 -1
- package/dist/services/document-service/transform/id-transform.mjs +18 -12
- package/dist/services/document-service/transform/id-transform.mjs.map +1 -1
- package/dist/services/document-service/transform/populate.d.ts +5 -2
- package/dist/services/document-service/transform/populate.d.ts.map +1 -1
- package/dist/services/document-service/transform/populate.js.map +1 -1
- package/dist/services/document-service/transform/populate.mjs.map +1 -1
- package/dist/services/document-service/transform/relations/extract/data-ids.d.ts +1 -1
- package/dist/services/document-service/transform/relations/extract/data-ids.d.ts.map +1 -1
- package/dist/services/document-service/transform/relations/extract/data-ids.js +23 -12
- package/dist/services/document-service/transform/relations/extract/data-ids.js.map +1 -1
- package/dist/services/document-service/transform/relations/extract/data-ids.mjs +23 -12
- package/dist/services/document-service/transform/relations/extract/data-ids.mjs.map +1 -1
- package/dist/services/document-service/transform/relations/transform/data-ids.d.ts +1 -1
- package/dist/services/document-service/transform/relations/transform/data-ids.d.ts.map +1 -1
- package/dist/services/document-service/transform/relations/transform/data-ids.js +61 -37
- package/dist/services/document-service/transform/relations/transform/data-ids.js.map +1 -1
- package/dist/services/document-service/transform/relations/transform/data-ids.mjs +62 -38
- package/dist/services/document-service/transform/relations/transform/data-ids.mjs.map +1 -1
- package/dist/services/document-service/transform/relations/utils/dp.d.ts +10 -0
- package/dist/services/document-service/transform/relations/utils/dp.d.ts.map +1 -0
- package/dist/services/document-service/transform/relations/utils/dp.js +25 -0
- package/dist/services/document-service/transform/relations/utils/dp.js.map +1 -0
- package/dist/services/document-service/transform/relations/utils/dp.mjs +25 -0
- package/dist/services/document-service/transform/relations/utils/dp.mjs.map +1 -0
- package/dist/services/document-service/transform/relations/utils/types.d.ts +4 -1
- package/dist/services/document-service/transform/relations/utils/types.d.ts.map +1 -1
- package/dist/services/document-service/transform/types.d.ts +1 -1
- package/dist/services/document-service/transform/types.d.ts.map +1 -1
- package/dist/services/document-service/utils/populate.js +2 -2
- package/dist/services/document-service/utils/populate.js.map +1 -1
- package/dist/services/document-service/utils/populate.mjs +2 -2
- package/dist/services/document-service/utils/populate.mjs.map +1 -1
- package/dist/services/entity-service/components.js +8 -8
- package/dist/services/entity-service/components.js.map +1 -1
- package/dist/services/entity-service/components.mjs +9 -9
- package/dist/services/entity-service/components.mjs.map +1 -1
- package/dist/services/entity-service/index.d.ts.map +1 -1
- package/dist/services/entity-service/index.js +3 -3
- package/dist/services/entity-service/index.js.map +1 -1
- package/dist/services/entity-service/index.mjs +3 -3
- package/dist/services/entity-service/index.mjs.map +1 -1
- package/dist/services/entity-service/params.d.ts +4 -4
- package/dist/services/entity-service/params.d.ts.map +1 -1
- package/dist/services/entity-service/params.js +1 -1
- package/dist/services/entity-service/params.js.map +1 -1
- package/dist/services/entity-service/params.mjs +1 -1
- package/dist/services/entity-service/params.mjs.map +1 -1
- package/dist/utils/load-config-file.js +1 -1
- package/dist/utils/load-config-file.js.map +1 -1
- package/dist/utils/load-config-file.mjs +2 -2
- package/dist/utils/load-config-file.mjs.map +1 -1
- package/package.json +14 -14
- package/dist/services/document-service/document-engine.d.ts +0 -8
- package/dist/services/document-service/document-engine.d.ts.map +0 -1
- package/dist/services/document-service/document-engine.js +0 -241
- package/dist/services/document-service/document-engine.js.map +0 -1
- package/dist/services/document-service/document-engine.mjs +0 -242
- package/dist/services/document-service/document-engine.mjs.map +0 -1
- package/dist/services/document-service/repositories/content-type.d.ts +0 -3
- package/dist/services/document-service/repositories/content-type.d.ts.map +0 -1
- package/dist/services/document-service/repositories/content-type.js +0 -139
- package/dist/services/document-service/repositories/content-type.js.map +0 -1
- package/dist/services/document-service/repositories/content-type.mjs +0 -139
- package/dist/services/document-service/repositories/content-type.mjs.map +0 -1
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"data-ids.mjs","sources":["../../../../../../src/services/document-service/transform/relations/extract/data-ids.ts"],"sourcesContent":["import { isObject } from 'lodash/fp';\nimport { EntityService, Attribute, Common } from '@strapi/types';\nimport { traverseEntity } from '@strapi/utils';\nimport { IdMap } from '../../id-map';\nimport { ShortHand, LongHand, LongHandDocument } from '../utils/types';\nimport { isShortHand, isLongHand } from '../utils/data';\nimport { getRelationTargetLocale } from '../utils/i18n';\n\n/**\n * Get relation ids from primitive representation (id, id[], {id}, {id}[])\n */\nconst handlePrimitive = (\n relation: ShortHand | LongHand | ShortHand[] | LongHand[] | null | undefined | any\n): LongHandDocument[] => {\n if (!relation) {\n return []; // null\n }\n\n if (isShortHand(relation)) {\n return [{ documentId: relation }]; // id\n }\n\n if (isLongHand(relation)) {\n // { documentId, locale? }\n if ('documentId' in relation) {\n return [{ documentId: relation.documentId, locale: relation.locale }];\n }\n // { id }\n return [];\n }\n\n if (Array.isArray(relation)) {\n return relation.map((item) => (isShortHand(item) ? { documentId: item } : item)); // id[]\n }\n\n return [];\n};\n\n/**\n * Get all relations document ids from a relation input value\n */\nconst extractRelationIds = <T extends Attribute.RelationKind.Any>(\n relation: EntityService.Params.Attribute.RelationInputValue<T>\n): LongHandDocument[] => {\n const ids = handlePrimitive(relation);\n if (!isObject(relation)) return ids;\n\n if ('set' in relation) ids.push(...handlePrimitive(relation.set)); // set: id[]\n if ('disconnect' in relation) ids.push(...handlePrimitive(relation.disconnect)); // disconnect: id[]\n if ('connect' in relation) {\n // connect: id[] | { id } | ...\n if (!relation.connect) return [];\n ids.push(...handlePrimitive(relation.connect));\n\n // handle positional arguments\n const connect = Array.isArray(relation.connect) ? relation.connect : [relation.connect];\n connect.forEach((relation) => {\n if (isShortHand(relation) || !('position' in relation)) return;\n\n const { position } = relation;\n\n // { connect: { id: id, position: { before: id } } }\n if (position?.before) {\n ids.push(...handlePrimitive({ ...position,
|
1
|
+
{"version":3,"file":"data-ids.mjs","sources":["../../../../../../src/services/document-service/transform/relations/extract/data-ids.ts"],"sourcesContent":["import { isObject } from 'lodash/fp';\nimport { EntityService, Attribute, Common } from '@strapi/types';\nimport { traverseEntity } from '@strapi/utils';\nimport { IdMap } from '../../id-map';\nimport { ShortHand, LongHand, LongHandDocument } from '../utils/types';\nimport { isShortHand, isLongHand } from '../utils/data';\nimport { getRelationTargetLocale } from '../utils/i18n';\nimport { getRelationTargetStatus } from '../utils/dp';\n\n/**\n * Get relation ids from primitive representation (id, id[], {id}, {id}[])\n */\nconst handlePrimitive = (\n relation: ShortHand | LongHand | ShortHand[] | LongHand[] | null | undefined | any\n): LongHandDocument[] => {\n if (!relation) {\n return []; // null\n }\n\n if (isShortHand(relation)) {\n return [{ documentId: relation }]; // id\n }\n\n if (isLongHand(relation)) {\n // { documentId, locale? }\n if ('documentId' in relation) {\n return [\n { documentId: relation.documentId, locale: relation.locale, status: relation.status },\n ];\n }\n // { id }\n return [];\n }\n\n if (Array.isArray(relation)) {\n return relation.map((item) => (isShortHand(item) ? { documentId: item } : item)); // id[]\n }\n\n return [];\n};\n\n/**\n * Get all relations document ids from a relation input value\n */\nconst extractRelationIds = <T extends Attribute.RelationKind.Any>(\n relation: EntityService.Params.Attribute.RelationInputValue<T>\n): LongHandDocument[] => {\n const ids = handlePrimitive(relation);\n if (!isObject(relation)) return ids;\n\n if ('set' in relation) ids.push(...handlePrimitive(relation.set)); // set: id[]\n if ('disconnect' in relation) ids.push(...handlePrimitive(relation.disconnect)); // disconnect: id[]\n if ('connect' in relation) {\n // connect: id[] | { id } | ...\n if (!relation.connect) return [];\n ids.push(...handlePrimitive(relation.connect));\n\n // handle positional arguments\n const connect = Array.isArray(relation.connect) ? relation.connect : [relation.connect];\n connect.forEach((relation) => {\n if (isShortHand(relation) || !('position' in relation)) return;\n\n const { position } = relation;\n\n // { connect: { id: id, position: { before: id } } }\n if (position?.before) {\n ids.push(...handlePrimitive({ ...position, documentId: position.before }));\n }\n\n // { connect: { id: id, position: { after: id } } }\n if (position?.after) {\n ids.push(...handlePrimitive({ ...position, documentId: position.after }));\n }\n });\n }\n\n return ids;\n};\n\n/**\n * Iterate over all attributes of a Data object and extract all relational document ids.\n * Those will later be transformed to entity ids.\n */\nconst extractDataIds = (\n idMap: IdMap,\n data: Record<string, any>,\n opts: { uid: Common.UID.Schema; locale?: string | null; status?: 'draft' | 'published' }\n) => {\n return traverseEntity(\n ({ value, attribute }) => {\n // Find relational attributes, and return the document ids\n if (attribute.type === 'relation') {\n const extractedIds = extractRelationIds(value as any);\n\n // TODO: Handle morph relations (they have multiple targets)\n const target = attribute.target;\n if (!target) return;\n\n // If not connecting to any version on disabled d&p, we should connect to both draft and published relations at the same time\n extractedIds.forEach((relation) => {\n const targetLocale = getRelationTargetLocale(relation, {\n targetUid: target as Common.UID.Schema,\n sourceUid: opts.uid,\n sourceLocale: opts.locale,\n });\n\n const targetStatus = getRelationTargetStatus(relation, {\n targetUid: target as Common.UID.Schema,\n sourceUid: opts.uid,\n sourceStatus: opts.status,\n });\n\n targetStatus.forEach((status) => {\n idMap.add({\n uid: target,\n documentId: relation.documentId,\n locale: targetLocale,\n status,\n });\n });\n });\n }\n },\n { schema: strapi.getModel(opts.uid) },\n data\n );\n};\n\nexport { extractDataIds };\n"],"names":["relation"],"mappings":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gBAAgB,EAAE,GAAG,UAAU,YAAY,SAAS,MAAO,CAAA,CAAC;AAAA,MAC1E;AAAA,IAAA,CACD;AAAA,EACH;AAEO,SAAA;AACT;AAMA,MAAM,iBAAiB,CACrB,OACA,MACA,SACG;AACI,SAAA;AAAA,IACL,CAAC,EAAE,OAAO,gBAAgB;AAEpB,UAAA,UAAU,SAAS,YAAY;AAC3B,cAAA,eAAe,mBAAmB,KAAY;AAGpD,cAAM,SAAS,UAAU;AACzB,YAAI,CAAC;AAAQ;AAGA,qBAAA,QAAQ,CAAC,aAAa;AAC3B,gBAAA,eAAe,wBAAwB,UAAU;AAAA,YACrD,WAAW;AAAA,YACX,WAAW,KAAK;AAAA,YAChB,cAAc,KAAK;AAAA,UAAA,CACpB;AAEK,gBAAA,eAAe,wBAAwB,UAAU;AAAA,YACrD,WAAW;AAAA,YACX,WAAW,KAAK;AAAA,YAChB,cAAc,KAAK;AAAA,UAAA,CACpB;AAEY,uBAAA,QAAQ,CAAC,WAAW;AAC/B,kBAAM,IAAI;AAAA,cACR,KAAK;AAAA,cACL,YAAY,SAAS;AAAA,cACrB,QAAQ;AAAA,cACR;AAAA,YAAA,CACD;AAAA,UAAA,CACF;AAAA,QAAA,CACF;AAAA,MACH;AAAA,IACF;AAAA,IACA,EAAE,QAAQ,OAAO,SAAS,KAAK,GAAG,EAAE;AAAA,IACpC;AAAA,EAAA;AAEJ;"}
|
@@ -3,7 +3,7 @@ import { IdMap } from '../../id-map';
|
|
3
3
|
declare const transformDataIdsVisitor: (idMap: IdMap, data: Record<string, any>, opts: {
|
4
4
|
uid: Common.UID.Schema;
|
5
5
|
locale?: string | null;
|
6
|
-
|
6
|
+
status?: 'draft' | 'published';
|
7
7
|
allowMissingId?: boolean;
|
8
8
|
}) => Promise<import("@strapi/utils/dist/types").Data>;
|
9
9
|
export { transformDataIdsVisitor };
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"data-ids.d.ts","sourceRoot":"","sources":["../../../../../../src/services/document-service/transform/relations/transform/data-ids.ts"],"names":[],"mappings":"AAEA,OAAO,EAA4B,MAAM,EAAE,MAAM,eAAe,CAAC;AAKjE,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;
|
1
|
+
{"version":3,"file":"data-ids.d.ts","sourceRoot":"","sources":["../../../../../../src/services/document-service/transform/relations/transform/data-ids.ts"],"names":[],"mappings":"AAEA,OAAO,EAA4B,MAAM,EAAE,MAAM,eAAe,CAAC;AAKjE,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AA8JrC,QAAA,MAAM,uBAAuB,UACpB,KAAK,QACN,OAAO,MAAM,EAAE,GAAG,CAAC,QACnB;IACJ,GAAG,EAAE,OAAO,GAAG,CAAC,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,MAAM,CAAC,EAAE,OAAO,GAAG,WAAW,CAAC;IAC/B,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B,qDA6DF,CAAC;AAEF,OAAO,EAAE,uBAAuB,EAAE,CAAC"}
|
@@ -4,13 +4,14 @@ const _ = require("lodash/fp");
|
|
4
4
|
const strapiUtils = require("@strapi/utils");
|
5
5
|
const data = require("../utils/data.js");
|
6
6
|
const i18n = require("../utils/i18n.js");
|
7
|
+
const dp = require("../utils/dp.js");
|
7
8
|
const isNumeric = (value) => {
|
8
9
|
if (Array.isArray(value))
|
9
10
|
return false;
|
10
11
|
const parsed = parseInt(value, 10);
|
11
12
|
return !Number.isNaN(parsed);
|
12
13
|
};
|
13
|
-
const transformPrimitive = (relation,
|
14
|
+
const transformPrimitive = (relation, getIds) => {
|
14
15
|
if (isNumeric(relation)) {
|
15
16
|
return relation;
|
16
17
|
}
|
@@ -18,48 +19,64 @@ const transformPrimitive = (relation, getId) => {
|
|
18
19
|
return relation;
|
19
20
|
}
|
20
21
|
if (data.isShortHand(relation)) {
|
21
|
-
|
22
|
+
const ids = getIds(relation);
|
23
|
+
if (ids?.length === 1)
|
24
|
+
return ids[0];
|
25
|
+
return ids;
|
22
26
|
}
|
23
27
|
if (data.isLongHand(relation)) {
|
24
28
|
if (!("documentId" in relation))
|
25
29
|
return relation;
|
26
|
-
const
|
27
|
-
if (!
|
30
|
+
const ids = getIds(relation.documentId, relation.locale, relation.status);
|
31
|
+
if (!ids?.length)
|
28
32
|
return void 0;
|
29
|
-
|
33
|
+
if (ids.length === 1)
|
34
|
+
return { id: ids[0], ..._.pick(["position"], relation) };
|
35
|
+
return ids.map((id) => ({ id, ..._.pick(["position"], relation) }));
|
30
36
|
}
|
31
37
|
if (Array.isArray(relation)) {
|
32
|
-
return relation.
|
38
|
+
return relation.flatMap((item) => transformPrimitive(item, getIds)).filter(Boolean);
|
33
39
|
}
|
34
40
|
return void 0;
|
35
41
|
};
|
36
|
-
const transformRelationIdsVisitor = (relation,
|
37
|
-
const map = transformPrimitive(relation,
|
42
|
+
const transformRelationIdsVisitor = (relation, getIds) => {
|
43
|
+
const map = transformPrimitive(relation, getIds);
|
38
44
|
if (map)
|
39
45
|
return map;
|
40
46
|
if (!_.isObject(relation))
|
41
47
|
return relation;
|
48
|
+
if (!("set" in relation) && !("disconnect" in relation) && !("connect" in relation)) {
|
49
|
+
return;
|
50
|
+
}
|
42
51
|
if ("set" in relation) {
|
43
|
-
relation.set = transformPrimitive(relation.set,
|
52
|
+
relation.set = transformPrimitive(relation.set, getIds);
|
44
53
|
}
|
45
54
|
if ("disconnect" in relation) {
|
46
|
-
relation.disconnect = transformPrimitive(relation.disconnect,
|
55
|
+
relation.disconnect = transformPrimitive(relation.disconnect, getIds);
|
47
56
|
}
|
48
57
|
if ("connect" in relation) {
|
49
|
-
relation.connect = transformPrimitive(relation.connect,
|
58
|
+
relation.connect = transformPrimitive(relation.connect, getIds);
|
50
59
|
const mapPosition = (relation2) => {
|
51
60
|
if (data.isShortHand(relation2) || !("position" in relation2))
|
52
61
|
return relation2;
|
53
|
-
const { position }
|
62
|
+
const position = { ...relation2?.position };
|
54
63
|
if (position?.before) {
|
55
|
-
const
|
56
|
-
|
64
|
+
const result = transformPrimitive({ ...position, documentId: position.before }, getIds);
|
65
|
+
if (Array.isArray(result)) {
|
66
|
+
position.before = result[0]?.id;
|
67
|
+
} else {
|
68
|
+
position.before = result?.id;
|
69
|
+
}
|
57
70
|
}
|
58
71
|
if (position?.after) {
|
59
|
-
const
|
60
|
-
|
72
|
+
const result = transformPrimitive({ ...position, documentId: position.after }, getIds);
|
73
|
+
if (Array.isArray(result)) {
|
74
|
+
position.after = result[0]?.id;
|
75
|
+
} else {
|
76
|
+
position.after = result?.id;
|
77
|
+
}
|
61
78
|
}
|
62
|
-
return relation2;
|
79
|
+
return { ...relation2, position };
|
63
80
|
};
|
64
81
|
if (Array.isArray(relation.connect)) {
|
65
82
|
relation.connect = relation.connect.map(mapPosition);
|
@@ -85,27 +102,34 @@ const transformDataIdsVisitor = (idMap, data2, opts) => {
|
|
85
102
|
return;
|
86
103
|
if (EXCLUDED_FIELDS.includes(key))
|
87
104
|
return;
|
88
|
-
const
|
89
|
-
const
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
105
|
+
const getIds = (documentId, locale, status) => {
|
106
|
+
const targetLocale = i18n.getRelationTargetLocale(
|
107
|
+
{ documentId, locale },
|
108
|
+
{ targetUid: target, sourceUid: opts.uid, sourceLocale: opts.locale }
|
109
|
+
);
|
110
|
+
const targetStatuses = dp.getRelationTargetStatus(
|
111
|
+
{ documentId, status },
|
112
|
+
{ targetUid: target, sourceUid: opts.uid, sourceStatus: opts.status }
|
113
|
+
);
|
114
|
+
const ids = [];
|
115
|
+
for (const targetStatus of targetStatuses) {
|
116
|
+
const entryId = idMap.get({
|
117
|
+
uid: target,
|
118
|
+
documentId,
|
119
|
+
locale: targetLocale,
|
120
|
+
status: targetStatus
|
121
|
+
});
|
122
|
+
if (entryId)
|
123
|
+
ids.push(entryId);
|
124
|
+
}
|
125
|
+
if (!ids.length && !opts.allowMissingId) {
|
126
|
+
throw new strapiUtils.errors.ValidationError(
|
127
|
+
`Document with id "${documentId}", locale "${targetLocale}" not found`
|
128
|
+
);
|
129
|
+
}
|
130
|
+
return ids;
|
107
131
|
};
|
108
|
-
const newRelation = transformRelationIdsVisitor(value,
|
132
|
+
const newRelation = transformRelationIdsVisitor(value, getIds);
|
109
133
|
set(key, newRelation);
|
110
134
|
}
|
111
135
|
},
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"data-ids.js","sources":["../../../../../../src/services/document-service/transform/relations/transform/data-ids.ts"],"sourcesContent":["import { isObject, isNil } from 'lodash/fp';\n\nimport { EntityService, Attribute, Common } from '@strapi/types';\nimport { traverseEntity, errors } from '@strapi/utils';\n\nimport { ShortHand, LongHand, ID, GetId } from '../utils/types';\nimport { isShortHand, isLongHand } from '../utils/data';\nimport { IdMap } from '../../id-map';\nimport { getRelationTargetLocale } from '../utils/i18n';\n\nconst isNumeric = (value: any): value is number => {\n if (Array.isArray(value)) return false; // Handle [1, 'docId'] case\n const parsed = parseInt(value, 10);\n return !Number.isNaN(parsed);\n};\n\nconst transformPrimitive = <T extends ShortHand | LongHand>(\n relation: T | T[] | null | undefined,\n getId: GetId\n): T | T[] | undefined => {\n // TODO: Remove this, we should use the long hand version with 'id' for this case\n // If id value is a number, return it as is, it's already an entry id\n if (isNumeric(relation)) {\n return relation;\n }\n\n // null\n if (isNil(relation)) {\n return relation as T | undefined;\n }\n\n // id\n if (isShortHand(relation)) {\n return getId(relation) as T;\n }\n\n // { id }\n if (isLongHand(relation)) {\n // If the id is already an entry id, return it as is\n if (!('documentId' in relation)) return relation;\n\n // @ts-expect-error - TODO: Add relation type\n const entryId = getId(relation.documentId, relation.locale) as T;\n\n // If the id is not found, return undefined\n if (!entryId) return undefined;\n\n return { ...(relation as object), id: entryId } as T;\n }\n\n // id[]\n if (Array.isArray(relation)) {\n return relation.map((item) => transformPrimitive(item, getId)).filter(Boolean) as T[];\n }\n return undefined;\n};\n\nconst transformRelationIdsVisitor = <T extends Attribute.RelationKind.Any>(\n relation: EntityService.Params.Attribute.RelationInputValue<T>,\n getId: GetId\n): EntityService.Params.Attribute.RelationInputValue<T> => {\n const map = transformPrimitive(relation as any, getId);\n if (map) return map;\n\n if (!isObject(relation)) return relation;\n\n // set: id[]\n // what if result of mapPrimitive is undefined?\n if ('set' in relation) {\n relation.set = transformPrimitive(relation.set as any, getId);\n }\n if ('disconnect' in relation) {\n relation.disconnect = transformPrimitive(relation.disconnect as any, getId);\n }\n\n if ('connect' in relation) {\n // connect: id[] | { id } | ...\n relation.connect = transformPrimitive(relation.connect as any, getId);\n\n const mapPosition = (relation: any) => {\n if (isShortHand(relation) || !('position' in relation)) return relation;\n\n const { position } = relation;\n\n // { connect: { id: id, position: { before: id } } }\n if (position?.before) {\n const { id } = transformPrimitive({ ...position, documentId: position.before }, getId);\n position.before = id;\n }\n\n // { connect: { id: id, position: { after: id } } }\n if (position?.after) {\n const { id } = transformPrimitive({ ...position, documentId: position.after }, getId);\n position.after = id;\n }\n\n return relation;\n };\n\n if (Array.isArray(relation.connect)) {\n relation.connect = relation.connect.map(mapPosition);\n } else {\n relation.connect = mapPosition(relation.connect);\n }\n }\n\n return relation;\n};\n\nconst EXCLUDED_FIELDS = [\n 'createdBy',\n 'updatedBy',\n 'localizations',\n 'strapi_stage',\n 'strapi_assignee',\n];\n\nconst transformDataIdsVisitor = (\n idMap: IdMap,\n data: Record<string, any>,\n opts: {\n uid: Common.UID.Schema;\n locale?: string | null;\n isDraft?: boolean;\n allowMissingId?: boolean; // Whether to ignore missing ids and not throw any error\n }\n) => {\n return traverseEntity(\n ({ key, value, attribute }, { set }) => {\n // Find relational attributes, and return the document ids\n if (attribute.type === 'relation') {\n const target = attribute.target;\n // TODO: Handle polymorphic relations\n if (!target) return;\n // TODO: Handle this differently\n if (EXCLUDED_FIELDS.includes(key)) return;\n\n const getId = (documentId: ID, locale?: string): ID | null => {\n const entryId = idMap.get({\n uid: target,\n documentId,\n locale: getRelationTargetLocale(\n { documentId, locale },\n {\n targetUid: target as Common.UID.Schema,\n sourceUid: opts.uid,\n sourceLocale: opts.locale,\n }\n ),\n isDraft: opts.isDraft,\n });\n\n if (entryId) return entryId;\n if (opts.allowMissingId) return null;\n\n throw new errors.ValidationError(`Document with id \"${documentId}\" not found`);\n };\n\n const newRelation = transformRelationIdsVisitor(value as any, getId);\n set(key, newRelation as any);\n }\n },\n { schema: strapi.getModel(opts.uid) },\n data\n );\n};\n\nexport { transformDataIdsVisitor };\n"],"names":["isNil","isShortHand","isLongHand","isObject","relation","data","traverseEntity","getRelationTargetLocale","errors"],"mappings":";;;;;;AAUA,MAAM,YAAY,CAAC,UAAgC;AAC7C,MAAA,MAAM,QAAQ,KAAK;AAAU,WAAA;AAC3B,QAAA,SAAS,SAAS,OAAO,EAAE;AAC1B,SAAA,CAAC,OAAO,MAAM,MAAM;AAC7B;AAEA,MAAM,qBAAqB,CACzB,UACA,UACwB;AAGpB,MAAA,UAAU,QAAQ,GAAG;AAChB,WAAA;AAAA,EACT;AAGI,MAAAA,EAAAA,MAAM,QAAQ,GAAG;AACZ,WAAA;AAAA,EACT;AAGI,MAAAC,KAAAA,YAAY,QAAQ,GAAG;AACzB,WAAO,MAAM,QAAQ;AAAA,EACvB;AAGI,MAAAC,KAAAA,WAAW,QAAQ,GAAG;AAExB,QAAI,EAAE,gBAAgB;AAAkB,aAAA;AAGxC,UAAM,UAAU,MAAM,SAAS,YAAY,SAAS,MAAM;AAG1D,QAAI,CAAC;AAAgB,aAAA;AAErB,WAAO,EAAE,GAAI,UAAqB,IAAI,QAAQ;AAAA,EAChD;AAGI,MAAA,MAAM,QAAQ,QAAQ,GAAG;AACpB,WAAA,SAAS,IAAI,CAAC,SAAS,mBAAmB,MAAM,KAAK,CAAC,EAAE,OAAO,OAAO;AAAA,EAC/E;A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AAS,YAAY;AACjC,cAAM,SAAS,UAAU;AAEzB,YAAI,CAAC;AAAQ;AAET,YAAA,gBAAgB,SAAS,GAAG;AAAG;AAE7B,cAAA,QAAQ,CAAC,YAAgB,WAA+B;AACtD,gBAAA,UAAU,MAAM,IAAI;AAAA,YACxB,KAAK;AAAA,YACL;AAAA,YACA,QAAQC,KAAA;AAAA,cACN,EAAE,YAAY,OAAO;AAAA,cACrB;AAAA,gBACE,WAAW;AAAA,gBACX,WAAW,KAAK;AAAA,gBAChB,cAAc,KAAK;AAAA,cACrB;AAAA,YACF;AAAA,YACA,SAAS,KAAK;AAAA,UAAA,CACf;AAEG,cAAA;AAAgB,mBAAA;AACpB,cAAI,KAAK;AAAuB,mBAAA;AAEhC,gBAAM,IAAIC,YAAA,OAAO,gBAAgB,qBAAqB,UAAU,aAAa;AAAA,QAAA;AAGzE,cAAA,cAAc,4BAA4B,OAAc,KAAK;AACnE,YAAI,KAAK,WAAkB;AAAA,MAC7B;AAAA,IACF;AAAA,IACA,EAAE,QAAQ,OAAO,SAAS,KAAK,GAAG,EAAE;AAAA,IACpCH;AAAA,EAAA;AAEJ;;"}
|
1
|
+
{"version":3,"file":"data-ids.js","sources":["../../../../../../src/services/document-service/transform/relations/transform/data-ids.ts"],"sourcesContent":["import { isObject, isNil, pick } from 'lodash/fp';\n\nimport { EntityService, Attribute, Common } from '@strapi/types';\nimport { traverseEntity, errors } from '@strapi/utils';\n\nimport { ShortHand, LongHand, ID, GetIds } from '../utils/types';\nimport { isShortHand, isLongHand } from '../utils/data';\nimport { IdMap } from '../../id-map';\nimport { getRelationTargetLocale } from '../utils/i18n';\nimport { getRelationTargetStatus } from '../utils/dp';\n\nconst isNumeric = (value: any): value is number => {\n if (Array.isArray(value)) return false; // Handle [1, 'docId'] case\n const parsed = parseInt(value, 10);\n return !Number.isNaN(parsed);\n};\n\n/**\n * Transform primitive relation representation to entry ids\n *\n * docId -> id\n * [docId] -> [id]\n * { documentID, locale, status } -> { id }\n * [{ documentID, locale, status }] -> [{ id }]\n *\n * Note: There are scenarios where a single documentID can map to multiple ids.\n * By default the returned format will match the input format.\n * Only when the docID maps to multiple ids, an array will always be returned, regardless of the input format.\n */\nconst transformPrimitive = <T extends ShortHand | LongHand>(\n relation: T | T[] | null | undefined,\n getIds: GetIds\n): T | T[] | undefined => {\n // TODO: Remove this, we should use the long hand version with 'id' for this case\n // If id value is a number, return it as is, it's already an entry id\n if (isNumeric(relation)) {\n return relation;\n }\n\n // null\n if (isNil(relation)) {\n return relation as T | undefined;\n }\n\n // id\n if (isShortHand(relation)) {\n const ids = getIds(relation) as T[];\n\n // Return it with the same format for consistency\n if (ids?.length === 1) return ids[0];\n\n // Return an array if multiple ids are found\n return ids;\n }\n\n // { id }\n if (isLongHand(relation)) {\n // If the id is already an entry id, return it as is\n if (!('documentId' in relation)) return relation;\n\n // @ts-expect-error - TODO: Add relation type\n const ids = getIds(relation.documentId, relation.locale, relation.status);\n\n // No ids to connect\n if (!ids?.length) return undefined;\n\n // Return it with the same format for consistency\n if (ids.length === 1) return { id: ids[0], ...pick(['position'], relation) } as T;\n\n // Return an array if it multiple ids are found\n return ids.map((id: ID) => ({ id, ...pick(['position'], relation) })) as T[];\n }\n\n // id[]\n if (Array.isArray(relation)) {\n return relation.flatMap((item) => transformPrimitive(item, getIds)).filter(Boolean) as T[];\n }\n\n return undefined;\n};\n\n/**\n * Transform ids in any type of relation input value\n * - set: [docId]\n * - disconnect: [docId]\n * - connect: [docId]\n * Or using any of the other primitive representations\n */\nconst transformRelationIdsVisitor = <T extends Attribute.RelationKind.Any>(\n relation: EntityService.Params.Attribute.RelationInputValue<T>,\n getIds: GetIds\n): EntityService.Params.Attribute.RelationInputValue<T> | undefined => {\n const map = transformPrimitive(relation as any, getIds);\n if (map) return map;\n\n if (!isObject(relation)) return relation;\n\n if (!('set' in relation) && !('disconnect' in relation) && !('connect' in relation)) {\n // The entry id couldn't be found and there are no connection properties in\n // the relation, therefore we want to remove the relation\n return;\n }\n\n // set: id[]\n // what if result of mapPrimitive is undefined?\n if ('set' in relation) {\n relation.set = transformPrimitive(relation.set as any, getIds);\n }\n\n if ('disconnect' in relation) {\n relation.disconnect = transformPrimitive(relation.disconnect as any, getIds);\n }\n\n if ('connect' in relation) {\n // connect: id[] | { id } | ...\n relation.connect = transformPrimitive(relation.connect as any, getIds);\n\n const mapPosition = (relation: any) => {\n if (isShortHand(relation) || !('position' in relation)) return relation;\n\n const position = { ...relation?.position };\n\n // { connect: { id: id, position: { before: id } } }\n if (position?.before) {\n const result = transformPrimitive({ ...position, documentId: position.before }, getIds);\n\n if (Array.isArray(result)) {\n position.before = result[0]?.id;\n } else {\n position.before = result?.id;\n }\n }\n\n // { connect: { id: id, position: { after: id } } }\n if (position?.after) {\n const result = transformPrimitive({ ...position, documentId: position.after }, getIds);\n\n if (Array.isArray(result)) {\n position.after = result[0]?.id;\n } else {\n position.after = result?.id;\n }\n }\n\n return { ...relation, position };\n };\n\n if (Array.isArray(relation.connect)) {\n relation.connect = relation.connect.map(mapPosition);\n } else {\n relation.connect = mapPosition(relation.connect);\n }\n }\n\n return relation;\n};\n\nconst EXCLUDED_FIELDS = [\n 'createdBy',\n 'updatedBy',\n 'localizations',\n 'strapi_stage',\n 'strapi_assignee',\n];\n\nconst transformDataIdsVisitor = (\n idMap: IdMap,\n data: Record<string, any>,\n opts: {\n uid: Common.UID.Schema;\n locale?: string | null;\n status?: 'draft' | 'published';\n allowMissingId?: boolean; // Whether to ignore missing ids and not throw any error\n }\n) => {\n return traverseEntity(\n ({ key, value, attribute }, { set }) => {\n // Find relational attributes, and return the document ids\n if (attribute.type === 'relation') {\n const target = attribute.target as Common.UID.Schema | undefined;\n // TODO: Handle polymorphic relations\n if (!target) return;\n // TODO: V5 remove excluded fields and use { id: } syntax for those relations\n if (EXCLUDED_FIELDS.includes(key)) return;\n\n const getIds = (\n documentId: ID,\n locale?: string,\n status?: 'draft' | 'published'\n ): ID[] | null => {\n // locale to connect to\n const targetLocale = getRelationTargetLocale(\n { documentId, locale },\n { targetUid: target, sourceUid: opts.uid, sourceLocale: opts.locale }\n );\n\n // status(es) to connect to\n const targetStatuses = getRelationTargetStatus(\n { documentId, status },\n { targetUid: target, sourceUid: opts.uid, sourceStatus: opts.status }\n );\n\n const ids = [];\n\n // Find mapping between documentID -> id(s).\n // There are scenarios where a single documentID can map to multiple ids.\n // e.g when connecting Non DP -> DP and connecting to both the draft and publish version at the same time\n for (const targetStatus of targetStatuses) {\n const entryId = idMap.get({\n uid: target,\n documentId,\n locale: targetLocale,\n status: targetStatus,\n });\n\n if (entryId) ids.push(entryId);\n }\n\n if (!ids.length && !opts.allowMissingId) {\n throw new errors.ValidationError(\n `Document with id \"${documentId}\", locale \"${targetLocale}\" not found`\n );\n }\n\n return ids;\n };\n\n const newRelation = transformRelationIdsVisitor(value as any, getIds);\n set(key, newRelation as any);\n }\n },\n { schema: strapi.getModel(opts.uid) },\n data\n );\n};\n\nexport { transformDataIdsVisitor };\n"],"names":["isNil","isShortHand","isLongHand","pick","isObject","relation","data","traverseEntity","getRelationTargetLocale","getRelationTargetStatus","errors"],"mappings":";;;;;;;AAWA,MAAM,YAAY,CAAC,UAAgC;AAC7C,MAAA,MAAM,QAAQ,KAAK;AAAU,WAAA;AAC3B,QAAA,SAAS,SAAS,OAAO,EAAE;AAC1B,SAAA,CAAC,OAAO,MAAM,MAAM;AAC7B;AAcA,MAAM,qBAAqB,CACzB,UACA,WACwB;AAGpB,MAAA,UAAU,QAAQ,GAAG;AAChB,WAAA;AAAA,EACT;AAGI,MAAAA,EAAAA,MAAM,QAAQ,GAAG;AACZ,WAAA;AAAA,EACT;AAGI,MAAAC,KAAAA,YAAY,QAAQ,GAAG;AACnB,UAAA,MAAM,OAAO,QAAQ;AAG3B,QAAI,KAAK,WAAW;AAAG,aAAO,IAAI,CAAC;AAG5B,WAAA;AAAA,EACT;AAGI,MAAAC,KAAAA,WAAW,QAAQ,GAAG;AAExB,QAAI,EAAE,gBAAgB;AAAkB,aAA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B,gBAAgB;AACnC,kBAAA,UAAU,MAAM,IAAI;AAAA,cACxB,KAAK;AAAA,cACL;AAAA,cACA,QAAQ;AAAA,cACR,QAAQ;AAAA,YAAA,CACT;AAEG,gBAAA;AAAS,kBAAI,KAAK,OAAO;AAAA,UAC/B;AAEA,cAAI,CAAC,IAAI,UAAU,CAAC,KAAK,gBAAgB;AACvC,kBAAM,IAAIC,YAAO,OAAA;AAAA,cACf,qBAAqB,UAAU,cAAc,YAAY;AAAA,YAAA;AAAA,UAE7D;AAEO,iBAAA;AAAA,QAAA;AAGH,cAAA,cAAc,4BAA4B,OAAc,MAAM;AACpE,YAAI,KAAK,WAAkB;AAAA,MAC7B;AAAA,IACF;AAAA,IACA,EAAE,QAAQ,OAAO,SAAS,KAAK,GAAG,EAAE;AAAA,IACpCJ;AAAA,EAAA;AAEJ;;"}
|
@@ -1,14 +1,15 @@
|
|
1
|
-
import { isObject, isNil } from "lodash/fp";
|
1
|
+
import { isObject, isNil, pick } from "lodash/fp";
|
2
2
|
import { traverseEntity, errors } from "@strapi/utils";
|
3
3
|
import { isShortHand, isLongHand } from "../utils/data.mjs";
|
4
4
|
import { getRelationTargetLocale } from "../utils/i18n.mjs";
|
5
|
+
import { getRelationTargetStatus } from "../utils/dp.mjs";
|
5
6
|
const isNumeric = (value) => {
|
6
7
|
if (Array.isArray(value))
|
7
8
|
return false;
|
8
9
|
const parsed = parseInt(value, 10);
|
9
10
|
return !Number.isNaN(parsed);
|
10
11
|
};
|
11
|
-
const transformPrimitive = (relation,
|
12
|
+
const transformPrimitive = (relation, getIds) => {
|
12
13
|
if (isNumeric(relation)) {
|
13
14
|
return relation;
|
14
15
|
}
|
@@ -16,48 +17,64 @@ const transformPrimitive = (relation, getId) => {
|
|
16
17
|
return relation;
|
17
18
|
}
|
18
19
|
if (isShortHand(relation)) {
|
19
|
-
|
20
|
+
const ids = getIds(relation);
|
21
|
+
if (ids?.length === 1)
|
22
|
+
return ids[0];
|
23
|
+
return ids;
|
20
24
|
}
|
21
25
|
if (isLongHand(relation)) {
|
22
26
|
if (!("documentId" in relation))
|
23
27
|
return relation;
|
24
|
-
const
|
25
|
-
if (!
|
28
|
+
const ids = getIds(relation.documentId, relation.locale, relation.status);
|
29
|
+
if (!ids?.length)
|
26
30
|
return void 0;
|
27
|
-
|
31
|
+
if (ids.length === 1)
|
32
|
+
return { id: ids[0], ...pick(["position"], relation) };
|
33
|
+
return ids.map((id) => ({ id, ...pick(["position"], relation) }));
|
28
34
|
}
|
29
35
|
if (Array.isArray(relation)) {
|
30
|
-
return relation.
|
36
|
+
return relation.flatMap((item) => transformPrimitive(item, getIds)).filter(Boolean);
|
31
37
|
}
|
32
38
|
return void 0;
|
33
39
|
};
|
34
|
-
const transformRelationIdsVisitor = (relation,
|
35
|
-
const map = transformPrimitive(relation,
|
40
|
+
const transformRelationIdsVisitor = (relation, getIds) => {
|
41
|
+
const map = transformPrimitive(relation, getIds);
|
36
42
|
if (map)
|
37
43
|
return map;
|
38
44
|
if (!isObject(relation))
|
39
45
|
return relation;
|
46
|
+
if (!("set" in relation) && !("disconnect" in relation) && !("connect" in relation)) {
|
47
|
+
return;
|
48
|
+
}
|
40
49
|
if ("set" in relation) {
|
41
|
-
relation.set = transformPrimitive(relation.set,
|
50
|
+
relation.set = transformPrimitive(relation.set, getIds);
|
42
51
|
}
|
43
52
|
if ("disconnect" in relation) {
|
44
|
-
relation.disconnect = transformPrimitive(relation.disconnect,
|
53
|
+
relation.disconnect = transformPrimitive(relation.disconnect, getIds);
|
45
54
|
}
|
46
55
|
if ("connect" in relation) {
|
47
|
-
relation.connect = transformPrimitive(relation.connect,
|
56
|
+
relation.connect = transformPrimitive(relation.connect, getIds);
|
48
57
|
const mapPosition = (relation2) => {
|
49
58
|
if (isShortHand(relation2) || !("position" in relation2))
|
50
59
|
return relation2;
|
51
|
-
const { position }
|
60
|
+
const position = { ...relation2?.position };
|
52
61
|
if (position?.before) {
|
53
|
-
const
|
54
|
-
|
62
|
+
const result = transformPrimitive({ ...position, documentId: position.before }, getIds);
|
63
|
+
if (Array.isArray(result)) {
|
64
|
+
position.before = result[0]?.id;
|
65
|
+
} else {
|
66
|
+
position.before = result?.id;
|
67
|
+
}
|
55
68
|
}
|
56
69
|
if (position?.after) {
|
57
|
-
const
|
58
|
-
|
70
|
+
const result = transformPrimitive({ ...position, documentId: position.after }, getIds);
|
71
|
+
if (Array.isArray(result)) {
|
72
|
+
position.after = result[0]?.id;
|
73
|
+
} else {
|
74
|
+
position.after = result?.id;
|
75
|
+
}
|
59
76
|
}
|
60
|
-
return relation2;
|
77
|
+
return { ...relation2, position };
|
61
78
|
};
|
62
79
|
if (Array.isArray(relation.connect)) {
|
63
80
|
relation.connect = relation.connect.map(mapPosition);
|
@@ -83,27 +100,34 @@ const transformDataIdsVisitor = (idMap, data, opts) => {
|
|
83
100
|
return;
|
84
101
|
if (EXCLUDED_FIELDS.includes(key))
|
85
102
|
return;
|
86
|
-
const
|
87
|
-
const
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
103
|
+
const getIds = (documentId, locale, status) => {
|
104
|
+
const targetLocale = getRelationTargetLocale(
|
105
|
+
{ documentId, locale },
|
106
|
+
{ targetUid: target, sourceUid: opts.uid, sourceLocale: opts.locale }
|
107
|
+
);
|
108
|
+
const targetStatuses = getRelationTargetStatus(
|
109
|
+
{ documentId, status },
|
110
|
+
{ targetUid: target, sourceUid: opts.uid, sourceStatus: opts.status }
|
111
|
+
);
|
112
|
+
const ids = [];
|
113
|
+
for (const targetStatus of targetStatuses) {
|
114
|
+
const entryId = idMap.get({
|
115
|
+
uid: target,
|
116
|
+
documentId,
|
117
|
+
locale: targetLocale,
|
118
|
+
status: targetStatus
|
119
|
+
});
|
120
|
+
if (entryId)
|
121
|
+
ids.push(entryId);
|
122
|
+
}
|
123
|
+
if (!ids.length && !opts.allowMissingId) {
|
124
|
+
throw new errors.ValidationError(
|
125
|
+
`Document with id "${documentId}", locale "${targetLocale}" not found`
|
126
|
+
);
|
127
|
+
}
|
128
|
+
return ids;
|
105
129
|
};
|
106
|
-
const newRelation = transformRelationIdsVisitor(value,
|
130
|
+
const newRelation = transformRelationIdsVisitor(value, getIds);
|
107
131
|
set(key, newRelation);
|
108
132
|
}
|
109
133
|
},
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"data-ids.mjs","sources":["../../../../../../src/services/document-service/transform/relations/transform/data-ids.ts"],"sourcesContent":["import { isObject, isNil } from 'lodash/fp';\n\nimport { EntityService, Attribute, Common } from '@strapi/types';\nimport { traverseEntity, errors } from '@strapi/utils';\n\nimport { ShortHand, LongHand, ID, GetId } from '../utils/types';\nimport { isShortHand, isLongHand } from '../utils/data';\nimport { IdMap } from '../../id-map';\nimport { getRelationTargetLocale } from '../utils/i18n';\n\nconst isNumeric = (value: any): value is number => {\n if (Array.isArray(value)) return false; // Handle [1, 'docId'] case\n const parsed = parseInt(value, 10);\n return !Number.isNaN(parsed);\n};\n\nconst transformPrimitive = <T extends ShortHand | LongHand>(\n relation: T | T[] | null | undefined,\n getId: GetId\n): T | T[] | undefined => {\n // TODO: Remove this, we should use the long hand version with 'id' for this case\n // If id value is a number, return it as is, it's already an entry id\n if (isNumeric(relation)) {\n return relation;\n }\n\n // null\n if (isNil(relation)) {\n return relation as T | undefined;\n }\n\n // id\n if (isShortHand(relation)) {\n return getId(relation) as T;\n }\n\n // { id }\n if (isLongHand(relation)) {\n // If the id is already an entry id, return it as is\n if (!('documentId' in relation)) return relation;\n\n // @ts-expect-error - TODO: Add relation type\n const entryId = getId(relation.documentId, relation.locale) as T;\n\n // If the id is not found, return undefined\n if (!entryId) return undefined;\n\n return { ...(relation as object), id: entryId } as T;\n }\n\n // id[]\n if (Array.isArray(relation)) {\n return relation.map((item) => transformPrimitive(item, getId)).filter(Boolean) as T[];\n }\n return undefined;\n};\n\nconst transformRelationIdsVisitor = <T extends Attribute.RelationKind.Any>(\n relation: EntityService.Params.Attribute.RelationInputValue<T>,\n getId: GetId\n): EntityService.Params.Attribute.RelationInputValue<T> => {\n const map = transformPrimitive(relation as any, getId);\n if (map) return map;\n\n if (!isObject(relation)) return relation;\n\n // set: id[]\n // what if result of mapPrimitive is undefined?\n if ('set' in relation) {\n relation.set = transformPrimitive(relation.set as any, getId);\n }\n if ('disconnect' in relation) {\n relation.disconnect = transformPrimitive(relation.disconnect as any, getId);\n }\n\n if ('connect' in relation) {\n // connect: id[] | { id } | ...\n relation.connect = transformPrimitive(relation.connect as any, getId);\n\n const mapPosition = (relation: any) => {\n if (isShortHand(relation) || !('position' in relation)) return relation;\n\n const { position } = relation;\n\n // { connect: { id: id, position: { before: id } } }\n if (position?.before) {\n const { id } = transformPrimitive({ ...position, documentId: position.before }, getId);\n position.before = id;\n }\n\n // { connect: { id: id, position: { after: id } } }\n if (position?.after) {\n const { id } = transformPrimitive({ ...position, documentId: position.after }, getId);\n position.after = id;\n }\n\n return relation;\n };\n\n if (Array.isArray(relation.connect)) {\n relation.connect = relation.connect.map(mapPosition);\n } else {\n relation.connect = mapPosition(relation.connect);\n }\n }\n\n return relation;\n};\n\nconst EXCLUDED_FIELDS = [\n 'createdBy',\n 'updatedBy',\n 'localizations',\n 'strapi_stage',\n 'strapi_assignee',\n];\n\nconst transformDataIdsVisitor = (\n idMap: IdMap,\n data: Record<string, any>,\n opts: {\n uid: Common.UID.Schema;\n locale?: string | null;\n isDraft?: boolean;\n allowMissingId?: boolean; // Whether to ignore missing ids and not throw any error\n }\n) => {\n return traverseEntity(\n ({ key, value, attribute }, { set }) => {\n // Find relational attributes, and return the document ids\n if (attribute.type === 'relation') {\n const target = attribute.target;\n // TODO: Handle polymorphic relations\n if (!target) return;\n // TODO: Handle this differently\n if (EXCLUDED_FIELDS.includes(key)) return;\n\n const getId = (documentId: ID, locale?: string): ID | null => {\n const entryId = idMap.get({\n uid: target,\n documentId,\n locale: getRelationTargetLocale(\n { documentId, locale },\n {\n targetUid: target as Common.UID.Schema,\n sourceUid: opts.uid,\n sourceLocale: opts.locale,\n }\n ),\n isDraft: opts.isDraft,\n });\n\n if (entryId) return entryId;\n if (opts.allowMissingId) return null;\n\n throw new errors.ValidationError(`Document with id \"${documentId}\" not found`);\n };\n\n const newRelation = transformRelationIdsVisitor(value as any, getId);\n set(key, newRelation as any);\n }\n },\n { schema: strapi.getModel(opts.uid) },\n data\n );\n};\n\nexport { transformDataIdsVisitor };\n"],"names":["relation"],"mappings":";;;;AAUA,MAAM,YAAY,CAAC,UAAgC;AAC7C,MAAA,MAAM,QAAQ,KAAK;AAAU,WAAA;AAC3B,QAAA,SAAS,SAAS,OAAO,EAAE;AAC1B,SAAA,CAAC,OAAO,MAAM,MAAM;AAC7B;AAEA,MAAM,qBAAqB,CACzB,UACA,UACwB;AAGpB,MAAA,UAAU,QAAQ,GAAG;AAChB,WAAA;AAAA,EACT;AAGI,MAAA,MAAM,QAAQ,GAAG;AACZ,WAAA;AAAA,EACT;AAGI,MAAA,YAAY,QAAQ,GAAG;AACzB,WAAO,MAAM,QAAQ;AAAA,EACvB;AAGI,MAAA,WAAW,QAAQ,GAAG;AAExB,QAAI,EAAE,gBAAgB;AAAkB,aAAA;AAGxC,UAAM,UAAU,MAAM,SAAS,YAAY,SAAS,MAAM;AAG1D,QAAI,CAAC;AAAgB,aAAA;AAErB,WAAO,EAAE,GAAI,UAAqB,IAAI,QAAQ;AAAA,EAChD;AAGI,MAAA,MAAM,QAAQ,QAAQ,GAAG;AACpB,WAAA,SAAS,IAAI,CAAC,SAAS,mBAAmB,MAAM,KAAK,CAAC,EAAE,OAAO,OAAO;AAAA,EAC/E;AACO,SAAA;AACT;AAEA,MAAM,8BAA8B,CAClC,UACA,UACyD;AACnD,QAAA,MAAM,mBAAmB,UAAiB,KAAK;AACjD,MAAA;AAAY,WAAA;AAEZ,MAAA,CAAC,SAAS,QAAQ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M,IAAI;AAAA,YACxB,KAAK;AAAA,YACL;AAAA,YACA,QAAQ;AAAA,cACN,EAAE,YAAY,OAAO;AAAA,cACrB;AAAA,gBACE,WAAW;AAAA,gBACX,WAAW,KAAK;AAAA,gBAChB,cAAc,KAAK;AAAA,cACrB;AAAA,YACF;AAAA,YACA,SAAS,KAAK;AAAA,UAAA,CACf;AAEG,cAAA;AAAgB,mBAAA;AACpB,cAAI,KAAK;AAAuB,mBAAA;AAEhC,gBAAM,IAAI,OAAO,gBAAgB,qBAAqB,UAAU,aAAa;AAAA,QAAA;AAGzE,cAAA,cAAc,4BAA4B,OAAc,KAAK;AACnE,YAAI,KAAK,WAAkB;AAAA,MAC7B;AAAA,IACF;AAAA,IACA,EAAE,QAAQ,OAAO,SAAS,KAAK,GAAG,EAAE;AAAA,IACpC;AAAA,EAAA;AAEJ;"}
|
1
|
+
{"version":3,"file":"data-ids.mjs","sources":["../../../../../../src/services/document-service/transform/relations/transform/data-ids.ts"],"sourcesContent":["import { isObject, isNil, pick } from 'lodash/fp';\n\nimport { EntityService, Attribute, Common } from '@strapi/types';\nimport { traverseEntity, errors } from '@strapi/utils';\n\nimport { ShortHand, LongHand, ID, GetIds } from '../utils/types';\nimport { isShortHand, isLongHand } from '../utils/data';\nimport { IdMap } from '../../id-map';\nimport { getRelationTargetLocale } from '../utils/i18n';\nimport { getRelationTargetStatus } from '../utils/dp';\n\nconst isNumeric = (value: any): value is number => {\n if (Array.isArray(value)) return false; // Handle [1, 'docId'] case\n const parsed = parseInt(value, 10);\n return !Number.isNaN(parsed);\n};\n\n/**\n * Transform primitive relation representation to entry ids\n *\n * docId -> id\n * [docId] -> [id]\n * { documentID, locale, status } -> { id }\n * [{ documentID, locale, status }] -> [{ id }]\n *\n * Note: There are scenarios where a single documentID can map to multiple ids.\n * By default the returned format will match the input format.\n * Only when the docID maps to multiple ids, an array will always be returned, regardless of the input format.\n */\nconst transformPrimitive = <T extends ShortHand | LongHand>(\n relation: T | T[] | null | undefined,\n getIds: GetIds\n): T | T[] | undefined => {\n // TODO: Remove this, we should use the long hand version with 'id' for this case\n // If id value is a number, return it as is, it's already an entry id\n if (isNumeric(relation)) {\n return relation;\n }\n\n // null\n if (isNil(relation)) {\n return relation as T | undefined;\n }\n\n // id\n if (isShortHand(relation)) {\n const ids = getIds(relation) as T[];\n\n // Return it with the same format for consistency\n if (ids?.length === 1) return ids[0];\n\n // Return an array if multiple ids are found\n return ids;\n }\n\n // { id }\n if (isLongHand(relation)) {\n // If the id is already an entry id, return it as is\n if (!('documentId' in relation)) return relation;\n\n // @ts-expect-error - TODO: Add relation type\n const ids = getIds(relation.documentId, relation.locale, relation.status);\n\n // No ids to connect\n if (!ids?.length) return undefined;\n\n // Return it with the same format for consistency\n if (ids.length === 1) return { id: ids[0], ...pick(['position'], relation) } as T;\n\n // Return an array if it multiple ids are found\n return ids.map((id: ID) => ({ id, ...pick(['position'], relation) })) as T[];\n }\n\n // id[]\n if (Array.isArray(relation)) {\n return relation.flatMap((item) => transformPrimitive(item, getIds)).filter(Boolean) as T[];\n }\n\n return undefined;\n};\n\n/**\n * Transform ids in any type of relation input value\n * - set: [docId]\n * - disconnect: [docId]\n * - connect: [docId]\n * Or using any of the other primitive representations\n */\nconst transformRelationIdsVisitor = <T extends Attribute.RelationKind.Any>(\n relation: EntityService.Params.Attribute.RelationInputValue<T>,\n getIds: GetIds\n): EntityService.Params.Attribute.RelationInputValue<T> | undefined => {\n const map = transformPrimitive(relation as any, getIds);\n if (map) return map;\n\n if (!isObject(relation)) return relation;\n\n if (!('set' in relation) && !('disconnect' in relation) && !('connect' in relation)) {\n // The entry id couldn't be found and there are no connection properties in\n // the relation, therefore we want to remove the relation\n return;\n }\n\n // set: id[]\n // what if result of mapPrimitive is undefined?\n if ('set' in relation) {\n relation.set = transformPrimitive(relation.set as any, getIds);\n }\n\n if ('disconnect' in relation) {\n relation.disconnect = transformPrimitive(relation.disconnect as any, getIds);\n }\n\n if ('connect' in relation) {\n // connect: id[] | { id } | ...\n relation.connect = transformPrimitive(relation.connect as any, getIds);\n\n const mapPosition = (relation: any) => {\n if (isShortHand(relation) || !('position' in relation)) return relation;\n\n const position = { ...relation?.position };\n\n // { connect: { id: id, position: { before: id } } }\n if (position?.before) {\n const result = transformPrimitive({ ...position, documentId: position.before }, getIds);\n\n if (Array.isArray(result)) {\n position.before = result[0]?.id;\n } else {\n position.before = result?.id;\n }\n }\n\n // { connect: { id: id, position: { after: id } } }\n if (position?.after) {\n const result = transformPrimitive({ ...position, documentId: position.after }, getIds);\n\n if (Array.isArray(result)) {\n position.after = result[0]?.id;\n } else {\n position.after = result?.id;\n }\n }\n\n return { ...relation, position };\n };\n\n if (Array.isArray(relation.connect)) {\n relation.connect = relation.connect.map(mapPosition);\n } else {\n relation.connect = mapPosition(relation.connect);\n }\n }\n\n return relation;\n};\n\nconst EXCLUDED_FIELDS = [\n 'createdBy',\n 'updatedBy',\n 'localizations',\n 'strapi_stage',\n 'strapi_assignee',\n];\n\nconst transformDataIdsVisitor = (\n idMap: IdMap,\n data: Record<string, any>,\n opts: {\n uid: Common.UID.Schema;\n locale?: string | null;\n status?: 'draft' | 'published';\n allowMissingId?: boolean; // Whether to ignore missing ids and not throw any error\n }\n) => {\n return traverseEntity(\n ({ key, value, attribute }, { set }) => {\n // Find relational attributes, and return the document ids\n if (attribute.type === 'relation') {\n const target = attribute.target as Common.UID.Schema | undefined;\n // TODO: Handle polymorphic relations\n if (!target) return;\n // TODO: V5 remove excluded fields and use { id: } syntax for those relations\n if (EXCLUDED_FIELDS.includes(key)) return;\n\n const getIds = (\n documentId: ID,\n locale?: string,\n status?: 'draft' | 'published'\n ): ID[] | null => {\n // locale to connect to\n const targetLocale = getRelationTargetLocale(\n { documentId, locale },\n { targetUid: target, sourceUid: opts.uid, sourceLocale: opts.locale }\n );\n\n // status(es) to connect to\n const targetStatuses = getRelationTargetStatus(\n { documentId, status },\n { targetUid: target, sourceUid: opts.uid, sourceStatus: opts.status }\n );\n\n const ids = [];\n\n // Find mapping between documentID -> id(s).\n // There are scenarios where a single documentID can map to multiple ids.\n // e.g when connecting Non DP -> DP and connecting to both the draft and publish version at the same time\n for (const targetStatus of targetStatuses) {\n const entryId = idMap.get({\n uid: target,\n documentId,\n locale: targetLocale,\n status: targetStatus,\n });\n\n if (entryId) ids.push(entryId);\n }\n\n if (!ids.length && !opts.allowMissingId) {\n throw new errors.ValidationError(\n `Document with id \"${documentId}\", locale \"${targetLocale}\" not found`\n );\n }\n\n return ids;\n };\n\n const newRelation = transformRelationIdsVisitor(value as any, getIds);\n set(key, newRelation as any);\n }\n },\n { schema: strapi.getModel(opts.uid) },\n data\n );\n};\n\nexport { transformDataIdsVisitor };\n"],"names":["relation"],"mappings":";;;;;AAWA,MAAM,YAAY,CAAC,UAAgC;AAC7C,MAAA,MAAM,QAAQ,KAAK;AAAU,WAAA;AAC3B,QAAA,SAAS,SAAS,OAAO,EAAE;AAC1B,SAAA,CAAC,OAAO,MAAM,MAAM;AAC7B;AAcA,MAAM,qBAAqB,CACzB,UACA,WACwB;AAGpB,MAAA,UAAU,QAAQ,GAAG;AAChB,WAAA;AAAA,EACT;AAGI,MAAA,MAAM,QAAQ,GAAG;AACZ,WAAA;AAAA,EACT;AAGI,MAAA,YAAY,QAAQ,GAAG;AACnB,UAAA,MAAM,OAAO,QAAQ;AAG3B,QAAI,KAAK,WAAW;AAAG,aAAO,IAAI,CAAC;AAG5B,WAAA;AAAA,EACT;AAGI,MAAA,WAAW,QAAQ,GAAG;AAExB,QAAI,EAAE,gBAAgB;AAAkB,aAAA;AAGxC,UAAM,MAAM,OAAO,SAAS,YAAY,SAAS,QAAQ,SAAS,MAAM;AAGxE,QAAI,CAAC,KAAK;AAAe,aAAA;AAGzB,QAAI,IAAI,WAAW;AAAU,aAAA,EAAE,IAAI,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC,UAAU,GAAG,QAAQ;AAGzE,WAAO,IAAI,IAAI,CAAC,QAAY,EAAE,IAAI,GAAG,KAAK,CAA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,iBAAA;AAAA,QAAA;AAGH,cAAA,cAAc,4BAA4B,OAAc,MAAM;AACpE,YAAI,KAAK,WAAkB;AAAA,MAC7B;AAAA,IACF;AAAA,IACA,EAAE,QAAQ,OAAO,SAAS,KAAK,GAAG,EAAE;AAAA,IACpC;AAAA,EAAA;AAEJ;"}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { Common } from '@strapi/types';
|
2
|
+
import { LongHandDocument } from './types';
|
3
|
+
type Status = 'draft' | 'published';
|
4
|
+
export declare const getRelationTargetStatus: (relation: Pick<LongHandDocument, 'documentId' | 'status'>, opts: {
|
5
|
+
targetUid: Common.UID.Schema;
|
6
|
+
sourceUid: Common.UID.Schema;
|
7
|
+
sourceStatus?: Status;
|
8
|
+
}) => Status[];
|
9
|
+
export {};
|
10
|
+
//# sourceMappingURL=dp.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"dp.d.ts","sourceRoot":"","sources":["../../../../../../src/services/document-service/transform/relations/utils/dp.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE3C,KAAK,MAAM,GAAG,OAAO,GAAG,WAAW,CAAC;AAEpC,eAAO,MAAM,uBAAuB,aACxB,KAAK,gBAAgB,EAAE,YAAY,GAAG,QAAQ,CAAC,QACnD;IACJ,SAAS,EAAE,OAAO,GAAG,CAAC,MAAM,CAAC;IAC7B,SAAS,EAAE,OAAO,GAAG,CAAC,MAAM,CAAC;IAC7B,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,KACA,MAAM,EA6BR,CAAC"}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
3
|
+
const _ = require("lodash/fp");
|
4
|
+
const strapiUtils = require("@strapi/utils");
|
5
|
+
const getRelationTargetStatus = (relation, opts) => {
|
6
|
+
const targetContentType = strapi.getModel(opts.targetUid);
|
7
|
+
const sourceContentType = strapi.getModel(opts.sourceUid);
|
8
|
+
const targetHasDP = strapiUtils.contentTypes.hasDraftAndPublish(targetContentType);
|
9
|
+
const sourceHasDP = strapiUtils.contentTypes.hasDraftAndPublish(sourceContentType);
|
10
|
+
if (!targetHasDP) {
|
11
|
+
return ["published"];
|
12
|
+
}
|
13
|
+
if (relation.status) {
|
14
|
+
return [relation.status];
|
15
|
+
}
|
16
|
+
if (!sourceHasDP) {
|
17
|
+
return ["draft", "published"];
|
18
|
+
}
|
19
|
+
if (!_.isNil(opts.sourceStatus)) {
|
20
|
+
return [opts.sourceStatus];
|
21
|
+
}
|
22
|
+
return ["draft"];
|
23
|
+
};
|
24
|
+
exports.getRelationTargetStatus = getRelationTargetStatus;
|
25
|
+
//# sourceMappingURL=dp.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"dp.js","sources":["../../../../../../src/services/document-service/transform/relations/utils/dp.ts"],"sourcesContent":["import { isNil } from 'lodash/fp';\n\nimport { contentTypes } from '@strapi/utils';\nimport { Common } from '@strapi/types';\n\nimport { LongHandDocument } from './types';\n\ntype Status = 'draft' | 'published';\n\nexport const getRelationTargetStatus = (\n relation: Pick<LongHandDocument, 'documentId' | 'status'>,\n opts: {\n targetUid: Common.UID.Schema;\n sourceUid: Common.UID.Schema;\n sourceStatus?: Status;\n }\n): Status[] => {\n // Ignore if the target content type does not have draft and publish enabled\n const targetContentType = strapi.getModel(opts.targetUid);\n const sourceContentType = strapi.getModel(opts.sourceUid);\n\n const targetHasDP = contentTypes.hasDraftAndPublish(targetContentType);\n const sourceHasDP = contentTypes.hasDraftAndPublish(sourceContentType);\n\n if (!targetHasDP) {\n return ['published'];\n }\n\n // priority:\n // DP Enabled 'relation status' -> 'source status' -> 'draft'\n // DP Disabled 'relation status' -> 'draft' and 'published'\n if (relation.status) {\n return [relation.status];\n }\n\n // Connect to both draft and published versions if dp is disabled and relation does not specify a status\n if (!sourceHasDP) {\n return ['draft', 'published'];\n }\n\n if (!isNil(opts.sourceStatus)) {\n return [opts.sourceStatus];\n }\n\n return ['draft'];\n};\n"],"names":["contentTypes","isNil"],"mappings":";;;;AASa,MAAA,0BAA0B,CACrC,UACA,SAKa;AAEb,QAAM,oBAAoB,OAAO,SAAS,KAAK,SAAS;AACxD,QAAM,oBAAoB,OAAO,SAAS,KAAK,SAAS;AAElD,QAAA,cAAcA,YAAAA,aAAa,mBAAmB,iBAAiB;AAC/D,QAAA,cAAcA,YAAAA,aAAa,mBAAmB,iBAAiB;AAErE,MAAI,CAAC,aAAa;AAChB,WAAO,CAAC,WAAW;AAAA,EACrB;AAKA,MAAI,SAAS,QAAQ;AACZ,WAAA,CAAC,SAAS,MAAM;AAAA,EACzB;AAGA,MAAI,CAAC,aAAa;AACT,WAAA,CAAC,SAAS,WAAW;AAAA,EAC9B;AAEA,MAAI,CAACC,EAAA,MAAM,KAAK,YAAY,GAAG;AACtB,WAAA,CAAC,KAAK,YAAY;AAAA,EAC3B;AAEA,SAAO,CAAC,OAAO;AACjB;;"}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import { isNil } from "lodash/fp";
|
2
|
+
import { contentTypes } from "@strapi/utils";
|
3
|
+
const getRelationTargetStatus = (relation, opts) => {
|
4
|
+
const targetContentType = strapi.getModel(opts.targetUid);
|
5
|
+
const sourceContentType = strapi.getModel(opts.sourceUid);
|
6
|
+
const targetHasDP = contentTypes.hasDraftAndPublish(targetContentType);
|
7
|
+
const sourceHasDP = contentTypes.hasDraftAndPublish(sourceContentType);
|
8
|
+
if (!targetHasDP) {
|
9
|
+
return ["published"];
|
10
|
+
}
|
11
|
+
if (relation.status) {
|
12
|
+
return [relation.status];
|
13
|
+
}
|
14
|
+
if (!sourceHasDP) {
|
15
|
+
return ["draft", "published"];
|
16
|
+
}
|
17
|
+
if (!isNil(opts.sourceStatus)) {
|
18
|
+
return [opts.sourceStatus];
|
19
|
+
}
|
20
|
+
return ["draft"];
|
21
|
+
};
|
22
|
+
export {
|
23
|
+
getRelationTargetStatus
|
24
|
+
};
|
25
|
+
//# sourceMappingURL=dp.mjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"dp.mjs","sources":["../../../../../../src/services/document-service/transform/relations/utils/dp.ts"],"sourcesContent":["import { isNil } from 'lodash/fp';\n\nimport { contentTypes } from '@strapi/utils';\nimport { Common } from '@strapi/types';\n\nimport { LongHandDocument } from './types';\n\ntype Status = 'draft' | 'published';\n\nexport const getRelationTargetStatus = (\n relation: Pick<LongHandDocument, 'documentId' | 'status'>,\n opts: {\n targetUid: Common.UID.Schema;\n sourceUid: Common.UID.Schema;\n sourceStatus?: Status;\n }\n): Status[] => {\n // Ignore if the target content type does not have draft and publish enabled\n const targetContentType = strapi.getModel(opts.targetUid);\n const sourceContentType = strapi.getModel(opts.sourceUid);\n\n const targetHasDP = contentTypes.hasDraftAndPublish(targetContentType);\n const sourceHasDP = contentTypes.hasDraftAndPublish(sourceContentType);\n\n if (!targetHasDP) {\n return ['published'];\n }\n\n // priority:\n // DP Enabled 'relation status' -> 'source status' -> 'draft'\n // DP Disabled 'relation status' -> 'draft' and 'published'\n if (relation.status) {\n return [relation.status];\n }\n\n // Connect to both draft and published versions if dp is disabled and relation does not specify a status\n if (!sourceHasDP) {\n return ['draft', 'published'];\n }\n\n if (!isNil(opts.sourceStatus)) {\n return [opts.sourceStatus];\n }\n\n return ['draft'];\n};\n"],"names":[],"mappings":";;AASa,MAAA,0BAA0B,CACrC,UACA,SAKa;AAEb,QAAM,oBAAoB,OAAO,SAAS,KAAK,SAAS;AACxD,QAAM,oBAAoB,OAAO,SAAS,KAAK,SAAS;AAElD,QAAA,cAAc,aAAa,mBAAmB,iBAAiB;AAC/D,QAAA,cAAc,aAAa,mBAAmB,iBAAiB;AAErE,MAAI,CAAC,aAAa;AAChB,WAAO,CAAC,WAAW;AAAA,EACrB;AAKA,MAAI,SAAS,QAAQ;AACZ,WAAA,CAAC,SAAS,MAAM;AAAA,EACzB;AAGA,MAAI,CAAC,aAAa;AACT,WAAA,CAAC,SAAS,WAAW;AAAA,EAC9B;AAEA,MAAI,CAAC,MAAM,KAAK,YAAY,GAAG;AACtB,WAAA,CAAC,KAAK,YAAY;AAAA,EAC3B;AAEA,SAAO,CAAC,OAAO;AACjB;"}
|
@@ -2,11 +2,14 @@ export type ID = string | number;
|
|
2
2
|
export type ShortHand = ID;
|
3
3
|
export type LongHandEntity = {
|
4
4
|
id: ID;
|
5
|
+
position?: object;
|
5
6
|
};
|
6
7
|
export type LongHandDocument = {
|
7
8
|
documentId: ID;
|
8
9
|
locale?: string;
|
10
|
+
status?: 'draft' | 'published';
|
11
|
+
position?: object;
|
9
12
|
};
|
10
13
|
export type LongHand = LongHandEntity | LongHandDocument;
|
11
|
-
export type
|
14
|
+
export type GetIds = (relation: ID) => ID[] | null;
|
12
15
|
//# sourceMappingURL=types.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../../src/services/document-service/transform/relations/utils/types.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,EAAE,GAAG,MAAM,GAAG,MAAM,CAAC;AACjC,MAAM,MAAM,SAAS,GAAG,EAAE,CAAC;AAE3B,MAAM,MAAM,cAAc,GAAG;IAAE,EAAE,EAAE,EAAE,CAAA;CAAE,CAAC;
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../../src/services/document-service/transform/relations/utils/types.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,EAAE,GAAG,MAAM,GAAG,MAAM,CAAC;AACjC,MAAM,MAAM,SAAS,GAAG,EAAE,CAAC;AAE3B,MAAM,MAAM,cAAc,GAAG;IAAE,EAAE,EAAE,EAAE,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAC3D,MAAM,MAAM,gBAAgB,GAAG;IAC7B,UAAU,EAAE,EAAE,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,GAAG,WAAW,CAAC;IAC/B,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AACF,MAAM,MAAM,QAAQ,GAAG,cAAc,GAAG,gBAAgB,CAAC;AAEzD,MAAM,MAAM,MAAM,GAAG,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,EAAE,GAAG,IAAI,CAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/services/document-service/transform/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,KAAK,EAAE,EAAE,MAAM,yBAAyB,CAAC;AAElD,MAAM,MAAM,IAAI,GAAG;IACjB,EAAE,CAAC,EAAE,EAAE,GAAG,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,EAAE,GAAG,MAAM,CAAC;IACzB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IACpB,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/services/document-service/transform/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,KAAK,EAAE,EAAE,MAAM,yBAAyB,CAAC;AAElD,MAAM,MAAM,IAAI,GAAG;IACjB,EAAE,CAAC,EAAE,EAAE,GAAG,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,EAAE,GAAG,MAAM,CAAC;IACzB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IACpB,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,MAAM,EAAE,OAAO,GAAG,WAAW,CAAC;CAC/B,CAAC"}
|
@@ -9,12 +9,12 @@ const getDeepPopulate = (uid) => {
|
|
9
9
|
case "relation": {
|
10
10
|
const isVisible = strapiUtils.contentTypes.isVisibleAttribute(model, attributeName);
|
11
11
|
if (isVisible) {
|
12
|
-
acc[attributeName] = {
|
12
|
+
acc[attributeName] = { select: ["document_id", "locale"] };
|
13
13
|
}
|
14
14
|
break;
|
15
15
|
}
|
16
16
|
case "media": {
|
17
|
-
acc[attributeName] = {
|
17
|
+
acc[attributeName] = { select: ["id"] };
|
18
18
|
break;
|
19
19
|
}
|
20
20
|
case "component": {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"populate.js","sources":["../../../../src/services/document-service/utils/populate.ts"],"sourcesContent":["import { Common } from '@strapi/types';\nimport { contentTypes } from '@strapi/utils';\n\n// We want to build a populate object based on the schema\nexport const getDeepPopulate = (uid: Common.UID.Schema) => {\n const model = strapi.getModel(uid);\n const attributes = Object.entries(model.attributes);\n\n return attributes.reduce((acc: any, [attributeName, attribute]) => {\n switch (attribute.type) {\n case 'relation': {\n // TODO: Should this just be a plain list?\n // Ignore createdBy, updatedBy, ...\n const isVisible = contentTypes.isVisibleAttribute(model, attributeName);\n if (isVisible) {\n acc[attributeName] = {
|
1
|
+
{"version":3,"file":"populate.js","sources":["../../../../src/services/document-service/utils/populate.ts"],"sourcesContent":["import { Common } from '@strapi/types';\nimport { contentTypes } from '@strapi/utils';\n\n// We want to build a populate object based on the schema\nexport const getDeepPopulate = (uid: Common.UID.Schema) => {\n const model = strapi.getModel(uid);\n const attributes = Object.entries(model.attributes);\n\n return attributes.reduce((acc: any, [attributeName, attribute]) => {\n switch (attribute.type) {\n case 'relation': {\n // TODO: Should this just be a plain list?\n // Ignore createdBy, updatedBy, ...\n const isVisible = contentTypes.isVisibleAttribute(model, attributeName);\n if (isVisible) {\n acc[attributeName] = { select: ['document_id', 'locale'] };\n }\n break;\n }\n\n case 'media': {\n acc[attributeName] = { select: ['id'] };\n break;\n }\n\n case 'component': {\n const populate = getDeepPopulate(attribute.component);\n acc[attributeName] = { populate };\n break;\n }\n\n case 'dynamiczone': {\n // Use fragments to populate the dynamic zone components\n const populatedComponents = (attribute.components || []).reduce(\n (acc: any, componentUID: Common.UID.Component) => {\n acc[componentUID] = { populate: getDeepPopulate(componentUID) };\n return acc;\n },\n {}\n );\n\n acc[attributeName] = { on: populatedComponents };\n break;\n }\n default:\n break;\n }\n\n return acc;\n }, {});\n};\n"],"names":["contentTypes","acc"],"mappings":";;;AAIa,MAAA,kBAAkB,CAAC,QAA2B;AACnD,QAAA,QAAQ,OAAO,SAAS,GAAG;AACjC,QAAM,aAAa,OAAO,QAAQ,MAAM,UAAU;AAElD,SAAO,WAAW,OAAO,CAAC,KAAU,CAAC,eAAe,SAAS,MAAM;AACjE,YAAQ,UAAU,MAAM;AAAA,MACtB,KAAK,YAAY;AAGf,cAAM,YAAYA,YAAA,aAAa,mBAAmB,OAAO,aAAa;AACtE,YAAI,WAAW;AACb,cAAI,aAAa,IAAI,EAAE,QAAQ,CAAC,eAAe,QAAQ;QACzD;AACA;AAAA,MACF;AAAA,MAEA,KAAK,SAAS;AACZ,YAAI,aAAa,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE;AACtC;AAAA,MACF;AAAA,MAEA,KAAK,aAAa;AACV,cAAA,WAAW,gBAAgB,UAAU,SAAS;AAChD,YAAA,aAAa,IAAI,EAAE;AACvB;AAAA,MACF;AAAA,MAEA,KAAK,eAAe;AAElB,cAAM,uBAAuB,UAAU,cAAc,CAAI,GAAA;AAAA,UACvD,CAACC,MAAU,iBAAuC;AAChDA,iBAAI,YAAY,IAAI,EAAE,UAAU,gBAAgB,YAAY;AACrDA,mBAAAA;AAAAA,UACT;AAAA,UACA,CAAC;AAAA,QAAA;AAGH,YAAI,aAAa,IAAI,EAAE,IAAI,oBAAoB;AAC/C;AAAA,MACF;AAAA,IAGF;AAEO,WAAA;AAAA,EACT,GAAG,CAAE,CAAA;AACP;;"}
|
@@ -7,12 +7,12 @@ const getDeepPopulate = (uid) => {
|
|
7
7
|
case "relation": {
|
8
8
|
const isVisible = contentTypes.isVisibleAttribute(model, attributeName);
|
9
9
|
if (isVisible) {
|
10
|
-
acc[attributeName] = {
|
10
|
+
acc[attributeName] = { select: ["document_id", "locale"] };
|
11
11
|
}
|
12
12
|
break;
|
13
13
|
}
|
14
14
|
case "media": {
|
15
|
-
acc[attributeName] = {
|
15
|
+
acc[attributeName] = { select: ["id"] };
|
16
16
|
break;
|
17
17
|
}
|
18
18
|
case "component": {
|