@strapi/core 5.45.1 → 5.46.1
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/core-api/routes/validation/attributes.d.ts +4 -4
- package/dist/core-api/routes/validation/attributes.d.ts.map +1 -1
- package/dist/core-api/routes/validation/attributes.js +6 -6
- package/dist/core-api/routes/validation/attributes.js.map +1 -1
- package/dist/core-api/routes/validation/attributes.mjs +6 -6
- package/dist/core-api/routes/validation/attributes.mjs.map +1 -1
- package/dist/core-api/routes/validation/component.js +1 -1
- package/dist/core-api/routes/validation/component.js.map +1 -1
- package/dist/core-api/routes/validation/component.mjs +1 -1
- package/dist/core-api/routes/validation/component.mjs.map +1 -1
- package/dist/core-api/routes/validation/content-type.js +2 -2
- package/dist/core-api/routes/validation/content-type.js.map +1 -1
- package/dist/core-api/routes/validation/content-type.mjs +2 -2
- package/dist/core-api/routes/validation/content-type.mjs.map +1 -1
- package/dist/core-api/routes/validation/mappers.d.ts +5 -5
- package/dist/core-api/routes/validation/mappers.d.ts.map +1 -1
- package/dist/core-api/routes/validation/mappers.js +13 -21
- package/dist/core-api/routes/validation/mappers.js.map +1 -1
- package/dist/core-api/routes/validation/mappers.mjs +13 -21
- package/dist/core-api/routes/validation/mappers.mjs.map +1 -1
- package/dist/core-api/routes/validation/utils.d.ts +3 -3
- package/dist/core-api/routes/validation/utils.d.ts.map +1 -1
- package/dist/core-api/routes/validation/utils.js +4 -7
- package/dist/core-api/routes/validation/utils.js.map +1 -1
- package/dist/core-api/routes/validation/utils.mjs +4 -7
- package/dist/core-api/routes/validation/utils.mjs.map +1 -1
- package/dist/migrations/database/5.0.0-discard-drafts.d.ts.map +1 -1
- package/dist/migrations/database/5.0.0-discard-drafts.js +23 -0
- package/dist/migrations/database/5.0.0-discard-drafts.js.map +1 -1
- package/dist/migrations/database/5.0.0-discard-drafts.mjs +23 -0
- package/dist/migrations/database/5.0.0-discard-drafts.mjs.map +1 -1
- package/dist/package.json.js +12 -12
- package/dist/package.json.mjs +12 -12
- package/dist/providers/session-manager.d.ts.map +1 -1
- package/dist/providers/session-manager.js +1 -2
- package/dist/providers/session-manager.js.map +1 -1
- package/dist/providers/session-manager.mjs +1 -2
- package/dist/providers/session-manager.mjs.map +1 -1
- package/dist/services/content-source-maps.d.ts.map +1 -1
- package/dist/services/content-source-maps.js +12 -4
- package/dist/services/content-source-maps.js.map +1 -1
- package/dist/services/content-source-maps.mjs +12 -4
- package/dist/services/content-source-maps.mjs.map +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 +4 -1
- 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 +4 -1
- 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.map +1 -1
- package/dist/services/document-service/transform/relations/transform/data-ids.js +4 -1
- 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 +4 -1
- package/dist/services/document-service/transform/relations/transform/data-ids.mjs.map +1 -1
- package/dist/services/document-service/transform/relations/utils/xto-one.d.ts +8 -0
- package/dist/services/document-service/transform/relations/utils/xto-one.d.ts.map +1 -0
- package/dist/services/document-service/transform/relations/utils/xto-one.js +41 -0
- package/dist/services/document-service/transform/relations/utils/xto-one.js.map +1 -0
- package/dist/services/document-service/transform/relations/utils/xto-one.mjs +39 -0
- package/dist/services/document-service/transform/relations/utils/xto-one.mjs.map +1 -0
- package/package.json +12 -12
package/dist/package.json.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var name = "@strapi/core";
|
|
6
|
-
var version = "5.
|
|
6
|
+
var version = "5.46.1";
|
|
7
7
|
var description = "Core of Strapi";
|
|
8
8
|
var homepage = "https://strapi.io";
|
|
9
9
|
var bugs = {
|
|
@@ -62,14 +62,14 @@ var dependencies = {
|
|
|
62
62
|
"@koa/cors": "5.0.0",
|
|
63
63
|
"@koa/router": "12.0.2",
|
|
64
64
|
"@paralleldrive/cuid2": "2.2.2",
|
|
65
|
-
"@strapi/admin": "5.
|
|
66
|
-
"@strapi/database": "5.
|
|
67
|
-
"@strapi/generators": "5.
|
|
68
|
-
"@strapi/logger": "5.
|
|
69
|
-
"@strapi/permissions": "5.
|
|
70
|
-
"@strapi/types": "5.
|
|
71
|
-
"@strapi/typescript-utils": "5.
|
|
72
|
-
"@strapi/utils": "5.
|
|
65
|
+
"@strapi/admin": "5.46.1",
|
|
66
|
+
"@strapi/database": "5.46.1",
|
|
67
|
+
"@strapi/generators": "5.46.1",
|
|
68
|
+
"@strapi/logger": "5.46.1",
|
|
69
|
+
"@strapi/permissions": "5.46.1",
|
|
70
|
+
"@strapi/types": "5.46.1",
|
|
71
|
+
"@strapi/typescript-utils": "5.46.1",
|
|
72
|
+
"@strapi/utils": "5.46.1",
|
|
73
73
|
"@vercel/stega": "0.1.2",
|
|
74
74
|
bcryptjs: "2.4.3",
|
|
75
75
|
boxen: "5.1.2",
|
|
@@ -136,11 +136,11 @@ var devDependencies = {
|
|
|
136
136
|
"@types/node": "24.10.0",
|
|
137
137
|
"@types/node-schedule": "2.1.7",
|
|
138
138
|
"@types/statuses": "2.0.1",
|
|
139
|
-
"eslint-config-custom": "5.
|
|
139
|
+
"eslint-config-custom": "5.46.1",
|
|
140
140
|
supertest: "7.2.2",
|
|
141
|
-
tsconfig: "5.
|
|
141
|
+
tsconfig: "5.46.1",
|
|
142
142
|
vitest: "catalog:",
|
|
143
|
-
"vitest-config": "5.
|
|
143
|
+
"vitest-config": "5.46.1"
|
|
144
144
|
};
|
|
145
145
|
var engines = {
|
|
146
146
|
node: ">=20.0.0 <=24.x.x",
|
package/dist/package.json.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
var name = "@strapi/core";
|
|
2
|
-
var version = "5.
|
|
2
|
+
var version = "5.46.1";
|
|
3
3
|
var description = "Core of Strapi";
|
|
4
4
|
var homepage = "https://strapi.io";
|
|
5
5
|
var bugs = {
|
|
@@ -58,14 +58,14 @@ var dependencies = {
|
|
|
58
58
|
"@koa/cors": "5.0.0",
|
|
59
59
|
"@koa/router": "12.0.2",
|
|
60
60
|
"@paralleldrive/cuid2": "2.2.2",
|
|
61
|
-
"@strapi/admin": "5.
|
|
62
|
-
"@strapi/database": "5.
|
|
63
|
-
"@strapi/generators": "5.
|
|
64
|
-
"@strapi/logger": "5.
|
|
65
|
-
"@strapi/permissions": "5.
|
|
66
|
-
"@strapi/types": "5.
|
|
67
|
-
"@strapi/typescript-utils": "5.
|
|
68
|
-
"@strapi/utils": "5.
|
|
61
|
+
"@strapi/admin": "5.46.1",
|
|
62
|
+
"@strapi/database": "5.46.1",
|
|
63
|
+
"@strapi/generators": "5.46.1",
|
|
64
|
+
"@strapi/logger": "5.46.1",
|
|
65
|
+
"@strapi/permissions": "5.46.1",
|
|
66
|
+
"@strapi/types": "5.46.1",
|
|
67
|
+
"@strapi/typescript-utils": "5.46.1",
|
|
68
|
+
"@strapi/utils": "5.46.1",
|
|
69
69
|
"@vercel/stega": "0.1.2",
|
|
70
70
|
bcryptjs: "2.4.3",
|
|
71
71
|
boxen: "5.1.2",
|
|
@@ -132,11 +132,11 @@ var devDependencies = {
|
|
|
132
132
|
"@types/node": "24.10.0",
|
|
133
133
|
"@types/node-schedule": "2.1.7",
|
|
134
134
|
"@types/statuses": "2.0.1",
|
|
135
|
-
"eslint-config-custom": "5.
|
|
135
|
+
"eslint-config-custom": "5.46.1",
|
|
136
136
|
supertest: "7.2.2",
|
|
137
|
-
tsconfig: "5.
|
|
137
|
+
tsconfig: "5.46.1",
|
|
138
138
|
vitest: "catalog:",
|
|
139
|
-
"vitest-config": "5.
|
|
139
|
+
"vitest-config": "5.46.1"
|
|
140
140
|
};
|
|
141
141
|
var engines = {
|
|
142
142
|
node: ">=20.0.0 <=24.x.x",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-manager.d.ts","sourceRoot":"","sources":["../../src/providers/session-manager.ts"],"names":[],"mappings":";AAIA,
|
|
1
|
+
{"version":3,"file":"session-manager.d.ts","sourceRoot":"","sources":["../../src/providers/session-manager.ts"],"names":[],"mappings":";AAIA,wBAmBG"}
|
|
@@ -9,8 +9,7 @@ var sessionManager = provider.defineProvider({
|
|
|
9
9
|
db: strapi.db
|
|
10
10
|
}));
|
|
11
11
|
},
|
|
12
|
-
async
|
|
13
|
-
// Get JWT secret from admin auth settings (same as admin token service)
|
|
12
|
+
async bootstrap (strapi) {
|
|
14
13
|
const adminAuth = strapi.config.get('admin.auth');
|
|
15
14
|
const jwtSecret = adminAuth?.secret;
|
|
16
15
|
if (!jwtSecret) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-manager.js","sources":["../../src/providers/session-manager.ts"],"sourcesContent":["import type { Core } from '@strapi/types';\nimport { defineProvider } from './provider';\nimport { createSessionManager } from '../services/session-manager';\n\nexport default defineProvider({\n init(strapi) {\n strapi.add('sessionManager', () =>\n createSessionManager({\n db: strapi.db,\n })\n );\n },\n\n async
|
|
1
|
+
{"version":3,"file":"session-manager.js","sources":["../../src/providers/session-manager.ts"],"sourcesContent":["import type { Core } from '@strapi/types';\nimport { defineProvider } from './provider';\nimport { createSessionManager } from '../services/session-manager';\n\nexport default defineProvider({\n init(strapi) {\n strapi.add('sessionManager', () =>\n createSessionManager({\n db: strapi.db,\n })\n );\n },\n\n async bootstrap(strapi) {\n const adminAuth = strapi.config.get<Core.Config.Admin['auth']>('admin.auth');\n const jwtSecret = adminAuth?.secret;\n\n if (!jwtSecret) {\n throw new Error(\n 'Missing admin.auth.secret configuration. The SessionManager requires a JWT secret'\n );\n }\n },\n});\n"],"names":["defineProvider","init","strapi","add","createSessionManager","db","bootstrap","adminAuth","config","get","jwtSecret","secret","Error"],"mappings":";;;;;AAIA,qBAAeA,uBAAAA,CAAe;AAC5BC,IAAAA,IAAAA,CAAAA,CAAKC,MAAM,EAAA;AACTA,QAAAA,MAAAA,CAAOC,GAAG,CAAC,gBAAA,EAAkB,IAC3BC,qCAAAA,CAAqB;AACnBC,gBAAAA,EAAAA,EAAIH,OAAOG;AACb,aAAA,CAAA,CAAA;AAEJ,IAAA,CAAA;AAEA,IAAA,MAAMC,WAAUJ,MAAM,EAAA;AACpB,QAAA,MAAMK,SAAAA,GAAYL,MAAAA,CAAOM,MAAM,CAACC,GAAG,CAA4B,YAAA,CAAA;AAC/D,QAAA,MAAMC,YAAYH,SAAAA,EAAWI,MAAAA;AAE7B,QAAA,IAAI,CAACD,SAAAA,EAAW;AACd,YAAA,MAAM,IAAIE,KAAAA,CACR,mFAAA,CAAA;AAEJ,QAAA;AACF,IAAA;AACF,CAAA,CAAA;;;;"}
|
|
@@ -7,8 +7,7 @@ var sessionManager = defineProvider({
|
|
|
7
7
|
db: strapi.db
|
|
8
8
|
}));
|
|
9
9
|
},
|
|
10
|
-
async
|
|
11
|
-
// Get JWT secret from admin auth settings (same as admin token service)
|
|
10
|
+
async bootstrap (strapi) {
|
|
12
11
|
const adminAuth = strapi.config.get('admin.auth');
|
|
13
12
|
const jwtSecret = adminAuth?.secret;
|
|
14
13
|
if (!jwtSecret) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-manager.mjs","sources":["../../src/providers/session-manager.ts"],"sourcesContent":["import type { Core } from '@strapi/types';\nimport { defineProvider } from './provider';\nimport { createSessionManager } from '../services/session-manager';\n\nexport default defineProvider({\n init(strapi) {\n strapi.add('sessionManager', () =>\n createSessionManager({\n db: strapi.db,\n })\n );\n },\n\n async
|
|
1
|
+
{"version":3,"file":"session-manager.mjs","sources":["../../src/providers/session-manager.ts"],"sourcesContent":["import type { Core } from '@strapi/types';\nimport { defineProvider } from './provider';\nimport { createSessionManager } from '../services/session-manager';\n\nexport default defineProvider({\n init(strapi) {\n strapi.add('sessionManager', () =>\n createSessionManager({\n db: strapi.db,\n })\n );\n },\n\n async bootstrap(strapi) {\n const adminAuth = strapi.config.get<Core.Config.Admin['auth']>('admin.auth');\n const jwtSecret = adminAuth?.secret;\n\n if (!jwtSecret) {\n throw new Error(\n 'Missing admin.auth.secret configuration. The SessionManager requires a JWT secret'\n );\n }\n },\n});\n"],"names":["defineProvider","init","strapi","add","createSessionManager","db","bootstrap","adminAuth","config","get","jwtSecret","secret","Error"],"mappings":";;;AAIA,qBAAeA,cAAAA,CAAe;AAC5BC,IAAAA,IAAAA,CAAAA,CAAKC,MAAM,EAAA;AACTA,QAAAA,MAAAA,CAAOC,GAAG,CAAC,gBAAA,EAAkB,IAC3BC,oBAAAA,CAAqB;AACnBC,gBAAAA,EAAAA,EAAIH,OAAOG;AACb,aAAA,CAAA,CAAA;AAEJ,IAAA,CAAA;AAEA,IAAA,MAAMC,WAAUJ,MAAM,EAAA;AACpB,QAAA,MAAMK,SAAAA,GAAYL,MAAAA,CAAOM,MAAM,CAACC,GAAG,CAA4B,YAAA,CAAA;AAC/D,QAAA,MAAMC,YAAYH,SAAAA,EAAWI,MAAAA;AAE7B,QAAA,IAAI,CAACD,SAAAA,EAAW;AACd,YAAA,MAAM,IAAIE,KAAAA,CACR,mFAAA,CAAA;AAEJ,QAAA;AACF,IAAA;AACF,CAAA,CAAA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content-source-maps.d.ts","sourceRoot":"","sources":["../../src/services/content-source-maps.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,EAAO,MAAM,eAAe,CAAC;AAEvD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAwCxE,UAAU,YAAY;IACpB,IAAI,EAAE,GAAG,CAAC;IACV,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC;CACvB;AAMD,QAAA,MAAM,8BAA8B,WAAY,KAAK,MAAM;sBAG/C,MAAM,mDACqC,qBAAqB;
|
|
1
|
+
{"version":3,"file":"content-source-maps.d.ts","sourceRoot":"","sources":["../../src/services/content-source-maps.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,EAAO,MAAM,eAAe,CAAC;AAEvD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAwCxE,UAAU,YAAY;IACpB,IAAI,EAAE,GAAG,CAAC;IACV,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC;CACvB;AAMD,QAAA,MAAM,8BAA8B,WAAY,KAAK,MAAM;sBAG/C,MAAM,mDACqC,qBAAqB;kCAiCpC,YAAY,GAAG,QAAQ,GAAG,CAAC;uCA6CtB,YAAY,GAAG,QAAQ,GAAG,CAAC;CAmBvE,CAAC;AAEF,OAAO,EAAE,8BAA8B,EAAE,CAAC"}
|
|
@@ -54,21 +54,29 @@ const createContentSourceMapsService = (strapi)=>{
|
|
|
54
54
|
if (locale) {
|
|
55
55
|
strapiSource.set('locale', locale);
|
|
56
56
|
}
|
|
57
|
-
|
|
57
|
+
const encoded = stega.vercelStegaCombine(text, {
|
|
58
58
|
strapiSource: strapiSource.toString()
|
|
59
|
-
});
|
|
59
|
+
}, false);
|
|
60
|
+
return encoded;
|
|
60
61
|
},
|
|
61
62
|
async encodeEntry ({ data, schema }) {
|
|
62
63
|
if (!isObject(data) || data === undefined) {
|
|
63
64
|
return data;
|
|
64
65
|
}
|
|
65
|
-
return strapiUtils.traverseEntity(({ key, value, attribute, schema, path }, { set })=>{
|
|
66
|
+
return strapiUtils.traverseEntity(({ key, value, attribute, schema, path, parent }, { set })=>{
|
|
66
67
|
if (!attribute || EXCLUDED_FIELDS.includes(key)) {
|
|
67
68
|
return;
|
|
68
69
|
}
|
|
69
70
|
if (ENCODABLE_TYPES.includes(attribute.type) && typeof value === 'string') {
|
|
71
|
+
// For inner fields of a multi-media field's items (e.g. `medias.0.url`),
|
|
72
|
+
// drop the array index so all items share the same encoded path. The
|
|
73
|
+
// preview groups them under one highlight and opens the multi-media
|
|
74
|
+
// input as a single field, matching the side editor.
|
|
75
|
+
const parentAttr = parent?.attribute;
|
|
76
|
+
const isInsideMultiMedia = parentAttr?.type === 'media' && parentAttr.multiple === true;
|
|
77
|
+
const encodedPath = isInsideMultiMedia && parent?.path?.rawWithIndices ? `${parent.path.rawWithIndices}.${key}` : path.rawWithIndices;
|
|
70
78
|
set(key, this.encodeField(value, {
|
|
71
|
-
path:
|
|
79
|
+
path: encodedPath,
|
|
72
80
|
type: attribute.type,
|
|
73
81
|
kind: schema.kind,
|
|
74
82
|
model: schema.uid,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content-source-maps.js","sources":["../../src/services/content-source-maps.ts"],"sourcesContent":["import { vercelStegaCombine } from '@vercel/stega';\nimport type { Core, Struct, UID } from '@strapi/types';\nimport { traverseEntity } from '@strapi/utils';\nimport type { FieldContentSourceMap } from '@strapi/admin/strapi-admin';\n\nconst ENCODABLE_TYPES = [\n 'string',\n 'text',\n 'richtext',\n 'biginteger',\n 'date',\n 'time',\n 'datetime',\n 'timestamp',\n 'boolean',\n 'enumeration',\n 'json',\n 'media',\n 'email',\n 'password',\n /**\n * We cannot modify the response shape, so types that aren't based on string cannot be encoded:\n * - json: object\n * - blocks: object, will require a custom implementation in a dedicated PR\n * - integer, float and decimal: number\n * - boolean: boolean (believe it or not)\n * - uid: can be stringified but would mess up URLs\n */\n];\n\n// TODO: use a centralized store for these fields that would be shared with the CM and CTB\nconst EXCLUDED_FIELDS = [\n 'id',\n 'documentId',\n 'locale',\n 'localizations',\n 'created_by',\n 'updated_by',\n 'created_at',\n 'updated_at',\n 'publishedAt',\n];\n\ninterface EncodingInfo {\n data: any;\n schema: Struct.Schema;\n}\n\nconst isObject = (value: unknown): value is Record<string, any> => {\n return typeof value === 'object' && value !== null;\n};\n\nconst createContentSourceMapsService = (strapi: Core.Strapi) => {\n return {\n encodeField(\n text: string,\n { kind, model, documentId, type, path, locale }: FieldContentSourceMap\n ) {\n /**\n * Combine all metadata into into a one string so we only have to deal with one data-atribute\n * on the frontend. Make it human readable because that data-attribute may be set manually by\n * users for fields that don't support sourcemap encoding.\n */\n const strapiSource = new URLSearchParams();\n strapiSource.set('documentId', documentId);\n strapiSource.set('type', type);\n strapiSource.set('path', path);\n\n if (model) {\n strapiSource.set('model', model);\n }\n if (kind) {\n strapiSource.set('kind', kind);\n }\n if (locale) {\n strapiSource.set('locale', locale);\n }\n\n
|
|
1
|
+
{"version":3,"file":"content-source-maps.js","sources":["../../src/services/content-source-maps.ts"],"sourcesContent":["import { vercelStegaCombine } from '@vercel/stega';\nimport type { Core, Struct, UID } from '@strapi/types';\nimport { traverseEntity } from '@strapi/utils';\nimport type { FieldContentSourceMap } from '@strapi/admin/strapi-admin';\n\nconst ENCODABLE_TYPES = [\n 'string',\n 'text',\n 'richtext',\n 'biginteger',\n 'date',\n 'time',\n 'datetime',\n 'timestamp',\n 'boolean',\n 'enumeration',\n 'json',\n 'media',\n 'email',\n 'password',\n /**\n * We cannot modify the response shape, so types that aren't based on string cannot be encoded:\n * - json: object\n * - blocks: object, will require a custom implementation in a dedicated PR\n * - integer, float and decimal: number\n * - boolean: boolean (believe it or not)\n * - uid: can be stringified but would mess up URLs\n */\n];\n\n// TODO: use a centralized store for these fields that would be shared with the CM and CTB\nconst EXCLUDED_FIELDS = [\n 'id',\n 'documentId',\n 'locale',\n 'localizations',\n 'created_by',\n 'updated_by',\n 'created_at',\n 'updated_at',\n 'publishedAt',\n];\n\ninterface EncodingInfo {\n data: any;\n schema: Struct.Schema;\n}\n\nconst isObject = (value: unknown): value is Record<string, any> => {\n return typeof value === 'object' && value !== null;\n};\n\nconst createContentSourceMapsService = (strapi: Core.Strapi) => {\n return {\n encodeField(\n text: string,\n { kind, model, documentId, type, path, locale }: FieldContentSourceMap\n ) {\n /**\n * Combine all metadata into into a one string so we only have to deal with one data-atribute\n * on the frontend. Make it human readable because that data-attribute may be set manually by\n * users for fields that don't support sourcemap encoding.\n */\n const strapiSource = new URLSearchParams();\n strapiSource.set('documentId', documentId);\n strapiSource.set('type', type);\n strapiSource.set('path', path);\n\n if (model) {\n strapiSource.set('model', model);\n }\n if (kind) {\n strapiSource.set('kind', kind);\n }\n if (locale) {\n strapiSource.set('locale', locale);\n }\n\n const encoded = vercelStegaCombine(\n text,\n {\n strapiSource: strapiSource.toString(),\n },\n false\n );\n\n return encoded;\n },\n\n async encodeEntry({ data, schema }: EncodingInfo): Promise<any> {\n if (!isObject(data) || data === undefined) {\n return data;\n }\n\n return traverseEntity(\n ({ key, value, attribute, schema, path, parent }, { set }) => {\n if (!attribute || EXCLUDED_FIELDS.includes(key)) {\n return;\n }\n\n if (ENCODABLE_TYPES.includes(attribute.type) && typeof value === 'string') {\n // For inner fields of a multi-media field's items (e.g. `medias.0.url`),\n // drop the array index so all items share the same encoded path. The\n // preview groups them under one highlight and opens the multi-media\n // input as a single field, matching the side editor.\n const parentAttr = parent?.attribute;\n const isInsideMultiMedia =\n parentAttr?.type === 'media' && (parentAttr as any).multiple === true;\n const encodedPath =\n isInsideMultiMedia && parent?.path?.rawWithIndices\n ? `${parent.path.rawWithIndices}.${key}`\n : path.rawWithIndices!;\n\n set(\n key,\n this.encodeField(value, {\n path: encodedPath,\n type: attribute.type,\n kind: schema.kind,\n model: schema.uid as UID.Schema,\n locale: data.locale,\n documentId: data.documentId,\n }) as any\n );\n }\n },\n {\n schema,\n getModel: (uid) => strapi.getModel(uid as UID.Schema),\n },\n data\n );\n },\n\n async encodeSourceMaps({ data, schema }: EncodingInfo): Promise<any> {\n try {\n if (Array.isArray(data)) {\n return await Promise.all(\n data.map((item) => this.encodeSourceMaps({ data: item, schema }))\n );\n }\n\n if (!isObject(data)) {\n return data;\n }\n\n return await this.encodeEntry({ data, schema });\n } catch (error) {\n strapi.log.error('Error encoding source maps:', error);\n return data;\n }\n },\n };\n};\n\nexport { createContentSourceMapsService };\n"],"names":["ENCODABLE_TYPES","EXCLUDED_FIELDS","isObject","value","createContentSourceMapsService","strapi","encodeField","text","kind","model","documentId","type","path","locale","strapiSource","URLSearchParams","set","encoded","vercelStegaCombine","toString","encodeEntry","data","schema","undefined","traverseEntity","key","attribute","parent","includes","parentAttr","isInsideMultiMedia","multiple","encodedPath","rawWithIndices","uid","getModel","encodeSourceMaps","Array","isArray","Promise","all","map","item","error","log"],"mappings":";;;;;AAKA,MAAMA,eAAAA,GAAkB;AACtB,IAAA,QAAA;AACA,IAAA,MAAA;AACA,IAAA,UAAA;AACA,IAAA,YAAA;AACA,IAAA,MAAA;AACA,IAAA,MAAA;AACA,IAAA,UAAA;AACA,IAAA,WAAA;AACA,IAAA,SAAA;AACA,IAAA,aAAA;AACA,IAAA,MAAA;AACA,IAAA,OAAA;AACA,IAAA,OAAA;AACA,IAAA;AASD,CAAA;AAED;AACA,MAAMC,eAAAA,GAAkB;AACtB,IAAA,IAAA;AACA,IAAA,YAAA;AACA,IAAA,QAAA;AACA,IAAA,eAAA;AACA,IAAA,YAAA;AACA,IAAA,YAAA;AACA,IAAA,YAAA;AACA,IAAA,YAAA;AACA,IAAA;AACD,CAAA;AAOD,MAAMC,WAAW,CAACC,KAAAA,GAAAA;IAChB,OAAO,OAAOA,KAAAA,KAAU,QAAA,IAAYA,KAAAA,KAAU,IAAA;AAChD,CAAA;AAEA,MAAMC,iCAAiC,CAACC,MAAAA,GAAAA;IACtC,OAAO;AACLC,QAAAA,WAAAA,CAAAA,CACEC,IAAY,EACZ,EAAEC,IAAI,EAAEC,KAAK,EAAEC,UAAU,EAAEC,IAAI,EAAEC,IAAI,EAAEC,MAAM,EAAyB,EAAA;AAEtE;;;;UAKA,MAAMC,eAAe,IAAIC,eAAAA,EAAAA;YACzBD,YAAAA,CAAaE,GAAG,CAAC,YAAA,EAAcN,UAAAA,CAAAA;YAC/BI,YAAAA,CAAaE,GAAG,CAAC,MAAA,EAAQL,IAAAA,CAAAA;YACzBG,YAAA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,WAAW,CAAC;AAAEC,oBAAAA,IAAAA;AAAMC,oBAAAA;AAAO,iBAAA,CAAA;AAC/C,YAAA,CAAA,CAAE,OAAOqB,KAAAA,EAAO;AACdtC,gBAAAA,MAAAA,CAAOuC,GAAG,CAACD,KAAK,CAAC,6BAAA,EAA+BA,KAAAA,CAAAA;gBAChD,OAAOtB,IAAAA;AACT,YAAA;AACF,QAAA;AACF,KAAA;AACF;;;;"}
|
|
@@ -52,21 +52,29 @@ const createContentSourceMapsService = (strapi)=>{
|
|
|
52
52
|
if (locale) {
|
|
53
53
|
strapiSource.set('locale', locale);
|
|
54
54
|
}
|
|
55
|
-
|
|
55
|
+
const encoded = vercelStegaCombine(text, {
|
|
56
56
|
strapiSource: strapiSource.toString()
|
|
57
|
-
});
|
|
57
|
+
}, false);
|
|
58
|
+
return encoded;
|
|
58
59
|
},
|
|
59
60
|
async encodeEntry ({ data, schema }) {
|
|
60
61
|
if (!isObject(data) || data === undefined) {
|
|
61
62
|
return data;
|
|
62
63
|
}
|
|
63
|
-
return traverseEntity(({ key, value, attribute, schema, path }, { set })=>{
|
|
64
|
+
return traverseEntity(({ key, value, attribute, schema, path, parent }, { set })=>{
|
|
64
65
|
if (!attribute || EXCLUDED_FIELDS.includes(key)) {
|
|
65
66
|
return;
|
|
66
67
|
}
|
|
67
68
|
if (ENCODABLE_TYPES.includes(attribute.type) && typeof value === 'string') {
|
|
69
|
+
// For inner fields of a multi-media field's items (e.g. `medias.0.url`),
|
|
70
|
+
// drop the array index so all items share the same encoded path. The
|
|
71
|
+
// preview groups them under one highlight and opens the multi-media
|
|
72
|
+
// input as a single field, matching the side editor.
|
|
73
|
+
const parentAttr = parent?.attribute;
|
|
74
|
+
const isInsideMultiMedia = parentAttr?.type === 'media' && parentAttr.multiple === true;
|
|
75
|
+
const encodedPath = isInsideMultiMedia && parent?.path?.rawWithIndices ? `${parent.path.rawWithIndices}.${key}` : path.rawWithIndices;
|
|
68
76
|
set(key, this.encodeField(value, {
|
|
69
|
-
path:
|
|
77
|
+
path: encodedPath,
|
|
70
78
|
type: attribute.type,
|
|
71
79
|
kind: schema.kind,
|
|
72
80
|
model: schema.uid,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content-source-maps.mjs","sources":["../../src/services/content-source-maps.ts"],"sourcesContent":["import { vercelStegaCombine } from '@vercel/stega';\nimport type { Core, Struct, UID } from '@strapi/types';\nimport { traverseEntity } from '@strapi/utils';\nimport type { FieldContentSourceMap } from '@strapi/admin/strapi-admin';\n\nconst ENCODABLE_TYPES = [\n 'string',\n 'text',\n 'richtext',\n 'biginteger',\n 'date',\n 'time',\n 'datetime',\n 'timestamp',\n 'boolean',\n 'enumeration',\n 'json',\n 'media',\n 'email',\n 'password',\n /**\n * We cannot modify the response shape, so types that aren't based on string cannot be encoded:\n * - json: object\n * - blocks: object, will require a custom implementation in a dedicated PR\n * - integer, float and decimal: number\n * - boolean: boolean (believe it or not)\n * - uid: can be stringified but would mess up URLs\n */\n];\n\n// TODO: use a centralized store for these fields that would be shared with the CM and CTB\nconst EXCLUDED_FIELDS = [\n 'id',\n 'documentId',\n 'locale',\n 'localizations',\n 'created_by',\n 'updated_by',\n 'created_at',\n 'updated_at',\n 'publishedAt',\n];\n\ninterface EncodingInfo {\n data: any;\n schema: Struct.Schema;\n}\n\nconst isObject = (value: unknown): value is Record<string, any> => {\n return typeof value === 'object' && value !== null;\n};\n\nconst createContentSourceMapsService = (strapi: Core.Strapi) => {\n return {\n encodeField(\n text: string,\n { kind, model, documentId, type, path, locale }: FieldContentSourceMap\n ) {\n /**\n * Combine all metadata into into a one string so we only have to deal with one data-atribute\n * on the frontend. Make it human readable because that data-attribute may be set manually by\n * users for fields that don't support sourcemap encoding.\n */\n const strapiSource = new URLSearchParams();\n strapiSource.set('documentId', documentId);\n strapiSource.set('type', type);\n strapiSource.set('path', path);\n\n if (model) {\n strapiSource.set('model', model);\n }\n if (kind) {\n strapiSource.set('kind', kind);\n }\n if (locale) {\n strapiSource.set('locale', locale);\n }\n\n
|
|
1
|
+
{"version":3,"file":"content-source-maps.mjs","sources":["../../src/services/content-source-maps.ts"],"sourcesContent":["import { vercelStegaCombine } from '@vercel/stega';\nimport type { Core, Struct, UID } from '@strapi/types';\nimport { traverseEntity } from '@strapi/utils';\nimport type { FieldContentSourceMap } from '@strapi/admin/strapi-admin';\n\nconst ENCODABLE_TYPES = [\n 'string',\n 'text',\n 'richtext',\n 'biginteger',\n 'date',\n 'time',\n 'datetime',\n 'timestamp',\n 'boolean',\n 'enumeration',\n 'json',\n 'media',\n 'email',\n 'password',\n /**\n * We cannot modify the response shape, so types that aren't based on string cannot be encoded:\n * - json: object\n * - blocks: object, will require a custom implementation in a dedicated PR\n * - integer, float and decimal: number\n * - boolean: boolean (believe it or not)\n * - uid: can be stringified but would mess up URLs\n */\n];\n\n// TODO: use a centralized store for these fields that would be shared with the CM and CTB\nconst EXCLUDED_FIELDS = [\n 'id',\n 'documentId',\n 'locale',\n 'localizations',\n 'created_by',\n 'updated_by',\n 'created_at',\n 'updated_at',\n 'publishedAt',\n];\n\ninterface EncodingInfo {\n data: any;\n schema: Struct.Schema;\n}\n\nconst isObject = (value: unknown): value is Record<string, any> => {\n return typeof value === 'object' && value !== null;\n};\n\nconst createContentSourceMapsService = (strapi: Core.Strapi) => {\n return {\n encodeField(\n text: string,\n { kind, model, documentId, type, path, locale }: FieldContentSourceMap\n ) {\n /**\n * Combine all metadata into into a one string so we only have to deal with one data-atribute\n * on the frontend. Make it human readable because that data-attribute may be set manually by\n * users for fields that don't support sourcemap encoding.\n */\n const strapiSource = new URLSearchParams();\n strapiSource.set('documentId', documentId);\n strapiSource.set('type', type);\n strapiSource.set('path', path);\n\n if (model) {\n strapiSource.set('model', model);\n }\n if (kind) {\n strapiSource.set('kind', kind);\n }\n if (locale) {\n strapiSource.set('locale', locale);\n }\n\n const encoded = vercelStegaCombine(\n text,\n {\n strapiSource: strapiSource.toString(),\n },\n false\n );\n\n return encoded;\n },\n\n async encodeEntry({ data, schema }: EncodingInfo): Promise<any> {\n if (!isObject(data) || data === undefined) {\n return data;\n }\n\n return traverseEntity(\n ({ key, value, attribute, schema, path, parent }, { set }) => {\n if (!attribute || EXCLUDED_FIELDS.includes(key)) {\n return;\n }\n\n if (ENCODABLE_TYPES.includes(attribute.type) && typeof value === 'string') {\n // For inner fields of a multi-media field's items (e.g. `medias.0.url`),\n // drop the array index so all items share the same encoded path. The\n // preview groups them under one highlight and opens the multi-media\n // input as a single field, matching the side editor.\n const parentAttr = parent?.attribute;\n const isInsideMultiMedia =\n parentAttr?.type === 'media' && (parentAttr as any).multiple === true;\n const encodedPath =\n isInsideMultiMedia && parent?.path?.rawWithIndices\n ? `${parent.path.rawWithIndices}.${key}`\n : path.rawWithIndices!;\n\n set(\n key,\n this.encodeField(value, {\n path: encodedPath,\n type: attribute.type,\n kind: schema.kind,\n model: schema.uid as UID.Schema,\n locale: data.locale,\n documentId: data.documentId,\n }) as any\n );\n }\n },\n {\n schema,\n getModel: (uid) => strapi.getModel(uid as UID.Schema),\n },\n data\n );\n },\n\n async encodeSourceMaps({ data, schema }: EncodingInfo): Promise<any> {\n try {\n if (Array.isArray(data)) {\n return await Promise.all(\n data.map((item) => this.encodeSourceMaps({ data: item, schema }))\n );\n }\n\n if (!isObject(data)) {\n return data;\n }\n\n return await this.encodeEntry({ data, schema });\n } catch (error) {\n strapi.log.error('Error encoding source maps:', error);\n return data;\n }\n },\n };\n};\n\nexport { createContentSourceMapsService };\n"],"names":["ENCODABLE_TYPES","EXCLUDED_FIELDS","isObject","value","createContentSourceMapsService","strapi","encodeField","text","kind","model","documentId","type","path","locale","strapiSource","URLSearchParams","set","encoded","vercelStegaCombine","toString","encodeEntry","data","schema","undefined","traverseEntity","key","attribute","parent","includes","parentAttr","isInsideMultiMedia","multiple","encodedPath","rawWithIndices","uid","getModel","encodeSourceMaps","Array","isArray","Promise","all","map","item","error","log"],"mappings":";;;AAKA,MAAMA,eAAAA,GAAkB;AACtB,IAAA,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-ids.d.ts","sourceRoot":"","sources":["../../../../../../src/services/document-service/transform/relations/extract/data-ids.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEzC,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"data-ids.d.ts","sourceRoot":"","sources":["../../../../../../src/services/document-service/transform/relations/extract/data-ids.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEzC,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AASrC,UAAU,OAAO;IACf,GAAG,EAAE,GAAG,CAAC,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,MAAM,CAAC,EAAE,OAAO,GAAG,WAAW,CAAC;CAChC;AA8BD;;;GAGG;AACH,QAAA,MAAM,cAAc,UAAW,KAAK,QAAQ,OAAO,MAAM,EAAE,GAAG,CAAC,UAAU,OAAO,qDA8C/E,CAAC;AAEF,OAAO,EAAE,cAAc,EAAE,CAAC"}
|
|
@@ -5,6 +5,7 @@ var strapiUtils = require('@strapi/utils');
|
|
|
5
5
|
var i18n = require('../utils/i18n.js');
|
|
6
6
|
var dp = require('../utils/dp.js');
|
|
7
7
|
var mapRelation = require('../utils/map-relation.js');
|
|
8
|
+
var xtoOne = require('../utils/xto-one.js');
|
|
8
9
|
|
|
9
10
|
const { isPolymorphic } = strapiUtils.relations;
|
|
10
11
|
/**
|
|
@@ -39,6 +40,8 @@ const { isPolymorphic } = strapiUtils.relations;
|
|
|
39
40
|
}
|
|
40
41
|
const isPolymorphicRelation = isPolymorphic(attribute);
|
|
41
42
|
const addDocId = addRelationDocId(idMap, source);
|
|
43
|
+
// Skip looking up entries we're about to discard.
|
|
44
|
+
const normalizedValue = xtoOne.normalizeXToOneRelationValue(attribute, value);
|
|
42
45
|
return mapRelation.mapRelation((relation)=>{
|
|
43
46
|
if (!relation || !relation.documentId) {
|
|
44
47
|
return relation;
|
|
@@ -69,7 +72,7 @@ const { isPolymorphic } = strapiUtils.relations;
|
|
|
69
72
|
});
|
|
70
73
|
}
|
|
71
74
|
return relation;
|
|
72
|
-
},
|
|
75
|
+
}, normalizedValue);
|
|
73
76
|
}, {
|
|
74
77
|
schema: strapi.getModel(source.uid),
|
|
75
78
|
getModel: strapi.getModel.bind(strapi)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-ids.js","sources":["../../../../../../src/services/document-service/transform/relations/extract/data-ids.ts"],"sourcesContent":["import { curry } from 'lodash/fp';\n\nimport type { UID } from '@strapi/types';\nimport { relations } from '@strapi/utils';\nimport { IdMap } from '../../id-map';\nimport { getRelationTargetLocale } from '../utils/i18n';\nimport { getRelationTargetStatus } from '../utils/dp';\nimport { mapRelation, traverseEntityRelations } from '../utils/map-relation';\nimport { LongHandDocument } from '../utils/types';\n\nconst { isPolymorphic } = relations;\n\ninterface Options {\n uid: UID.Schema;\n locale?: string | null;\n status?: 'draft' | 'published';\n}\n\n/**\n * Load a relation documentId into the idMap.\n */\nconst addRelationDocId = curry(\n (idMap: IdMap, source: Options, targetUid: UID.Schema, relation: LongHandDocument) => {\n const targetLocale = getRelationTargetLocale(relation, {\n targetUid,\n sourceUid: source.uid,\n sourceLocale: source.locale,\n });\n\n const targetStatus = getRelationTargetStatus(relation, {\n targetUid,\n sourceUid: source.uid,\n sourceStatus: source.status,\n });\n\n targetStatus.forEach((status) => {\n idMap.add({\n uid: targetUid,\n documentId: relation.documentId,\n locale: targetLocale,\n status,\n });\n });\n }\n);\n\n/**\n * Iterate over all relations of a data object and extract all relational document ids.\n * Those will later be transformed to entity ids.\n */\nconst extractDataIds = (idMap: IdMap, data: Record<string, any>, source: Options) => {\n return traverseEntityRelations(\n async ({ attribute, value }) => {\n if (!attribute) {\n return;\n }\n const isPolymorphicRelation = isPolymorphic(attribute);\n const addDocId = addRelationDocId(idMap, source);\n\n return mapRelation((relation) => {\n if (!relation || !relation.documentId) {\n return relation;\n }\n\n // Regular relations will always target the same target\n // if its a polymorphic relation we need to get it from the data itself\n const targetUid = isPolymorphicRelation ? relation.__type : attribute.target;\n\n addDocId(targetUid, relation);\n\n // Handle positional arguments\n const position = relation.position;\n\n // The positional relation target uid can be different for polymorphic relations\n let positionTargetUid = targetUid;\n if (isPolymorphicRelation && position?.__type) {\n positionTargetUid = position.__type;\n }\n\n if (position?.before) {\n addDocId(positionTargetUid, { ...relation, ...position, documentId: position.before });\n }\n\n if (position?.after) {\n addDocId(positionTargetUid, { ...relation, ...position, documentId: position.after });\n }\n\n return relation;\n },
|
|
1
|
+
{"version":3,"file":"data-ids.js","sources":["../../../../../../src/services/document-service/transform/relations/extract/data-ids.ts"],"sourcesContent":["import { curry } from 'lodash/fp';\n\nimport type { UID } from '@strapi/types';\nimport { relations } from '@strapi/utils';\nimport { IdMap } from '../../id-map';\nimport { getRelationTargetLocale } from '../utils/i18n';\nimport { getRelationTargetStatus } from '../utils/dp';\nimport { mapRelation, traverseEntityRelations } from '../utils/map-relation';\nimport { normalizeXToOneRelationValue } from '../utils/xto-one';\nimport { LongHandDocument } from '../utils/types';\n\nconst { isPolymorphic } = relations;\n\ninterface Options {\n uid: UID.Schema;\n locale?: string | null;\n status?: 'draft' | 'published';\n}\n\n/**\n * Load a relation documentId into the idMap.\n */\nconst addRelationDocId = curry(\n (idMap: IdMap, source: Options, targetUid: UID.Schema, relation: LongHandDocument) => {\n const targetLocale = getRelationTargetLocale(relation, {\n targetUid,\n sourceUid: source.uid,\n sourceLocale: source.locale,\n });\n\n const targetStatus = getRelationTargetStatus(relation, {\n targetUid,\n sourceUid: source.uid,\n sourceStatus: source.status,\n });\n\n targetStatus.forEach((status) => {\n idMap.add({\n uid: targetUid,\n documentId: relation.documentId,\n locale: targetLocale,\n status,\n });\n });\n }\n);\n\n/**\n * Iterate over all relations of a data object and extract all relational document ids.\n * Those will later be transformed to entity ids.\n */\nconst extractDataIds = (idMap: IdMap, data: Record<string, any>, source: Options) => {\n return traverseEntityRelations(\n async ({ attribute, value }) => {\n if (!attribute) {\n return;\n }\n const isPolymorphicRelation = isPolymorphic(attribute);\n const addDocId = addRelationDocId(idMap, source);\n\n // Skip looking up entries we're about to discard.\n const normalizedValue = normalizeXToOneRelationValue(attribute, value as any);\n\n return mapRelation((relation) => {\n if (!relation || !relation.documentId) {\n return relation;\n }\n\n // Regular relations will always target the same target\n // if its a polymorphic relation we need to get it from the data itself\n const targetUid = isPolymorphicRelation ? relation.__type : attribute.target;\n\n addDocId(targetUid, relation);\n\n // Handle positional arguments\n const position = relation.position;\n\n // The positional relation target uid can be different for polymorphic relations\n let positionTargetUid = targetUid;\n if (isPolymorphicRelation && position?.__type) {\n positionTargetUid = position.__type;\n }\n\n if (position?.before) {\n addDocId(positionTargetUid, { ...relation, ...position, documentId: position.before });\n }\n\n if (position?.after) {\n addDocId(positionTargetUid, { ...relation, ...position, documentId: position.after });\n }\n\n return relation;\n }, normalizedValue as any);\n },\n { schema: strapi.getModel(source.uid), getModel: strapi.getModel.bind(strapi) },\n data\n );\n};\n\nexport { extractDataIds };\n"],"names":["isPolymorphic","relations","addRelationDocId","curry","idMap","source","targetUid","relation","targetLocale","getRelationTargetLocale","sourceUid","uid","sourceLocale","locale","targetStatus","getRelationTargetStatus","sourceStatus","status","forEach","add","documentId","extractDataIds","data","traverseEntityRelations","attribute","value","isPolymorphicRelation","addDocId","normalizedValue","normalizeXToOneRelationValue","mapRelation","__type","target","position","positionTargetUid","before","after","schema","strapi","getModel","bind"],"mappings":";;;;;;;;;AAWA,MAAM,EAAEA,aAAa,EAAE,GAAGC,qBAAAA;AAQ1B;;AAEC,IACD,MAAMC,gBAAAA,GAAmBC,QAAAA,CACvB,CAACC,KAAAA,EAAcC,QAAiBC,SAAAA,EAAuBC,QAAAA,GAAAA;IACrD,MAAMC,YAAAA,GAAeC,6BAAwBF,QAAAA,EAAU;AACrDD,QAAAA,SAAAA;AACA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AAA,CAAAA;;YAGpB,MAAM0B,QAAAA,GAAW1B,SAAS0B,QAAQ;;AAGlC,YAAA,IAAIC,iBAAAA,GAAoB5B,SAAAA;YACxB,IAAIoB,qBAAAA,IAAyBO,UAAUF,MAAAA,EAAQ;AAC7CG,gBAAAA,iBAAAA,GAAoBD,SAASF,MAAM;AACrC,YAAA;AAEA,YAAA,IAAIE,UAAUE,MAAAA,EAAQ;AACpBR,gBAAAA,QAAAA,CAASO,iBAAAA,EAAmB;AAAE,oBAAA,GAAG3B,QAAQ;AAAE,oBAAA,GAAG0B,QAAQ;AAAEb,oBAAAA,UAAAA,EAAYa,SAASE;AAAO,iBAAA,CAAA;AACtF,YAAA;AAEA,YAAA,IAAIF,UAAUG,KAAAA,EAAO;AACnBT,gBAAAA,QAAAA,CAASO,iBAAAA,EAAmB;AAAE,oBAAA,GAAG3B,QAAQ;AAAE,oBAAA,GAAG0B,QAAQ;AAAEb,oBAAAA,UAAAA,EAAYa,SAASG;AAAM,iBAAA,CAAA;AACrF,YAAA;YAEA,OAAO7B,QAAAA;QACT,CAAA,EAAGqB,eAAAA,CAAAA;IACL,CAAA,EACA;AAAES,QAAAA,MAAAA,EAAQC,MAAAA,CAAOC,QAAQ,CAAClC,MAAAA,CAAOM,GAAG,CAAA;AAAG4B,QAAAA,QAAAA,EAAUD,MAAAA,CAAOC,QAAQ,CAACC,IAAI,CAACF,MAAAA;KAAQ,EAC9EhB,IAAAA,CAAAA;AAEJ;;;;"}
|
|
@@ -3,6 +3,7 @@ import { relations } from '@strapi/utils';
|
|
|
3
3
|
import { getRelationTargetLocale } from '../utils/i18n.mjs';
|
|
4
4
|
import { getRelationTargetStatus } from '../utils/dp.mjs';
|
|
5
5
|
import { traverseEntityRelations as traverseEntityRelationsCurried, mapRelation as mapRelationCurried } from '../utils/map-relation.mjs';
|
|
6
|
+
import { normalizeXToOneRelationValue } from '../utils/xto-one.mjs';
|
|
6
7
|
|
|
7
8
|
const { isPolymorphic } = relations;
|
|
8
9
|
/**
|
|
@@ -37,6 +38,8 @@ const { isPolymorphic } = relations;
|
|
|
37
38
|
}
|
|
38
39
|
const isPolymorphicRelation = isPolymorphic(attribute);
|
|
39
40
|
const addDocId = addRelationDocId(idMap, source);
|
|
41
|
+
// Skip looking up entries we're about to discard.
|
|
42
|
+
const normalizedValue = normalizeXToOneRelationValue(attribute, value);
|
|
40
43
|
return mapRelationCurried((relation)=>{
|
|
41
44
|
if (!relation || !relation.documentId) {
|
|
42
45
|
return relation;
|
|
@@ -67,7 +70,7 @@ const { isPolymorphic } = relations;
|
|
|
67
70
|
});
|
|
68
71
|
}
|
|
69
72
|
return relation;
|
|
70
|
-
},
|
|
73
|
+
}, normalizedValue);
|
|
71
74
|
}, {
|
|
72
75
|
schema: strapi.getModel(source.uid),
|
|
73
76
|
getModel: strapi.getModel.bind(strapi)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-ids.mjs","sources":["../../../../../../src/services/document-service/transform/relations/extract/data-ids.ts"],"sourcesContent":["import { curry } from 'lodash/fp';\n\nimport type { UID } from '@strapi/types';\nimport { relations } from '@strapi/utils';\nimport { IdMap } from '../../id-map';\nimport { getRelationTargetLocale } from '../utils/i18n';\nimport { getRelationTargetStatus } from '../utils/dp';\nimport { mapRelation, traverseEntityRelations } from '../utils/map-relation';\nimport { LongHandDocument } from '../utils/types';\n\nconst { isPolymorphic } = relations;\n\ninterface Options {\n uid: UID.Schema;\n locale?: string | null;\n status?: 'draft' | 'published';\n}\n\n/**\n * Load a relation documentId into the idMap.\n */\nconst addRelationDocId = curry(\n (idMap: IdMap, source: Options, targetUid: UID.Schema, relation: LongHandDocument) => {\n const targetLocale = getRelationTargetLocale(relation, {\n targetUid,\n sourceUid: source.uid,\n sourceLocale: source.locale,\n });\n\n const targetStatus = getRelationTargetStatus(relation, {\n targetUid,\n sourceUid: source.uid,\n sourceStatus: source.status,\n });\n\n targetStatus.forEach((status) => {\n idMap.add({\n uid: targetUid,\n documentId: relation.documentId,\n locale: targetLocale,\n status,\n });\n });\n }\n);\n\n/**\n * Iterate over all relations of a data object and extract all relational document ids.\n * Those will later be transformed to entity ids.\n */\nconst extractDataIds = (idMap: IdMap, data: Record<string, any>, source: Options) => {\n return traverseEntityRelations(\n async ({ attribute, value }) => {\n if (!attribute) {\n return;\n }\n const isPolymorphicRelation = isPolymorphic(attribute);\n const addDocId = addRelationDocId(idMap, source);\n\n return mapRelation((relation) => {\n if (!relation || !relation.documentId) {\n return relation;\n }\n\n // Regular relations will always target the same target\n // if its a polymorphic relation we need to get it from the data itself\n const targetUid = isPolymorphicRelation ? relation.__type : attribute.target;\n\n addDocId(targetUid, relation);\n\n // Handle positional arguments\n const position = relation.position;\n\n // The positional relation target uid can be different for polymorphic relations\n let positionTargetUid = targetUid;\n if (isPolymorphicRelation && position?.__type) {\n positionTargetUid = position.__type;\n }\n\n if (position?.before) {\n addDocId(positionTargetUid, { ...relation, ...position, documentId: position.before });\n }\n\n if (position?.after) {\n addDocId(positionTargetUid, { ...relation, ...position, documentId: position.after });\n }\n\n return relation;\n },
|
|
1
|
+
{"version":3,"file":"data-ids.mjs","sources":["../../../../../../src/services/document-service/transform/relations/extract/data-ids.ts"],"sourcesContent":["import { curry } from 'lodash/fp';\n\nimport type { UID } from '@strapi/types';\nimport { relations } from '@strapi/utils';\nimport { IdMap } from '../../id-map';\nimport { getRelationTargetLocale } from '../utils/i18n';\nimport { getRelationTargetStatus } from '../utils/dp';\nimport { mapRelation, traverseEntityRelations } from '../utils/map-relation';\nimport { normalizeXToOneRelationValue } from '../utils/xto-one';\nimport { LongHandDocument } from '../utils/types';\n\nconst { isPolymorphic } = relations;\n\ninterface Options {\n uid: UID.Schema;\n locale?: string | null;\n status?: 'draft' | 'published';\n}\n\n/**\n * Load a relation documentId into the idMap.\n */\nconst addRelationDocId = curry(\n (idMap: IdMap, source: Options, targetUid: UID.Schema, relation: LongHandDocument) => {\n const targetLocale = getRelationTargetLocale(relation, {\n targetUid,\n sourceUid: source.uid,\n sourceLocale: source.locale,\n });\n\n const targetStatus = getRelationTargetStatus(relation, {\n targetUid,\n sourceUid: source.uid,\n sourceStatus: source.status,\n });\n\n targetStatus.forEach((status) => {\n idMap.add({\n uid: targetUid,\n documentId: relation.documentId,\n locale: targetLocale,\n status,\n });\n });\n }\n);\n\n/**\n * Iterate over all relations of a data object and extract all relational document ids.\n * Those will later be transformed to entity ids.\n */\nconst extractDataIds = (idMap: IdMap, data: Record<string, any>, source: Options) => {\n return traverseEntityRelations(\n async ({ attribute, value }) => {\n if (!attribute) {\n return;\n }\n const isPolymorphicRelation = isPolymorphic(attribute);\n const addDocId = addRelationDocId(idMap, source);\n\n // Skip looking up entries we're about to discard.\n const normalizedValue = normalizeXToOneRelationValue(attribute, value as any);\n\n return mapRelation((relation) => {\n if (!relation || !relation.documentId) {\n return relation;\n }\n\n // Regular relations will always target the same target\n // if its a polymorphic relation we need to get it from the data itself\n const targetUid = isPolymorphicRelation ? relation.__type : attribute.target;\n\n addDocId(targetUid, relation);\n\n // Handle positional arguments\n const position = relation.position;\n\n // The positional relation target uid can be different for polymorphic relations\n let positionTargetUid = targetUid;\n if (isPolymorphicRelation && position?.__type) {\n positionTargetUid = position.__type;\n }\n\n if (position?.before) {\n addDocId(positionTargetUid, { ...relation, ...position, documentId: position.before });\n }\n\n if (position?.after) {\n addDocId(positionTargetUid, { ...relation, ...position, documentId: position.after });\n }\n\n return relation;\n }, normalizedValue as any);\n },\n { schema: strapi.getModel(source.uid), getModel: strapi.getModel.bind(strapi) },\n data\n );\n};\n\nexport { extractDataIds };\n"],"names":["isPolymorphic","relations","addRelationDocId","curry","idMap","source","targetUid","relation","targetLocale","getRelationTargetLocale","sourceUid","uid","sourceLocale","locale","targetStatus","getRelationTargetStatus","sourceStatus","status","forEach","add","documentId","extractDataIds","data","traverseEntityRelations","attribute","value","isPolymorphicRelation","addDocId","normalizedValue","normalizeXToOneRelationValue","mapRelation","__type","target","position","positionTargetUid","before","after","schema","strapi","getModel","bind"],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":"","sources":["../../../../../../src/services/document-service/transform/relations/transform/data-ids.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAIzC,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,KAAK,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAIzC,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAQrC,UAAU,OAAO;IACf,GAAG,EAAE,GAAG,CAAC,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,MAAM,CAAC,EAAE,OAAO,GAAG,WAAW,CAAC;IAC/B,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AA+CD;;GAEG;AACH,QAAA,MAAM,uBAAuB,UAAW,KAAK,QAAQ,OAAO,MAAM,EAAE,GAAG,CAAC,UAAU,OAAO,qDAiExF,CAAC;AAEF,OAAO,EAAE,uBAAuB,EAAE,CAAC"}
|
|
@@ -5,6 +5,7 @@ var strapiUtils = require('@strapi/utils');
|
|
|
5
5
|
var i18n = require('../utils/i18n.js');
|
|
6
6
|
var dp = require('../utils/dp.js');
|
|
7
7
|
var mapRelation = require('../utils/map-relation.js');
|
|
8
|
+
var xtoOne = require('../utils/xto-one.js');
|
|
8
9
|
|
|
9
10
|
const { isPolymorphic } = strapiUtils.relations;
|
|
10
11
|
/**
|
|
@@ -49,6 +50,8 @@ const { isPolymorphic } = strapiUtils.relations;
|
|
|
49
50
|
}
|
|
50
51
|
const isPolymorphicRelation = isPolymorphic(attribute);
|
|
51
52
|
const getIds = getRelationIds(idMap, source);
|
|
53
|
+
// Collapse a "relates to one" payload to a single entry first.
|
|
54
|
+
const normalizedValue = xtoOne.normalizeXToOneRelationValue(attribute, value);
|
|
52
55
|
// Transform the relation documentId to entity id
|
|
53
56
|
const newRelation = await mapRelation.mapRelation((relation)=>{
|
|
54
57
|
if (!relation || !relation.documentId) {
|
|
@@ -98,7 +101,7 @@ const { isPolymorphic } = strapiUtils.relations;
|
|
|
98
101
|
}
|
|
99
102
|
return newRelation;
|
|
100
103
|
});
|
|
101
|
-
},
|
|
104
|
+
}, normalizedValue);
|
|
102
105
|
set(key, newRelation);
|
|
103
106
|
}, {
|
|
104
107
|
schema: strapi.getModel(source.uid),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-ids.js","sources":["../../../../../../src/services/document-service/transform/relations/transform/data-ids.ts"],"sourcesContent":["import { curry } from 'lodash/fp';\n\nimport type { UID } from '@strapi/types';\nimport { errors, relations } from '@strapi/utils';\n\nimport { ID, LongHandDocument } from '../utils/types';\nimport { IdMap } from '../../id-map';\nimport { getRelationTargetLocale } from '../utils/i18n';\nimport { getRelationTargetStatus } from '../utils/dp';\nimport { mapRelation, traverseEntityRelations } from '../utils/map-relation';\n\nconst { isPolymorphic } = relations;\n\ninterface Options {\n uid: 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/**\n * Get the entry ids for a given documentId.\n */\nconst getRelationIds = curry(\n (idMap: IdMap, source: Options, targetUid: UID.Schema, relation: LongHandDocument) => {\n // locale to connect to\n const targetLocale = getRelationTargetLocale(relation, {\n targetUid,\n sourceUid: source.uid,\n sourceLocale: source.locale,\n });\n\n // status(es) to connect to\n const targetStatus = getRelationTargetStatus(relation, {\n targetUid,\n sourceUid: source.uid,\n sourceStatus: source.status,\n });\n\n const ids: ID[] = [];\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 tStatus of targetStatus) {\n const entryId = idMap.get({\n uid: targetUid,\n documentId: relation.documentId,\n locale: targetLocale,\n status: tStatus,\n });\n\n if (entryId) ids.push(entryId);\n }\n\n if (!ids.length && !source.allowMissingId) {\n throw new errors.ValidationError(\n `Document with id \"${relation.documentId}\", locale \"${targetLocale}\" not found`\n );\n }\n\n return ids;\n }\n);\n\n/**\n * Iterate over all relations of a data object and transform all relational document ids to entity ids.\n */\nconst transformDataIdsVisitor = (idMap: IdMap, data: Record<string, any>, source: Options) => {\n return traverseEntityRelations(\n async ({ key, value, attribute }, { set }) => {\n if (!attribute) {\n return;\n }\n const isPolymorphicRelation = isPolymorphic(attribute);\n const getIds = getRelationIds(idMap, source);\n\n // Transform the relation documentId to entity id\n const newRelation = await mapRelation((relation) => {\n if (!relation || !relation.documentId) {\n return relation;\n }\n\n // Find relational attributes, and return the document ids\n // if its a polymorphic relation we need to get it from the data itself\n const targetUid: UID.Schema = isPolymorphicRelation ? relation.__type : attribute.target;\n const ids: ID[] = getIds(targetUid, relation);\n\n // Handle positional arguments\n const position = { ...relation.position };\n\n // The positional relation target uid can be different for polymorphic relations\n let positionTargetUid: UID.Schema = targetUid;\n if (isPolymorphicRelation && position?.__type) {\n positionTargetUid = position.__type;\n }\n\n if (position.before) {\n const beforeRelation = { ...relation, ...position, documentId: position.before };\n const beforeIds: ID[] = getIds(positionTargetUid, beforeRelation);\n position.before = beforeIds.at(0);\n }\n\n if (position.after) {\n const afterRelation = { ...relation, ...position, documentId: position.after };\n position.after = getIds(positionTargetUid, afterRelation).at(0);\n }\n\n // Transform all ids to new relations\n return ids?.map((id) => {\n const newRelation = { id } as typeof relation;\n\n if (relation.position) {\n newRelation.position = position;\n }\n\n // Insert type if its a polymorphic relation\n if (isPolymorphicRelation) {\n newRelation.__type = targetUid;\n }\n\n return newRelation;\n });\n },
|
|
1
|
+
{"version":3,"file":"data-ids.js","sources":["../../../../../../src/services/document-service/transform/relations/transform/data-ids.ts"],"sourcesContent":["import { curry } from 'lodash/fp';\n\nimport type { UID } from '@strapi/types';\nimport { errors, relations } from '@strapi/utils';\n\nimport { ID, LongHandDocument } from '../utils/types';\nimport { IdMap } from '../../id-map';\nimport { getRelationTargetLocale } from '../utils/i18n';\nimport { getRelationTargetStatus } from '../utils/dp';\nimport { mapRelation, traverseEntityRelations } from '../utils/map-relation';\nimport { normalizeXToOneRelationValue } from '../utils/xto-one';\n\nconst { isPolymorphic } = relations;\n\ninterface Options {\n uid: 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/**\n * Get the entry ids for a given documentId.\n */\nconst getRelationIds = curry(\n (idMap: IdMap, source: Options, targetUid: UID.Schema, relation: LongHandDocument) => {\n // locale to connect to\n const targetLocale = getRelationTargetLocale(relation, {\n targetUid,\n sourceUid: source.uid,\n sourceLocale: source.locale,\n });\n\n // status(es) to connect to\n const targetStatus = getRelationTargetStatus(relation, {\n targetUid,\n sourceUid: source.uid,\n sourceStatus: source.status,\n });\n\n const ids: ID[] = [];\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 tStatus of targetStatus) {\n const entryId = idMap.get({\n uid: targetUid,\n documentId: relation.documentId,\n locale: targetLocale,\n status: tStatus,\n });\n\n if (entryId) ids.push(entryId);\n }\n\n if (!ids.length && !source.allowMissingId) {\n throw new errors.ValidationError(\n `Document with id \"${relation.documentId}\", locale \"${targetLocale}\" not found`\n );\n }\n\n return ids;\n }\n);\n\n/**\n * Iterate over all relations of a data object and transform all relational document ids to entity ids.\n */\nconst transformDataIdsVisitor = (idMap: IdMap, data: Record<string, any>, source: Options) => {\n return traverseEntityRelations(\n async ({ key, value, attribute }, { set }) => {\n if (!attribute) {\n return;\n }\n const isPolymorphicRelation = isPolymorphic(attribute);\n const getIds = getRelationIds(idMap, source);\n\n // Collapse a \"relates to one\" payload to a single entry first.\n const normalizedValue = normalizeXToOneRelationValue(attribute, value as any);\n\n // Transform the relation documentId to entity id\n const newRelation = await mapRelation((relation) => {\n if (!relation || !relation.documentId) {\n return relation;\n }\n\n // Find relational attributes, and return the document ids\n // if its a polymorphic relation we need to get it from the data itself\n const targetUid: UID.Schema = isPolymorphicRelation ? relation.__type : attribute.target;\n const ids: ID[] = getIds(targetUid, relation);\n\n // Handle positional arguments\n const position = { ...relation.position };\n\n // The positional relation target uid can be different for polymorphic relations\n let positionTargetUid: UID.Schema = targetUid;\n if (isPolymorphicRelation && position?.__type) {\n positionTargetUid = position.__type;\n }\n\n if (position.before) {\n const beforeRelation = { ...relation, ...position, documentId: position.before };\n const beforeIds: ID[] = getIds(positionTargetUid, beforeRelation);\n position.before = beforeIds.at(0);\n }\n\n if (position.after) {\n const afterRelation = { ...relation, ...position, documentId: position.after };\n position.after = getIds(positionTargetUid, afterRelation).at(0);\n }\n\n // Transform all ids to new relations\n return ids?.map((id) => {\n const newRelation = { id } as typeof relation;\n\n if (relation.position) {\n newRelation.position = position;\n }\n\n // Insert type if its a polymorphic relation\n if (isPolymorphicRelation) {\n newRelation.__type = targetUid;\n }\n\n return newRelation;\n });\n }, normalizedValue as any);\n\n set(key, newRelation as any);\n },\n { schema: strapi.getModel(source.uid), getModel: strapi.getModel.bind(strapi) },\n data\n );\n};\n\nexport { transformDataIdsVisitor };\n"],"names":["isPolymorphic","relations","getRelationIds","curry","idMap","source","targetUid","relation","targetLocale","getRelationTargetLocale","sourceUid","uid","sourceLocale","locale","targetStatus","getRelationTargetStatus","sourceStatus","status","ids","tStatus","entryId","get","documentId","push","length","allowMissingId","errors","ValidationError","transformDataIdsVisitor","data","traverseEntityRelations","key","value","attribute","set","isPolymorphicRelation","getIds","normalizedValue","normalizeXToOneRelationValue","newRelation","mapRelation","__type","target","position","positionTargetUid","before","beforeRelation","beforeIds","at","after","afterRelation","map","id","schema","strapi","getModel","bind"],"mappings":";;;;;;;;;AAYA,MAAM,EAAEA,aAAa,EAAE,GAAGC,qBAAAA;AAS1B;;AAEC,IACD,MAAMC,cAAAA,GAAiBC,QAAAA,CACrB,CAAC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,GAAgB;AAAE,oBAAA,GAAG3C,QAAQ;AAAE,oBAAA,GAAGoC,QAAQ;AAAErB,oBAAAA,UAAAA,EAAYqB,SAASM;AAAM,iBAAA;AAC7EN,gBAAAA,QAAAA,CAASM,KAAK,GAAGb,MAAAA,CAAOQ,iBAAAA,EAAmBM,aAAAA,CAAAA,CAAeF,EAAE,CAAC,CAAA,CAAA;AAC/D,YAAA;;YAGA,OAAO9B,GAAAA,EAAKiC,IAAI,CAACC,EAAAA,GAAAA;AACf,gBAAA,MAAMb,WAAAA,GAAc;AAAEa,oBAAAA;AAAG,iBAAA;gBAEzB,IAAI7C,QAAAA,CAASoC,QAAQ,EAAE;AACrBJ,oBAAAA,WAAAA,CAAYI,QAAQ,GAAGA,QAAAA;AACzB,gBAAA;;AAGA,gBAAA,IAAIR,qBAAAA,EAAuB;AACzBI,oBAAAA,WAAAA,CAAYE,MAAM,GAAGnC,SAAAA;AACvB,gBAAA;gBAEA,OAAOiC,WAAAA;AACT,YAAA,CAAA,CAAA;QACF,CAAA,EAAGF,eAAAA,CAAAA;AAEHH,QAAAA,GAAAA,CAAIH,GAAAA,EAAKQ,WAAAA,CAAAA;IACX,CAAA,EACA;AAAEc,QAAAA,MAAAA,EAAQC,MAAAA,CAAOC,QAAQ,CAAClD,MAAAA,CAAOM,GAAG,CAAA;AAAG4C,QAAAA,QAAAA,EAAUD,MAAAA,CAAOC,QAAQ,CAACC,IAAI,CAACF,MAAAA;KAAQ,EAC9EzB,IAAAA,CAAAA;AAEJ;;;;"}
|
|
@@ -3,6 +3,7 @@ import { relations, errors } from '@strapi/utils';
|
|
|
3
3
|
import { getRelationTargetLocale } from '../utils/i18n.mjs';
|
|
4
4
|
import { getRelationTargetStatus } from '../utils/dp.mjs';
|
|
5
5
|
import { traverseEntityRelations as traverseEntityRelationsCurried, mapRelation as mapRelationCurried } from '../utils/map-relation.mjs';
|
|
6
|
+
import { normalizeXToOneRelationValue } from '../utils/xto-one.mjs';
|
|
6
7
|
|
|
7
8
|
const { isPolymorphic } = relations;
|
|
8
9
|
/**
|
|
@@ -47,6 +48,8 @@ const { isPolymorphic } = relations;
|
|
|
47
48
|
}
|
|
48
49
|
const isPolymorphicRelation = isPolymorphic(attribute);
|
|
49
50
|
const getIds = getRelationIds(idMap, source);
|
|
51
|
+
// Collapse a "relates to one" payload to a single entry first.
|
|
52
|
+
const normalizedValue = normalizeXToOneRelationValue(attribute, value);
|
|
50
53
|
// Transform the relation documentId to entity id
|
|
51
54
|
const newRelation = await mapRelationCurried((relation)=>{
|
|
52
55
|
if (!relation || !relation.documentId) {
|
|
@@ -96,7 +99,7 @@ const { isPolymorphic } = relations;
|
|
|
96
99
|
}
|
|
97
100
|
return newRelation;
|
|
98
101
|
});
|
|
99
|
-
},
|
|
102
|
+
}, normalizedValue);
|
|
100
103
|
set(key, newRelation);
|
|
101
104
|
}, {
|
|
102
105
|
schema: strapi.getModel(source.uid),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-ids.mjs","sources":["../../../../../../src/services/document-service/transform/relations/transform/data-ids.ts"],"sourcesContent":["import { curry } from 'lodash/fp';\n\nimport type { UID } from '@strapi/types';\nimport { errors, relations } from '@strapi/utils';\n\nimport { ID, LongHandDocument } from '../utils/types';\nimport { IdMap } from '../../id-map';\nimport { getRelationTargetLocale } from '../utils/i18n';\nimport { getRelationTargetStatus } from '../utils/dp';\nimport { mapRelation, traverseEntityRelations } from '../utils/map-relation';\n\nconst { isPolymorphic } = relations;\n\ninterface Options {\n uid: 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/**\n * Get the entry ids for a given documentId.\n */\nconst getRelationIds = curry(\n (idMap: IdMap, source: Options, targetUid: UID.Schema, relation: LongHandDocument) => {\n // locale to connect to\n const targetLocale = getRelationTargetLocale(relation, {\n targetUid,\n sourceUid: source.uid,\n sourceLocale: source.locale,\n });\n\n // status(es) to connect to\n const targetStatus = getRelationTargetStatus(relation, {\n targetUid,\n sourceUid: source.uid,\n sourceStatus: source.status,\n });\n\n const ids: ID[] = [];\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 tStatus of targetStatus) {\n const entryId = idMap.get({\n uid: targetUid,\n documentId: relation.documentId,\n locale: targetLocale,\n status: tStatus,\n });\n\n if (entryId) ids.push(entryId);\n }\n\n if (!ids.length && !source.allowMissingId) {\n throw new errors.ValidationError(\n `Document with id \"${relation.documentId}\", locale \"${targetLocale}\" not found`\n );\n }\n\n return ids;\n }\n);\n\n/**\n * Iterate over all relations of a data object and transform all relational document ids to entity ids.\n */\nconst transformDataIdsVisitor = (idMap: IdMap, data: Record<string, any>, source: Options) => {\n return traverseEntityRelations(\n async ({ key, value, attribute }, { set }) => {\n if (!attribute) {\n return;\n }\n const isPolymorphicRelation = isPolymorphic(attribute);\n const getIds = getRelationIds(idMap, source);\n\n // Transform the relation documentId to entity id\n const newRelation = await mapRelation((relation) => {\n if (!relation || !relation.documentId) {\n return relation;\n }\n\n // Find relational attributes, and return the document ids\n // if its a polymorphic relation we need to get it from the data itself\n const targetUid: UID.Schema = isPolymorphicRelation ? relation.__type : attribute.target;\n const ids: ID[] = getIds(targetUid, relation);\n\n // Handle positional arguments\n const position = { ...relation.position };\n\n // The positional relation target uid can be different for polymorphic relations\n let positionTargetUid: UID.Schema = targetUid;\n if (isPolymorphicRelation && position?.__type) {\n positionTargetUid = position.__type;\n }\n\n if (position.before) {\n const beforeRelation = { ...relation, ...position, documentId: position.before };\n const beforeIds: ID[] = getIds(positionTargetUid, beforeRelation);\n position.before = beforeIds.at(0);\n }\n\n if (position.after) {\n const afterRelation = { ...relation, ...position, documentId: position.after };\n position.after = getIds(positionTargetUid, afterRelation).at(0);\n }\n\n // Transform all ids to new relations\n return ids?.map((id) => {\n const newRelation = { id } as typeof relation;\n\n if (relation.position) {\n newRelation.position = position;\n }\n\n // Insert type if its a polymorphic relation\n if (isPolymorphicRelation) {\n newRelation.__type = targetUid;\n }\n\n return newRelation;\n });\n },
|
|
1
|
+
{"version":3,"file":"data-ids.mjs","sources":["../../../../../../src/services/document-service/transform/relations/transform/data-ids.ts"],"sourcesContent":["import { curry } from 'lodash/fp';\n\nimport type { UID } from '@strapi/types';\nimport { errors, relations } from '@strapi/utils';\n\nimport { ID, LongHandDocument } from '../utils/types';\nimport { IdMap } from '../../id-map';\nimport { getRelationTargetLocale } from '../utils/i18n';\nimport { getRelationTargetStatus } from '../utils/dp';\nimport { mapRelation, traverseEntityRelations } from '../utils/map-relation';\nimport { normalizeXToOneRelationValue } from '../utils/xto-one';\n\nconst { isPolymorphic } = relations;\n\ninterface Options {\n uid: 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/**\n * Get the entry ids for a given documentId.\n */\nconst getRelationIds = curry(\n (idMap: IdMap, source: Options, targetUid: UID.Schema, relation: LongHandDocument) => {\n // locale to connect to\n const targetLocale = getRelationTargetLocale(relation, {\n targetUid,\n sourceUid: source.uid,\n sourceLocale: source.locale,\n });\n\n // status(es) to connect to\n const targetStatus = getRelationTargetStatus(relation, {\n targetUid,\n sourceUid: source.uid,\n sourceStatus: source.status,\n });\n\n const ids: ID[] = [];\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 tStatus of targetStatus) {\n const entryId = idMap.get({\n uid: targetUid,\n documentId: relation.documentId,\n locale: targetLocale,\n status: tStatus,\n });\n\n if (entryId) ids.push(entryId);\n }\n\n if (!ids.length && !source.allowMissingId) {\n throw new errors.ValidationError(\n `Document with id \"${relation.documentId}\", locale \"${targetLocale}\" not found`\n );\n }\n\n return ids;\n }\n);\n\n/**\n * Iterate over all relations of a data object and transform all relational document ids to entity ids.\n */\nconst transformDataIdsVisitor = (idMap: IdMap, data: Record<string, any>, source: Options) => {\n return traverseEntityRelations(\n async ({ key, value, attribute }, { set }) => {\n if (!attribute) {\n return;\n }\n const isPolymorphicRelation = isPolymorphic(attribute);\n const getIds = getRelationIds(idMap, source);\n\n // Collapse a \"relates to one\" payload to a single entry first.\n const normalizedValue = normalizeXToOneRelationValue(attribute, value as any);\n\n // Transform the relation documentId to entity id\n const newRelation = await mapRelation((relation) => {\n if (!relation || !relation.documentId) {\n return relation;\n }\n\n // Find relational attributes, and return the document ids\n // if its a polymorphic relation we need to get it from the data itself\n const targetUid: UID.Schema = isPolymorphicRelation ? relation.__type : attribute.target;\n const ids: ID[] = getIds(targetUid, relation);\n\n // Handle positional arguments\n const position = { ...relation.position };\n\n // The positional relation target uid can be different for polymorphic relations\n let positionTargetUid: UID.Schema = targetUid;\n if (isPolymorphicRelation && position?.__type) {\n positionTargetUid = position.__type;\n }\n\n if (position.before) {\n const beforeRelation = { ...relation, ...position, documentId: position.before };\n const beforeIds: ID[] = getIds(positionTargetUid, beforeRelation);\n position.before = beforeIds.at(0);\n }\n\n if (position.after) {\n const afterRelation = { ...relation, ...position, documentId: position.after };\n position.after = getIds(positionTargetUid, afterRelation).at(0);\n }\n\n // Transform all ids to new relations\n return ids?.map((id) => {\n const newRelation = { id } as typeof relation;\n\n if (relation.position) {\n newRelation.position = position;\n }\n\n // Insert type if its a polymorphic relation\n if (isPolymorphicRelation) {\n newRelation.__type = targetUid;\n }\n\n return newRelation;\n });\n }, normalizedValue as any);\n\n set(key, newRelation as any);\n },\n { schema: strapi.getModel(source.uid), getModel: strapi.getModel.bind(strapi) },\n data\n );\n};\n\nexport { transformDataIdsVisitor };\n"],"names":["isPolymorphic","relations","getRelationIds","curry","idMap","source","targetUid","relation","targetLocale","getRelationTargetLocale","sourceUid","uid","sourceLocale","locale","targetStatus","getRelationTargetStatus","sourceStatus","status","ids","tStatus","entryId","get","documentId","push","length","allowMissingId","errors","ValidationError","transformDataIdsVisitor","data","traverseEntityRelations","key","value","attribute","set","isPolymorphicRelation","getIds","normalizedValue","normalizeXToOneRelationValue","newRelation","mapRelation","__type","target","position","positionTargetUid","before","beforeRelation","beforeIds","at","after","afterRelation","map","id","schema","strapi","getModel","bind"],"mappings":";;;;;;;AAYA,MAAM,EAAEA,aAAa,EAAE,GAAGC,SAAAA;AAS1B;;AAEC,IACD,MAAMC,cAAAA,GAAiBC,KAAAA,CACrB,CAACC,KAAAA,EAAcC,QAAiBC,SAAAA,EAAuBC,QAAAA,GAAAA;;IAErD,MAAMC,YAAAA,GAAeC,wBAAwBF,QAAAA,EAAU;AACrDD,QAAAA,SAAAA;AACAI,QAAAA,SAAAA,EAAWL,OAAOM,GAAG;AACrBC,QAAAA,YAAAA,EAAcP,OAAOQ;AACvB,KAAA,CAAA;;IAGA,MAAMC,YAAAA,GAAeC,wBAAwBR,QAAAA,EAAU;AACrDD,QAAAA,SAAAA;AACAI,QAAAA,SAAAA,EAAWL,OAAOM,GAAG;AACrBK,QAAAA,YAAAA,EAAcX,OAAOY;AACvB,KAAA,CAAA;AAEA,IAAA,MAAMC,MAAY,EAAE;;;;IAKpB,KAAK,MAAMC,WAAWL,YAAAA,CAAc;QAClC,MAAMM,OAAAA,GAAUhB,KAAAA,CAAMiB,GAAG,CAAC;YACxBV,GAAAA,EAAKL,SAAAA;AACLgB,YAAAA,UAAAA,EAAYf,SAASe,UAAU;YAC/BT,MAAAA,EAAQL,YAAAA;YACRS,MAAAA,EAAQE;AACV,SAAA,CAAA;QAEA,IAAIC,OAAAA,EAASF,GAAAA,CAAIK,IAAI,CAACH,OAAAA,CAAAA;AACxB,IAAA;AAEA,IAAA,IAAI,CAACF,GAAAA,CAAIM,MAAM,IAAI,CAACnB,MAAAA,CAAOoB,cAAc,EAAE;AACzC,QAAA,MAAM,IAAIC,MAAAA,CAAOC,eAAe,CAC9B,CAAC,kBAAkB,EAAEpB,QAAAA,CAASe,UAAU,CAAC,WAAW,EAAEd,YAAAA,CAAa,WAAW,CAAC,CAA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