@strapi/data-transfer 5.48.1 → 5.49.0
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/directory/providers/destination/index.js +16 -11
- package/dist/directory/providers/destination/index.js.map +1 -1
- package/dist/directory/providers/destination/utils.js +6 -2
- package/dist/directory/providers/destination/utils.js.map +1 -1
- package/dist/directory/providers/source/index.js +25 -20
- package/dist/directory/providers/source/index.js.map +1 -1
- package/dist/file/providers/destination/index.js +10 -4
- package/dist/file/providers/destination/index.js.map +1 -1
- package/dist/file/providers/source/index.js +9 -3
- package/dist/file/providers/source/index.js.map +1 -1
- package/dist/file/providers/source/utils.js +10 -6
- package/dist/file/providers/source/utils.js.map +1 -1
- package/dist/strapi/providers/local-destination/index.js +11 -7
- package/dist/strapi/providers/local-destination/index.js.map +1 -1
- package/dist/strapi/providers/local-destination/strategies/restore/configuration.d.ts.map +1 -1
- package/dist/strapi/providers/local-destination/strategies/restore/configuration.js +9 -3
- package/dist/strapi/providers/local-destination/strategies/restore/configuration.js.map +1 -1
- package/dist/strapi/providers/local-destination/strategies/restore/configuration.mjs +4 -2
- package/dist/strapi/providers/local-destination/strategies/restore/configuration.mjs.map +1 -1
- package/dist/strapi/providers/local-source/configuration.d.ts.map +1 -1
- package/dist/strapi/providers/local-source/configuration.js +8 -0
- package/dist/strapi/providers/local-source/configuration.js.map +1 -1
- package/dist/strapi/providers/local-source/configuration.mjs +8 -0
- package/dist/strapi/providers/local-source/configuration.mjs.map +1 -1
- package/dist/strapi/remote/handlers/push.js +1 -0
- package/dist/strapi/remote/handlers/push.js.map +1 -1
- package/dist/strapi/remote/handlers/push.mjs +1 -0
- package/dist/strapi/remote/handlers/push.mjs.map +1 -1
- package/dist/strapi/utils/project-settings-logos.d.ts +29 -0
- package/dist/strapi/utils/project-settings-logos.d.ts.map +1 -0
- package/dist/strapi/utils/project-settings-logos.js +174 -0
- package/dist/strapi/utils/project-settings-logos.js.map +1 -0
- package/dist/strapi/utils/project-settings-logos.mjs +169 -0
- package/dist/strapi/utils/project-settings-logos.mjs.map +1 -0
- package/dist/utils/components.js +10 -6
- package/dist/utils/components.js.map +1 -1
- package/package.json +8 -6
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { join } from 'path';
|
|
2
|
+
import { Readable } from 'stream';
|
|
3
|
+
import { pick } from 'lodash/fp';
|
|
4
|
+
import { readFile } from 'fs-extra';
|
|
5
|
+
import { lookup } from 'mime-types';
|
|
6
|
+
|
|
7
|
+
const PROJECT_SETTINGS_CORE_STORE_KEY = 'core_admin_project-settings';
|
|
8
|
+
// The shape persisted back to core-store, matching what the admin project-settings
|
|
9
|
+
// service stores (so the admin UI keeps behaving identically after a transfer).
|
|
10
|
+
const LOGO_PERSISTED_FIELDS = [
|
|
11
|
+
'name',
|
|
12
|
+
'hash',
|
|
13
|
+
'url',
|
|
14
|
+
'width',
|
|
15
|
+
'height',
|
|
16
|
+
'ext',
|
|
17
|
+
'size',
|
|
18
|
+
'provider'
|
|
19
|
+
];
|
|
20
|
+
const isProjectSettingsRow = (row)=>row.key === PROJECT_SETTINGS_CORE_STORE_KEY;
|
|
21
|
+
const getConfiguredUploadProvider = (strapi)=>strapi.config.get('plugin::upload')?.provider;
|
|
22
|
+
// Admin logos with no provider were uploaded with the local provider (the default).
|
|
23
|
+
const isLocalProviderLogo = (logo)=>!logo.provider || logo.provider === 'local';
|
|
24
|
+
// Best-effort mime type for a logo so that remote providers (S3, Cloudinary, …)
|
|
25
|
+
// store the correct Content-Type and the image renders instead of downloading.
|
|
26
|
+
// The admin does not persist the mime type, so it is reconstructed from the
|
|
27
|
+
// file extension (falling back to the file name).
|
|
28
|
+
const getLogoMimeType = (logo)=>{
|
|
29
|
+
const fromExt = logo.ext ? lookup(logo.ext) : false;
|
|
30
|
+
if (fromExt) {
|
|
31
|
+
return fromExt;
|
|
32
|
+
}
|
|
33
|
+
const fromName = logo.name ? lookup(logo.name) : false;
|
|
34
|
+
if (fromName) {
|
|
35
|
+
return fromName;
|
|
36
|
+
}
|
|
37
|
+
return undefined;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Resolve the URL to read a non-local logo from during export.
|
|
41
|
+
*
|
|
42
|
+
* Mirrors the media-library asset export: when the file lives on the
|
|
43
|
+
* currently-configured provider and that provider serves private files,
|
|
44
|
+
* a signed URL is generated so the bytes can be fetched.
|
|
45
|
+
*/ const getRemoteLogoUrl = async (strapi, logo)=>{
|
|
46
|
+
const { provider } = strapi.plugins.upload;
|
|
47
|
+
const providerName = getConfiguredUploadProvider(strapi);
|
|
48
|
+
if (logo.provider === providerName && typeof provider?.isPrivate === 'function' && typeof provider?.getSignedUrl === 'function' && await provider.isPrivate()) {
|
|
49
|
+
const { url } = await provider.getSignedUrl(logo);
|
|
50
|
+
return url;
|
|
51
|
+
}
|
|
52
|
+
return logo.url;
|
|
53
|
+
};
|
|
54
|
+
const logoLabel = (logo)=>logo.name ?? logo.hash ?? 'unknown';
|
|
55
|
+
const readLocalLogoBuffer = async (strapi, logo)=>{
|
|
56
|
+
const filepath = join(strapi.dirs.static.public, logo.url);
|
|
57
|
+
try {
|
|
58
|
+
const buffer = await readFile(filepath);
|
|
59
|
+
return buffer.toString('base64');
|
|
60
|
+
} catch (error) {
|
|
61
|
+
const code = error && typeof error === 'object' && 'code' in error ? error.code : undefined;
|
|
62
|
+
if (code === 'ENOENT') {
|
|
63
|
+
strapi.log.warn(`[Data transfer] Admin logo "${logoLabel(logo)}" exists in project settings but no corresponding file was found to transfer. Path: ${filepath}`);
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
const readRemoteLogoBuffer = async (strapi, logo)=>{
|
|
70
|
+
const url = await getRemoteLogoUrl(strapi, logo);
|
|
71
|
+
const response = await strapi.fetch(url);
|
|
72
|
+
if (response.status !== 200 || !response.body) {
|
|
73
|
+
strapi.log.warn(`[Data transfer] Admin logo "${logoLabel(logo)}" exists in project settings but could not be fetched for transfer. URL: ${url} (status: ${response.status})`);
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
const chunks = [];
|
|
77
|
+
for await (const chunk of Readable.fromWeb(response.body)){
|
|
78
|
+
chunks.push(chunk);
|
|
79
|
+
}
|
|
80
|
+
return Buffer.concat(chunks).toString('base64');
|
|
81
|
+
};
|
|
82
|
+
const readLogoTransferBuffer = async (strapi, logo)=>{
|
|
83
|
+
if (!logo.url) {
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
86
|
+
if (isLocalProviderLogo(logo)) {
|
|
87
|
+
return readLocalLogoBuffer(strapi, logo);
|
|
88
|
+
}
|
|
89
|
+
return readRemoteLogoBuffer(strapi, logo);
|
|
90
|
+
};
|
|
91
|
+
const enrichLogoForExport = async (strapi, logo)=>{
|
|
92
|
+
if (!logo?.url) {
|
|
93
|
+
return logo;
|
|
94
|
+
}
|
|
95
|
+
const transferBuffer = await readLogoTransferBuffer(strapi, logo);
|
|
96
|
+
if (!transferBuffer) {
|
|
97
|
+
return logo;
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
...logo,
|
|
101
|
+
__transferBuffer: transferBuffer
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
const enrichProjectSettingsForExport = async (strapi, row)=>{
|
|
105
|
+
if (!isProjectSettingsRow(row)) {
|
|
106
|
+
return row;
|
|
107
|
+
}
|
|
108
|
+
const settings = row.value;
|
|
109
|
+
const [menuLogo, authLogo] = await Promise.all([
|
|
110
|
+
enrichLogoForExport(strapi, settings.menuLogo),
|
|
111
|
+
enrichLogoForExport(strapi, settings.authLogo)
|
|
112
|
+
]);
|
|
113
|
+
return {
|
|
114
|
+
...row,
|
|
115
|
+
value: {
|
|
116
|
+
...settings,
|
|
117
|
+
menuLogo,
|
|
118
|
+
authLogo
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* Re-upload a transferred logo to the destination's configured upload provider.
|
|
124
|
+
*
|
|
125
|
+
* The file is always re-uploaded through the destination provider, so the
|
|
126
|
+
* persisted `url` and `provider` reflect the destination (matching how the
|
|
127
|
+
* media-library asset restore behaves). A best-effort mime type is supplied so
|
|
128
|
+
* remote providers serve the logo with the correct Content-Type.
|
|
129
|
+
*/ const uploadLogoFromTransferBuffer = async (strapi, logo)=>{
|
|
130
|
+
if (!logo.__transferBuffer) {
|
|
131
|
+
return logo;
|
|
132
|
+
}
|
|
133
|
+
const { __transferBuffer, ...logoWithoutBuffer } = logo;
|
|
134
|
+
const provider = getConfiguredUploadProvider(strapi);
|
|
135
|
+
const mime = getLogoMimeType(logoWithoutBuffer);
|
|
136
|
+
const file = {
|
|
137
|
+
...logoWithoutBuffer,
|
|
138
|
+
...mime ? {
|
|
139
|
+
mime
|
|
140
|
+
} : {},
|
|
141
|
+
stream: Readable.from(Buffer.from(__transferBuffer, 'base64')),
|
|
142
|
+
provider
|
|
143
|
+
};
|
|
144
|
+
await strapi.plugin('upload').provider.uploadStream(file);
|
|
145
|
+
return pick(LOGO_PERSISTED_FIELDS, file);
|
|
146
|
+
};
|
|
147
|
+
const restoreProjectSettingsLogos = async (strapi, settings)=>{
|
|
148
|
+
const [menuLogo, authLogo] = await Promise.all([
|
|
149
|
+
settings.menuLogo ? uploadLogoFromTransferBuffer(strapi, settings.menuLogo) : settings.menuLogo,
|
|
150
|
+
settings.authLogo ? uploadLogoFromTransferBuffer(strapi, settings.authLogo) : settings.authLogo
|
|
151
|
+
]);
|
|
152
|
+
return {
|
|
153
|
+
...settings,
|
|
154
|
+
menuLogo,
|
|
155
|
+
authLogo
|
|
156
|
+
};
|
|
157
|
+
};
|
|
158
|
+
const restoreProjectSettingsRow = async (strapi, row)=>{
|
|
159
|
+
if (!isProjectSettingsRow(row)) {
|
|
160
|
+
return row;
|
|
161
|
+
}
|
|
162
|
+
return {
|
|
163
|
+
...row,
|
|
164
|
+
value: await restoreProjectSettingsLogos(strapi, row.value)
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
export { PROJECT_SETTINGS_CORE_STORE_KEY, enrichProjectSettingsForExport, restoreProjectSettingsLogos, restoreProjectSettingsRow };
|
|
169
|
+
//# sourceMappingURL=project-settings-logos.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"project-settings-logos.mjs","sources":["../../../src/strapi/utils/project-settings-logos.ts"],"sourcesContent":["import { join } from 'path';\nimport { Readable } from 'stream';\nimport { pick } from 'lodash/fp';\nimport { readFile } from 'fs-extra';\nimport { lookup as lookupMimeType } from 'mime-types';\nimport * as webStream from 'stream/web';\nimport type { Core } from '@strapi/types';\n\nexport const PROJECT_SETTINGS_CORE_STORE_KEY = 'core_admin_project-settings';\n\nexport const PROJECT_SETTINGS_LOGO_FIELDS = ['menuLogo', 'authLogo'] as const;\n\nexport type ProjectSettingsLogoField = (typeof PROJECT_SETTINGS_LOGO_FIELDS)[number];\n\nexport type ProjectSettingsLogo = {\n name?: string;\n hash?: string;\n url?: string;\n width?: number;\n height?: number;\n ext?: string;\n size?: number;\n mime?: string;\n provider?: string;\n __transferBuffer?: string;\n};\n\nexport type ProjectSettingsStoreValue = {\n menuLogo?: ProjectSettingsLogo | null;\n authLogo?: ProjectSettingsLogo | null;\n};\n\nexport type CoreStoreRow = {\n key: string;\n value: unknown;\n [key: string]: unknown;\n};\n\n// The shape persisted back to core-store, matching what the admin project-settings\n// service stores (so the admin UI keeps behaving identically after a transfer).\nconst LOGO_PERSISTED_FIELDS = [\n 'name',\n 'hash',\n 'url',\n 'width',\n 'height',\n 'ext',\n 'size',\n 'provider',\n] as const;\n\nconst isProjectSettingsRow = (row: CoreStoreRow) => row.key === PROJECT_SETTINGS_CORE_STORE_KEY;\n\nconst getConfiguredUploadProvider = (strapi: Core.Strapi) =>\n (strapi.config.get('plugin::upload') as { provider?: string } | undefined)?.provider;\n\n// Admin logos with no provider were uploaded with the local provider (the default).\nconst isLocalProviderLogo = (logo: ProjectSettingsLogo) =>\n !logo.provider || logo.provider === 'local';\n\n// Best-effort mime type for a logo so that remote providers (S3, Cloudinary, …)\n// store the correct Content-Type and the image renders instead of downloading.\n// The admin does not persist the mime type, so it is reconstructed from the\n// file extension (falling back to the file name).\nconst getLogoMimeType = (logo: ProjectSettingsLogo): string | undefined => {\n const fromExt = logo.ext ? lookupMimeType(logo.ext) : false;\n if (fromExt) {\n return fromExt;\n }\n\n const fromName = logo.name ? lookupMimeType(logo.name) : false;\n if (fromName) {\n return fromName;\n }\n\n return undefined;\n};\n\n/**\n * Resolve the URL to read a non-local logo from during export.\n *\n * Mirrors the media-library asset export: when the file lives on the\n * currently-configured provider and that provider serves private files,\n * a signed URL is generated so the bytes can be fetched.\n */\nconst getRemoteLogoUrl = async (strapi: Core.Strapi, logo: ProjectSettingsLogo) => {\n const { provider } = strapi.plugins.upload;\n const providerName = getConfiguredUploadProvider(strapi);\n\n if (\n logo.provider === providerName &&\n typeof provider?.isPrivate === 'function' &&\n typeof provider?.getSignedUrl === 'function' &&\n (await provider.isPrivate())\n ) {\n const { url } = await provider.getSignedUrl(logo);\n return url;\n }\n\n return logo.url;\n};\n\nconst logoLabel = (logo: ProjectSettingsLogo) => logo.name ?? logo.hash ?? 'unknown';\n\nconst readLocalLogoBuffer = async (strapi: Core.Strapi, logo: ProjectSettingsLogo) => {\n const filepath = join(strapi.dirs.static.public, logo.url as string);\n\n try {\n const buffer = await readFile(filepath);\n return buffer.toString('base64');\n } catch (error) {\n const code =\n error && typeof error === 'object' && 'code' in error\n ? (error as NodeJS.ErrnoException).code\n : undefined;\n\n if (code === 'ENOENT') {\n strapi.log.warn(\n `[Data transfer] Admin logo \"${logoLabel(logo)}\" exists in project settings but no corresponding file was found to transfer. Path: ${filepath}`\n );\n return undefined;\n }\n\n throw error;\n }\n};\n\nconst readRemoteLogoBuffer = async (strapi: Core.Strapi, logo: ProjectSettingsLogo) => {\n const url = await getRemoteLogoUrl(strapi, logo);\n const response = await strapi.fetch(url);\n\n if (response.status !== 200 || !response.body) {\n strapi.log.warn(\n `[Data transfer] Admin logo \"${logoLabel(logo)}\" exists in project settings but could not be fetched for transfer. URL: ${url} (status: ${response.status})`\n );\n return undefined;\n }\n\n const chunks: Uint8Array[] = [];\n\n for await (const chunk of Readable.fromWeb(\n response.body as webStream.ReadableStream<Uint8Array>\n )) {\n chunks.push(chunk);\n }\n\n return Buffer.concat(chunks).toString('base64');\n};\n\nconst readLogoTransferBuffer = async (strapi: Core.Strapi, logo: ProjectSettingsLogo) => {\n if (!logo.url) {\n return undefined;\n }\n\n if (isLocalProviderLogo(logo)) {\n return readLocalLogoBuffer(strapi, logo);\n }\n\n return readRemoteLogoBuffer(strapi, logo);\n};\n\nconst enrichLogoForExport = async (\n strapi: Core.Strapi,\n logo: ProjectSettingsLogo | null | undefined\n) => {\n if (!logo?.url) {\n return logo;\n }\n\n const transferBuffer = await readLogoTransferBuffer(strapi, logo);\n\n if (!transferBuffer) {\n return logo;\n }\n\n return {\n ...logo,\n __transferBuffer: transferBuffer,\n };\n};\n\nexport const enrichProjectSettingsForExport = async (\n strapi: Core.Strapi,\n row: CoreStoreRow\n): Promise<CoreStoreRow> => {\n if (!isProjectSettingsRow(row)) {\n return row;\n }\n\n const settings = row.value as ProjectSettingsStoreValue;\n\n const [menuLogo, authLogo] = await Promise.all([\n enrichLogoForExport(strapi, settings.menuLogo),\n enrichLogoForExport(strapi, settings.authLogo),\n ]);\n\n return {\n ...row,\n value: {\n ...settings,\n menuLogo,\n authLogo,\n },\n };\n};\n\n/**\n * Re-upload a transferred logo to the destination's configured upload provider.\n *\n * The file is always re-uploaded through the destination provider, so the\n * persisted `url` and `provider` reflect the destination (matching how the\n * media-library asset restore behaves). A best-effort mime type is supplied so\n * remote providers serve the logo with the correct Content-Type.\n */\nconst uploadLogoFromTransferBuffer = async (strapi: Core.Strapi, logo: ProjectSettingsLogo) => {\n if (!logo.__transferBuffer) {\n return logo;\n }\n\n const { __transferBuffer, ...logoWithoutBuffer } = logo;\n const provider = getConfiguredUploadProvider(strapi);\n const mime = getLogoMimeType(logoWithoutBuffer);\n\n const file = {\n ...logoWithoutBuffer,\n ...(mime ? { mime } : {}),\n stream: Readable.from(Buffer.from(__transferBuffer, 'base64')),\n provider,\n };\n\n await strapi.plugin('upload').provider.uploadStream(file);\n\n return pick(LOGO_PERSISTED_FIELDS, file);\n};\n\nexport const restoreProjectSettingsLogos = async (\n strapi: Core.Strapi,\n settings: ProjectSettingsStoreValue\n): Promise<ProjectSettingsStoreValue> => {\n const [menuLogo, authLogo] = await Promise.all([\n settings.menuLogo ? uploadLogoFromTransferBuffer(strapi, settings.menuLogo) : settings.menuLogo,\n settings.authLogo ? uploadLogoFromTransferBuffer(strapi, settings.authLogo) : settings.authLogo,\n ]);\n\n return {\n ...settings,\n menuLogo,\n authLogo,\n };\n};\n\nexport const restoreProjectSettingsRow = async (strapi: Core.Strapi, row: CoreStoreRow) => {\n if (!isProjectSettingsRow(row)) {\n return row;\n }\n\n return {\n ...row,\n value: await restoreProjectSettingsLogos(strapi, row.value as ProjectSettingsStoreValue),\n };\n};\n"],"names":["PROJECT_SETTINGS_CORE_STORE_KEY","LOGO_PERSISTED_FIELDS","isProjectSettingsRow","row","key","getConfiguredUploadProvider","strapi","config","get","provider","isLocalProviderLogo","logo","getLogoMimeType","fromExt","ext","lookupMimeType","fromName","name","undefined","getRemoteLogoUrl","plugins","upload","providerName","isPrivate","getSignedUrl","url","logoLabel","hash","readLocalLogoBuffer","filepath","join","dirs","static","public","buffer","readFile","toString","error","code","log","warn","readRemoteLogoBuffer","response","fetch","status","body","chunks","chunk","Readable","fromWeb","push","Buffer","concat","readLogoTransferBuffer","enrichLogoForExport","transferBuffer","__transferBuffer","enrichProjectSettingsForExport","settings","value","menuLogo","authLogo","Promise","all","uploadLogoFromTransferBuffer","logoWithoutBuffer","mime","file","stream","from","plugin","uploadStream","pick","restoreProjectSettingsLogos","restoreProjectSettingsRow"],"mappings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|
5
5
|
var utils = require('@strapi/utils');
|
|
6
6
|
|
|
7
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
|
+
|
|
9
|
+
var ___default = /*#__PURE__*/_interopDefault(_);
|
|
10
|
+
|
|
7
11
|
const isDialectMySQL = ()=>strapi.db?.dialect.client === 'mysql';
|
|
8
12
|
function omitComponentData(contentType, data) {
|
|
9
13
|
const { attributes } = contentType;
|
|
@@ -81,7 +85,7 @@ const createComponents = async (uid, data)=>{
|
|
|
81
85
|
};
|
|
82
86
|
const getComponents = async (uid, entity)=>{
|
|
83
87
|
const componentAttributes = utils.contentTypes.getComponentAttributes(strapi.getModel(uid));
|
|
84
|
-
if (
|
|
88
|
+
if (___default.default.isEmpty(componentAttributes)) {
|
|
85
89
|
return {};
|
|
86
90
|
}
|
|
87
91
|
return strapi.db.query(uid).load(entity, componentAttributes);
|
|
@@ -104,13 +108,13 @@ const deleteComponents = async (uid, entityToDelete, { loadComponents = true } =
|
|
|
104
108
|
if (attribute.type === 'component') {
|
|
105
109
|
const { component: componentUID } = attribute;
|
|
106
110
|
// MySQL/MariaDB can cause deadlocks here if concurrency higher than 1
|
|
107
|
-
await utils.async.map(
|
|
111
|
+
await utils.async.map(___default.default.castArray(value), (subValue)=>deleteComponent(componentUID, subValue), {
|
|
108
112
|
concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity
|
|
109
113
|
});
|
|
110
114
|
} else {
|
|
111
115
|
// delete dynamic zone components
|
|
112
116
|
// MySQL/MariaDB can cause deadlocks here if concurrency higher than 1
|
|
113
|
-
await utils.async.map(
|
|
117
|
+
await utils.async.map(___default.default.castArray(value), (subValue)=>deleteComponent(subValue.__component, subValue), {
|
|
114
118
|
concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity
|
|
115
119
|
});
|
|
116
120
|
}
|
|
@@ -151,7 +155,7 @@ const deleteComponent = async (uid, componentToDelete)=>{
|
|
|
151
155
|
*/ const collectComponentIdMappings = ({ data, created, schema, strapi: strapi1 })=>{
|
|
152
156
|
const mappings = [];
|
|
153
157
|
const visitComponent = (uid, oldValue, newValue)=>{
|
|
154
|
-
if (!
|
|
158
|
+
if (!___default.default.isObjectLike(oldValue) || !___default.default.isObjectLike(newValue)) {
|
|
155
159
|
return;
|
|
156
160
|
}
|
|
157
161
|
if (typeof oldValue.id === 'number' && typeof newValue.id === 'number') {
|
|
@@ -168,14 +172,14 @@ const deleteComponent = async (uid, componentToDelete)=>{
|
|
|
168
172
|
}
|
|
169
173
|
};
|
|
170
174
|
const visitSchema = (currentSchema, oldData, newData)=>{
|
|
171
|
-
if (!
|
|
175
|
+
if (!___default.default.isObjectLike(oldData) || !___default.default.isObjectLike(newData)) {
|
|
172
176
|
return;
|
|
173
177
|
}
|
|
174
178
|
const { attributes = {} } = currentSchema;
|
|
175
179
|
for (const [attributeName, attribute] of Object.entries(attributes)){
|
|
176
180
|
const oldValue = oldData[attributeName];
|
|
177
181
|
const newValue = newData[attributeName];
|
|
178
|
-
if (
|
|
182
|
+
if (___default.default.isNil(oldValue) || ___default.default.isNil(newValue)) {
|
|
179
183
|
continue;
|
|
180
184
|
}
|
|
181
185
|
if (attribute.type === 'component') {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"components.js","sources":["../../src/utils/components.ts"],"sourcesContent":["import _ from 'lodash';\nimport { get, has, omit, pipe, assign } from 'lodash/fp';\n\nimport { contentTypes as contentTypesUtils, async, errors } from '@strapi/utils';\nimport type { Modules, UID, Data, Utils, Schema, Core } from '@strapi/types';\n\ntype LoadedComponents<TUID extends UID.Schema> = Data.Entity<\n TUID,\n Schema.AttributeNamesByType<TUID, 'component' | 'dynamiczone'>\n>;\n\ntype ComponentValue = Schema.Attribute.Value<\n Schema.Attribute.Component<UID.Component, false> | Schema.Attribute.Component<UID.Component, true>\n>;\n\ntype ComponentBody = {\n [key: string]: Schema.Attribute.Value<\n | Schema.Attribute.Component<UID.Component, false>\n | Schema.Attribute.Component<UID.Component, true>\n | Schema.Attribute.DynamicZone\n >;\n};\n\nconst isDialectMySQL = () => strapi.db?.dialect.client === 'mysql';\n\nfunction omitComponentData(\n contentType: Schema.ContentType,\n data: Modules.EntityService.Params.Data.Input<Schema.ContentType['uid']>\n): Partial<Modules.EntityService.Params.Data.Input<Schema.ContentType['uid']>>;\nfunction omitComponentData(\n contentType: Schema.Component,\n data: Modules.EntityService.Params.Data.Input<Schema.Component['uid']>\n): Partial<Modules.EntityService.Params.Data.Input<Schema.Component['uid']>>;\nfunction omitComponentData(\n contentType: Schema.ContentType | Schema.Component,\n data: Modules.EntityService.Params.Data.Input<Schema.ContentType['uid'] | Schema.Component['uid']>\n): Partial<\n Modules.EntityService.Params.Data.Input<Schema.ContentType['uid'] | Schema.Component['uid']>\n> {\n const { attributes } = contentType;\n const componentAttributes = Object.keys(attributes).filter((attributeName) =>\n contentTypesUtils.isComponentAttribute(attributes[attributeName])\n );\n\n return omit(componentAttributes, data);\n}\n\n// NOTE: we could generalize the logic to allow CRUD of relation directly in the DB layer\nconst createComponents = async <\n TUID extends UID.Schema,\n TData extends Modules.EntityService.Params.Data.Input<TUID>,\n>(\n uid: TUID,\n data: TData\n) => {\n const { attributes = {} } = strapi.getModel(uid);\n\n const componentBody: ComponentBody = {};\n\n const attributeNames = Object.keys(attributes);\n\n for (const attributeName of attributeNames) {\n const attribute = attributes[attributeName];\n\n if (!has(attributeName, data) || !contentTypesUtils.isComponentAttribute(attribute)) {\n continue;\n }\n\n if (attribute.type === 'component') {\n const { component: componentUID, repeatable = false } = attribute;\n\n const componentValue = data[attributeName as keyof TData];\n\n if (componentValue === null) {\n continue;\n }\n\n if (repeatable === true) {\n if (!Array.isArray(componentValue)) {\n throw new Error('Expected an array to create repeatable component');\n }\n\n // MySQL/MariaDB can cause deadlocks here if concurrency higher than 1\n const components = (await async.map(\n componentValue,\n (value: any) => createComponent(componentUID, value),\n { concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity }\n )) as Schema.Attribute.Value<Schema.Attribute.Component<UID.Component, true>>;\n\n componentBody[attributeName] = components.map(({ id }) => {\n return {\n id,\n __pivot: {\n field: attributeName,\n component_type: componentUID,\n },\n };\n });\n } else {\n const component = await createComponent(\n componentUID,\n componentValue as Modules.EntityService.Params.Data.Input<UID.Component>\n );\n componentBody[attributeName] = {\n id: component.id,\n __pivot: {\n field: attributeName,\n component_type: componentUID,\n },\n };\n }\n\n continue;\n }\n\n if (attribute.type === 'dynamiczone') {\n const dynamiczoneValues = data[\n attributeName as keyof TData\n ] as Modules.EntityService.Params.Attribute.GetValue<Schema.Attribute.DynamicZone>;\n\n if (!Array.isArray(dynamiczoneValues)) {\n throw new Error('Expected an array to create repeatable component');\n }\n\n const createDynamicZoneComponents = async (\n value: Utils.Array.Values<typeof dynamiczoneValues>\n ) => {\n const { id } = await createComponent(value.__component, value);\n return {\n id,\n __component: value.__component,\n __pivot: {\n field: attributeName,\n },\n };\n };\n\n // MySQL/MariaDB can cause deadlocks here if concurrency higher than 1\n componentBody[attributeName] = await async.map(\n dynamiczoneValues,\n createDynamicZoneComponents,\n { concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity }\n );\n\n continue;\n }\n }\n\n return componentBody;\n};\n\nconst getComponents = async <TUID extends UID.Schema>(\n uid: TUID,\n entity: { id: Modules.EntityService.Params.Attribute.ID }\n): Promise<LoadedComponents<TUID>> => {\n const componentAttributes = contentTypesUtils.getComponentAttributes(strapi.getModel(uid));\n\n if (_.isEmpty(componentAttributes)) {\n return {} as LoadedComponents<TUID>;\n }\n\n return strapi.db.query(uid).load(entity, componentAttributes) as Promise<LoadedComponents<TUID>>;\n};\n\n/*\n delete old components\n create or update\n*/\nconst updateComponents = async <\n TUID extends UID.Schema,\n TData extends Partial<Modules.EntityService.Params.Data.Input<TUID>>,\n>(\n uid: TUID,\n entityToUpdate: { id: Modules.EntityService.Params.Attribute.ID },\n data: TData\n) => {\n const { attributes = {} } = strapi.getModel(uid);\n\n const componentBody: ComponentBody = {};\n\n for (const attributeName of Object.keys(attributes)) {\n const attribute = attributes[attributeName];\n\n if (!has(attributeName, data)) {\n continue;\n }\n\n if (attribute.type === 'component') {\n const { component: componentUID, repeatable = false } = attribute;\n\n const componentValue = data[\n attributeName as keyof TData\n ] as Schema.Attribute.Value<Schema.Attribute.Component>;\n\n await deleteOldComponents(uid, componentUID, entityToUpdate, attributeName, componentValue);\n\n if (repeatable === true) {\n if (!Array.isArray(componentValue)) {\n throw new Error('Expected an array to create repeatable component');\n }\n\n // MySQL/MariaDB can cause deadlocks here if concurrency higher than 1\n const components = (await async.map(\n componentValue,\n (value: any) => updateOrCreateComponent(componentUID, value),\n { concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity }\n )) as Schema.Attribute.Value<Schema.Attribute.Component<UID.Component, true>>;\n\n componentBody[attributeName] = components.filter(_.negate(_.isNil)).map(({ id }) => {\n return {\n id,\n __pivot: {\n field: attributeName,\n component_type: componentUID,\n },\n };\n });\n } else {\n const component = await updateOrCreateComponent(componentUID, componentValue);\n componentBody[attributeName] = component && {\n id: component.id,\n __pivot: {\n field: attributeName,\n component_type: componentUID,\n },\n };\n }\n\n continue;\n }\n\n if (attribute.type === 'dynamiczone') {\n const dynamiczoneValues = data[\n attributeName as keyof TData\n ] as Schema.Attribute.Value<Schema.Attribute.DynamicZone>;\n\n await deleteOldDZComponents(uid, entityToUpdate, attributeName, dynamiczoneValues);\n\n if (!Array.isArray(dynamiczoneValues)) {\n throw new Error('Expected an array to create repeatable component');\n }\n\n // MySQL/MariaDB can cause deadlocks here if concurrency higher than 1\n componentBody[attributeName] = await async.map(\n dynamiczoneValues,\n async (value: any) => {\n const { id } = await updateOrCreateComponent(value.__component, value);\n\n return {\n id,\n __component: value.__component,\n __pivot: {\n field: attributeName,\n },\n };\n },\n { concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity }\n );\n\n continue;\n }\n }\n\n return componentBody;\n};\n\nconst pickStringifiedId = ({\n id,\n}: {\n id: Modules.EntityService.Params.Attribute.ID;\n}): Modules.EntityService.Params.Attribute.ID & string => {\n if (typeof id === 'string') {\n return id;\n }\n\n return `${id}`;\n};\n\nconst deleteOldComponents = async <TUID extends UID.Schema>(\n uid: TUID,\n componentUID: UID.Component,\n entityToUpdate: { id: Modules.EntityService.Params.Attribute.ID },\n attributeName: string,\n componentValue: Schema.Attribute.Value<Schema.Attribute.Component>\n) => {\n const previousValue = (await strapi.db\n .query(uid)\n .load(entityToUpdate, attributeName)) as ComponentValue;\n\n const idsToKeep = _.castArray(componentValue).filter(has('id')).map(pickStringifiedId);\n const allIds = _.castArray(previousValue).filter(has('id')).map(pickStringifiedId);\n\n idsToKeep.forEach((id) => {\n if (!allIds.includes(id)) {\n throw new errors.ApplicationError(\n `Some of the provided components in ${attributeName} are not related to the entity`\n );\n }\n });\n\n const idsToDelete = _.difference(allIds, idsToKeep);\n\n if (idsToDelete.length > 0) {\n for (const idToDelete of idsToDelete) {\n await deleteComponent(componentUID, { id: idToDelete });\n }\n }\n};\n\nconst deleteOldDZComponents = async <TUID extends UID.Schema>(\n uid: TUID,\n entityToUpdate: { id: Modules.EntityService.Params.Attribute.ID },\n attributeName: string,\n dynamiczoneValues: Schema.Attribute.Value<Schema.Attribute.DynamicZone>\n) => {\n const previousValue = (await strapi.db\n .query(uid)\n .load(entityToUpdate, attributeName)) as Schema.Attribute.Value<Schema.Attribute.DynamicZone>;\n\n const idsToKeep = _.castArray(dynamiczoneValues)\n .filter(has('id'))\n .map((v) => ({\n id: pickStringifiedId(v),\n __component: v.__component,\n }));\n\n const allIds = _.castArray(previousValue)\n .filter(has('id'))\n .map((v) => ({\n id: pickStringifiedId(v),\n __component: v.__component,\n }));\n\n idsToKeep.forEach(({ id, __component }) => {\n if (!allIds.find((el) => el.id === id && el.__component === __component)) {\n const err = new Error(\n `Some of the provided components in ${attributeName} are not related to the entity`\n );\n\n Object.assign(err, { status: 400 });\n throw err;\n }\n });\n\n type IdsToDelete = Schema.Attribute.Value<Schema.Attribute.DynamicZone>;\n\n const idsToDelete = allIds.reduce((acc, { id, __component }) => {\n if (!idsToKeep.find((el) => el.id === id && el.__component === __component)) {\n acc.push({ id, __component });\n }\n\n return acc;\n }, [] as IdsToDelete);\n\n if (idsToDelete.length > 0) {\n for (const idToDelete of idsToDelete) {\n const { id, __component } = idToDelete;\n await deleteComponent(__component, { id });\n }\n }\n};\n\nconst deleteComponents = async <TUID extends UID.Schema, TEntity extends Data.Entity<TUID>>(\n uid: TUID,\n entityToDelete: TEntity,\n { loadComponents = true } = {}\n) => {\n const { attributes = {} } = strapi.getModel(uid);\n\n const attributeNames = Object.keys(attributes);\n\n for (const attributeName of attributeNames) {\n const attribute = attributes[attributeName];\n\n if (attribute.type === 'component' || attribute.type === 'dynamiczone') {\n let value;\n if (loadComponents) {\n value = await strapi.db.query(uid).load(entityToDelete, attributeName);\n } else {\n value = entityToDelete[attributeName as keyof TEntity];\n }\n\n if (!value) {\n continue;\n }\n\n if (attribute.type === 'component') {\n const { component: componentUID } = attribute;\n // MySQL/MariaDB can cause deadlocks here if concurrency higher than 1\n await async.map(\n _.castArray(value),\n (subValue: any) => deleteComponent(componentUID, subValue),\n {\n concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity,\n }\n );\n } else {\n // delete dynamic zone components\n // MySQL/MariaDB can cause deadlocks here if concurrency higher than 1\n await async.map(\n _.castArray(value),\n (subValue: any) => deleteComponent(subValue.__component, subValue),\n { concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity }\n );\n }\n\n continue;\n }\n }\n};\n\n/** *************************\n Component queries\n************************** */\n\n// components can have nested compos so this must be recursive\nconst createComponent = async <TUID extends UID.Component = UID.Component>(\n uid: TUID,\n data: Modules.EntityService.Params.Data.Input<TUID>\n) => {\n const model = strapi.getModel(uid) as Schema.Component;\n\n const componentData = await createComponents(uid, data);\n const transform = pipe(\n // Make sure we don't save the component with a pre-defined ID\n omit('id'),\n // Remove the component data from the original data object ...\n (payload) => omitComponentData(model, payload),\n // ... and assign the newly created component instead\n assign(componentData)\n );\n\n return strapi.db.query(uid).create({ data: transform(data) });\n};\n\n// components can have nested compos so this must be recursive\nconst updateComponent = async <TUID extends UID.Component>(\n uid: TUID,\n componentToUpdate: { id: Modules.EntityService.Params.Attribute.ID },\n data: Modules.EntityService.Params.Data.Input<TUID>\n) => {\n const model = strapi.getModel(uid) as Schema.Component;\n\n const componentData = await updateComponents(uid, componentToUpdate, data);\n\n return strapi.db.query(uid).update({\n where: {\n id: componentToUpdate.id,\n },\n data: Object.assign(omitComponentData(model, data), componentData),\n });\n};\n\nconst updateOrCreateComponent = <TUID extends UID.Component>(\n componentUID: TUID,\n value: Modules.EntityService.Params.Data.Input<TUID>\n) => {\n if (value === null) {\n return null;\n }\n\n // update\n if ('id' in value && typeof value.id !== 'undefined') {\n // TODO: verify the compo is associated with the entity\n return updateComponent(componentUID, { id: value.id }, value);\n }\n\n // create\n return createComponent(componentUID, value);\n};\n\nconst deleteComponent = async <TUID extends UID.Component>(\n uid: TUID,\n componentToDelete: Data.Component<TUID>\n) => {\n await deleteComponents(uid, componentToDelete);\n await strapi.db.query(uid).delete({ where: { id: componentToDelete.id } });\n};\n\ninterface IComponentIdMapping {\n uid: UID.Component;\n oldID: number;\n newID: number;\n}\n\n/**\n * Walk the source data and the newly created entity in parallel and collect\n * the [old ID, new ID] couple of every component instance found in both trees\n * (components & dynamic zones, including nested ones).\n *\n * Unlike a JSON diff, couples are also collected when the ID did not change,\n * so the result is an exhaustive map of every component instance that was\n * re-created with the entity.\n */\nconst collectComponentIdMappings = ({\n data,\n created,\n schema,\n strapi,\n}: {\n data: any;\n created: any;\n schema: Schema.Schema;\n strapi: Core.Strapi;\n}): IComponentIdMapping[] => {\n const mappings: IComponentIdMapping[] = [];\n\n const visitComponent = (uid: UID.Component, oldValue: any, newValue: any) => {\n if (!_.isObjectLike(oldValue) || !_.isObjectLike(newValue)) {\n return;\n }\n\n if (typeof oldValue.id === 'number' && typeof newValue.id === 'number') {\n mappings.push({ uid, oldID: oldValue.id, newID: newValue.id });\n }\n\n const componentSchema = strapi.getModel(uid);\n\n // Collect nested components & dynamic zones\n if (componentSchema) {\n visitSchema(componentSchema, oldValue, newValue);\n }\n };\n\n const visitSchema = (currentSchema: Schema.Schema, oldData: any, newData: any) => {\n if (!_.isObjectLike(oldData) || !_.isObjectLike(newData)) {\n return;\n }\n\n const { attributes = {} } = currentSchema;\n\n for (const [attributeName, attribute] of Object.entries(attributes)) {\n const oldValue = oldData[attributeName];\n const newValue = newData[attributeName];\n\n if (_.isNil(oldValue) || _.isNil(newValue)) {\n continue;\n }\n\n if (attribute.type === 'component') {\n const { component: componentUID, repeatable = false } = attribute;\n\n if (repeatable === true) {\n if (!Array.isArray(oldValue) || !Array.isArray(newValue)) {\n continue;\n }\n\n // Components are created (and thus populated back) in the same\n // order as the source data, pair them by index\n const length = Math.min(oldValue.length, newValue.length);\n\n for (let i = 0; i < length; i += 1) {\n visitComponent(componentUID, oldValue[i], newValue[i]);\n }\n } else {\n visitComponent(componentUID, oldValue, newValue);\n }\n }\n\n if (attribute.type === 'dynamiczone') {\n if (!Array.isArray(oldValue) || !Array.isArray(newValue)) {\n continue;\n }\n\n const length = Math.min(oldValue.length, newValue.length);\n\n for (let i = 0; i < length; i += 1) {\n const oldItem = oldValue[i];\n const newItem = newValue[i];\n const componentUID = oldItem?.__component;\n\n // Both items must reference the same dynamic zone component for the\n // ID couple to be meaningful\n if (!componentUID || (newItem?.__component && newItem.__component !== componentUID)) {\n continue;\n }\n\n visitComponent(componentUID, oldItem, newItem);\n }\n }\n }\n };\n\n visitSchema(schema, data, created);\n\n return mappings;\n};\n\n/**\n * Resolve the component UID of an entity's attribute based\n * on a given path (components & dynamic zones only)\n */\nconst resolveComponentUID = ({\n paths,\n strapi,\n data,\n contentType,\n}: {\n paths: string[];\n strapi: Core.Strapi;\n data: any;\n contentType: Schema.ContentType;\n}): UID.Schema | undefined => {\n let value: unknown = data;\n let cType:\n | Schema.ContentType\n | Schema.Component\n | ((...opts: any[]) => Schema.ContentType | Schema.Component) = contentType;\n for (const path of paths) {\n value = get(path, value);\n\n // Needed when the value of cType should be computed\n // based on the next value (eg: dynamic zones)\n if (typeof cType === 'function') {\n cType = cType(value);\n }\n\n if (path in cType.attributes) {\n const attribute: Schema.Attribute.AnyAttribute = cType.attributes[path];\n\n if (attribute.type === 'component') {\n cType = strapi.getModel(attribute.component);\n }\n\n if (attribute.type === 'dynamiczone') {\n cType = ({ __component }: { __component: UID.Component }) => strapi.getModel(__component);\n }\n }\n }\n\n if ('uid' in cType) {\n return cType.uid;\n }\n\n return undefined;\n};\n\nexport {\n omitComponentData,\n getComponents,\n createComponents,\n updateComponents,\n deleteComponents,\n deleteComponent,\n collectComponentIdMappings,\n resolveComponentUID,\n};\n"],"names":["isDialectMySQL","strapi","db","dialect","client","omitComponentData","contentType","data","attributes","componentAttributes","Object","keys","filter","attributeName","contentTypesUtils","isComponentAttribute","omit","createComponents","uid","getModel","componentBody","attributeNames","attribute","has","type","component","componentUID","repeatable","componentValue","Array","isArray","Error","components","async","map","value","createComponent","concurrency","inTransaction","Infinity","id","__pivot","field","component_type","dynamiczoneValues","createDynamicZoneComponents","__component","getComponents","entity","getComponentAttributes","_","isEmpty","query","load","deleteComponents","entityToDelete","loadComponents","castArray","subValue","deleteComponent","model","componentData","transform","pipe","payload","assign","create","componentToDelete","delete","where","collectComponentIdMappings","created","schema","mappings","visitComponent","oldValue","newValue","isObjectLike","push","oldID","newID","componentSchema","visitSchema","currentSchema","oldData","newData","entries","isNil","length","Math","min","i","oldItem","newItem"],"mappings":";;;;;;AAuBA,MAAMA,iBAAiB,IAAMC,MAAAA,CAAOC,EAAE,EAAEC,QAAQC,MAAAA,KAAW,OAAA;AAU3D,SAASC,iBAAAA,CACPC,WAAkD,EAClDC,IAAkG,EAAA;IAIlG,MAAM,EAAEC,UAAU,EAAE,GAAGF,WAAAA;AAC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AACxC,gBAAA;AACF,YAAA;AACF,QAAA;AACF,IAAA,CAAA;AAEAX,IAAAA,WAAAA,CAAYV,QAAQjE,IAAAA,EAAMgE,OAAAA,CAAAA;IAE1B,OAAOE,QAAAA;AACT;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"components.js","sources":["../../src/utils/components.ts"],"sourcesContent":["import _ from 'lodash';\nimport { get, has, omit, pipe, assign } from 'lodash/fp';\n\nimport { contentTypes as contentTypesUtils, async, errors } from '@strapi/utils';\nimport type { Modules, UID, Data, Utils, Schema, Core } from '@strapi/types';\n\ntype LoadedComponents<TUID extends UID.Schema> = Data.Entity<\n TUID,\n Schema.AttributeNamesByType<TUID, 'component' | 'dynamiczone'>\n>;\n\ntype ComponentValue = Schema.Attribute.Value<\n Schema.Attribute.Component<UID.Component, false> | Schema.Attribute.Component<UID.Component, true>\n>;\n\ntype ComponentBody = {\n [key: string]: Schema.Attribute.Value<\n | Schema.Attribute.Component<UID.Component, false>\n | Schema.Attribute.Component<UID.Component, true>\n | Schema.Attribute.DynamicZone\n >;\n};\n\nconst isDialectMySQL = () => strapi.db?.dialect.client === 'mysql';\n\nfunction omitComponentData(\n contentType: Schema.ContentType,\n data: Modules.EntityService.Params.Data.Input<Schema.ContentType['uid']>\n): Partial<Modules.EntityService.Params.Data.Input<Schema.ContentType['uid']>>;\nfunction omitComponentData(\n contentType: Schema.Component,\n data: Modules.EntityService.Params.Data.Input<Schema.Component['uid']>\n): Partial<Modules.EntityService.Params.Data.Input<Schema.Component['uid']>>;\nfunction omitComponentData(\n contentType: Schema.ContentType | Schema.Component,\n data: Modules.EntityService.Params.Data.Input<Schema.ContentType['uid'] | Schema.Component['uid']>\n): Partial<\n Modules.EntityService.Params.Data.Input<Schema.ContentType['uid'] | Schema.Component['uid']>\n> {\n const { attributes } = contentType;\n const componentAttributes = Object.keys(attributes).filter((attributeName) =>\n contentTypesUtils.isComponentAttribute(attributes[attributeName])\n );\n\n return omit(componentAttributes, data);\n}\n\n// NOTE: we could generalize the logic to allow CRUD of relation directly in the DB layer\nconst createComponents = async <\n TUID extends UID.Schema,\n TData extends Modules.EntityService.Params.Data.Input<TUID>,\n>(\n uid: TUID,\n data: TData\n) => {\n const { attributes = {} } = strapi.getModel(uid);\n\n const componentBody: ComponentBody = {};\n\n const attributeNames = Object.keys(attributes);\n\n for (const attributeName of attributeNames) {\n const attribute = attributes[attributeName];\n\n if (!has(attributeName, data) || !contentTypesUtils.isComponentAttribute(attribute)) {\n continue;\n }\n\n if (attribute.type === 'component') {\n const { component: componentUID, repeatable = false } = attribute;\n\n const componentValue = data[attributeName as keyof TData];\n\n if (componentValue === null) {\n continue;\n }\n\n if (repeatable === true) {\n if (!Array.isArray(componentValue)) {\n throw new Error('Expected an array to create repeatable component');\n }\n\n // MySQL/MariaDB can cause deadlocks here if concurrency higher than 1\n const components = (await async.map(\n componentValue,\n (value: any) => createComponent(componentUID, value),\n { concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity }\n )) as Schema.Attribute.Value<Schema.Attribute.Component<UID.Component, true>>;\n\n componentBody[attributeName] = components.map(({ id }) => {\n return {\n id,\n __pivot: {\n field: attributeName,\n component_type: componentUID,\n },\n };\n });\n } else {\n const component = await createComponent(\n componentUID,\n componentValue as Modules.EntityService.Params.Data.Input<UID.Component>\n );\n componentBody[attributeName] = {\n id: component.id,\n __pivot: {\n field: attributeName,\n component_type: componentUID,\n },\n };\n }\n\n continue;\n }\n\n if (attribute.type === 'dynamiczone') {\n const dynamiczoneValues = data[\n attributeName as keyof TData\n ] as Modules.EntityService.Params.Attribute.GetValue<Schema.Attribute.DynamicZone>;\n\n if (!Array.isArray(dynamiczoneValues)) {\n throw new Error('Expected an array to create repeatable component');\n }\n\n const createDynamicZoneComponents = async (\n value: Utils.Array.Values<typeof dynamiczoneValues>\n ) => {\n const { id } = await createComponent(value.__component, value);\n return {\n id,\n __component: value.__component,\n __pivot: {\n field: attributeName,\n },\n };\n };\n\n // MySQL/MariaDB can cause deadlocks here if concurrency higher than 1\n componentBody[attributeName] = await async.map(\n dynamiczoneValues,\n createDynamicZoneComponents,\n { concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity }\n );\n\n continue;\n }\n }\n\n return componentBody;\n};\n\nconst getComponents = async <TUID extends UID.Schema>(\n uid: TUID,\n entity: { id: Modules.EntityService.Params.Attribute.ID }\n): Promise<LoadedComponents<TUID>> => {\n const componentAttributes = contentTypesUtils.getComponentAttributes(strapi.getModel(uid));\n\n if (_.isEmpty(componentAttributes)) {\n return {} as LoadedComponents<TUID>;\n }\n\n return strapi.db.query(uid).load(entity, componentAttributes) as Promise<LoadedComponents<TUID>>;\n};\n\n/*\n delete old components\n create or update\n*/\nconst updateComponents = async <\n TUID extends UID.Schema,\n TData extends Partial<Modules.EntityService.Params.Data.Input<TUID>>,\n>(\n uid: TUID,\n entityToUpdate: { id: Modules.EntityService.Params.Attribute.ID },\n data: TData\n) => {\n const { attributes = {} } = strapi.getModel(uid);\n\n const componentBody: ComponentBody = {};\n\n for (const attributeName of Object.keys(attributes)) {\n const attribute = attributes[attributeName];\n\n if (!has(attributeName, data)) {\n continue;\n }\n\n if (attribute.type === 'component') {\n const { component: componentUID, repeatable = false } = attribute;\n\n const componentValue = data[\n attributeName as keyof TData\n ] as Schema.Attribute.Value<Schema.Attribute.Component>;\n\n await deleteOldComponents(uid, componentUID, entityToUpdate, attributeName, componentValue);\n\n if (repeatable === true) {\n if (!Array.isArray(componentValue)) {\n throw new Error('Expected an array to create repeatable component');\n }\n\n // MySQL/MariaDB can cause deadlocks here if concurrency higher than 1\n const components = (await async.map(\n componentValue,\n (value: any) => updateOrCreateComponent(componentUID, value),\n { concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity }\n )) as Schema.Attribute.Value<Schema.Attribute.Component<UID.Component, true>>;\n\n componentBody[attributeName] = components.filter(_.negate(_.isNil)).map(({ id }) => {\n return {\n id,\n __pivot: {\n field: attributeName,\n component_type: componentUID,\n },\n };\n });\n } else {\n const component = await updateOrCreateComponent(componentUID, componentValue);\n componentBody[attributeName] = component && {\n id: component.id,\n __pivot: {\n field: attributeName,\n component_type: componentUID,\n },\n };\n }\n\n continue;\n }\n\n if (attribute.type === 'dynamiczone') {\n const dynamiczoneValues = data[\n attributeName as keyof TData\n ] as Schema.Attribute.Value<Schema.Attribute.DynamicZone>;\n\n await deleteOldDZComponents(uid, entityToUpdate, attributeName, dynamiczoneValues);\n\n if (!Array.isArray(dynamiczoneValues)) {\n throw new Error('Expected an array to create repeatable component');\n }\n\n // MySQL/MariaDB can cause deadlocks here if concurrency higher than 1\n componentBody[attributeName] = await async.map(\n dynamiczoneValues,\n async (value: any) => {\n const { id } = await updateOrCreateComponent(value.__component, value);\n\n return {\n id,\n __component: value.__component,\n __pivot: {\n field: attributeName,\n },\n };\n },\n { concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity }\n );\n\n continue;\n }\n }\n\n return componentBody;\n};\n\nconst pickStringifiedId = ({\n id,\n}: {\n id: Modules.EntityService.Params.Attribute.ID;\n}): Modules.EntityService.Params.Attribute.ID & string => {\n if (typeof id === 'string') {\n return id;\n }\n\n return `${id}`;\n};\n\nconst deleteOldComponents = async <TUID extends UID.Schema>(\n uid: TUID,\n componentUID: UID.Component,\n entityToUpdate: { id: Modules.EntityService.Params.Attribute.ID },\n attributeName: string,\n componentValue: Schema.Attribute.Value<Schema.Attribute.Component>\n) => {\n const previousValue = (await strapi.db\n .query(uid)\n .load(entityToUpdate, attributeName)) as ComponentValue;\n\n const idsToKeep = _.castArray(componentValue).filter(has('id')).map(pickStringifiedId);\n const allIds = _.castArray(previousValue).filter(has('id')).map(pickStringifiedId);\n\n idsToKeep.forEach((id) => {\n if (!allIds.includes(id)) {\n throw new errors.ApplicationError(\n `Some of the provided components in ${attributeName} are not related to the entity`\n );\n }\n });\n\n const idsToDelete = _.difference(allIds, idsToKeep);\n\n if (idsToDelete.length > 0) {\n for (const idToDelete of idsToDelete) {\n await deleteComponent(componentUID, { id: idToDelete });\n }\n }\n};\n\nconst deleteOldDZComponents = async <TUID extends UID.Schema>(\n uid: TUID,\n entityToUpdate: { id: Modules.EntityService.Params.Attribute.ID },\n attributeName: string,\n dynamiczoneValues: Schema.Attribute.Value<Schema.Attribute.DynamicZone>\n) => {\n const previousValue = (await strapi.db\n .query(uid)\n .load(entityToUpdate, attributeName)) as Schema.Attribute.Value<Schema.Attribute.DynamicZone>;\n\n const idsToKeep = _.castArray(dynamiczoneValues)\n .filter(has('id'))\n .map((v) => ({\n id: pickStringifiedId(v),\n __component: v.__component,\n }));\n\n const allIds = _.castArray(previousValue)\n .filter(has('id'))\n .map((v) => ({\n id: pickStringifiedId(v),\n __component: v.__component,\n }));\n\n idsToKeep.forEach(({ id, __component }) => {\n if (!allIds.find((el) => el.id === id && el.__component === __component)) {\n const err = new Error(\n `Some of the provided components in ${attributeName} are not related to the entity`\n );\n\n Object.assign(err, { status: 400 });\n throw err;\n }\n });\n\n type IdsToDelete = Schema.Attribute.Value<Schema.Attribute.DynamicZone>;\n\n const idsToDelete = allIds.reduce((acc, { id, __component }) => {\n if (!idsToKeep.find((el) => el.id === id && el.__component === __component)) {\n acc.push({ id, __component });\n }\n\n return acc;\n }, [] as IdsToDelete);\n\n if (idsToDelete.length > 0) {\n for (const idToDelete of idsToDelete) {\n const { id, __component } = idToDelete;\n await deleteComponent(__component, { id });\n }\n }\n};\n\nconst deleteComponents = async <TUID extends UID.Schema, TEntity extends Data.Entity<TUID>>(\n uid: TUID,\n entityToDelete: TEntity,\n { loadComponents = true } = {}\n) => {\n const { attributes = {} } = strapi.getModel(uid);\n\n const attributeNames = Object.keys(attributes);\n\n for (const attributeName of attributeNames) {\n const attribute = attributes[attributeName];\n\n if (attribute.type === 'component' || attribute.type === 'dynamiczone') {\n let value;\n if (loadComponents) {\n value = await strapi.db.query(uid).load(entityToDelete, attributeName);\n } else {\n value = entityToDelete[attributeName as keyof TEntity];\n }\n\n if (!value) {\n continue;\n }\n\n if (attribute.type === 'component') {\n const { component: componentUID } = attribute;\n // MySQL/MariaDB can cause deadlocks here if concurrency higher than 1\n await async.map(\n _.castArray(value),\n (subValue: any) => deleteComponent(componentUID, subValue),\n {\n concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity,\n }\n );\n } else {\n // delete dynamic zone components\n // MySQL/MariaDB can cause deadlocks here if concurrency higher than 1\n await async.map(\n _.castArray(value),\n (subValue: any) => deleteComponent(subValue.__component, subValue),\n { concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity }\n );\n }\n\n continue;\n }\n }\n};\n\n/** *************************\n Component queries\n************************** */\n\n// components can have nested compos so this must be recursive\nconst createComponent = async <TUID extends UID.Component = UID.Component>(\n uid: TUID,\n data: Modules.EntityService.Params.Data.Input<TUID>\n) => {\n const model = strapi.getModel(uid) as Schema.Component;\n\n const componentData = await createComponents(uid, data);\n const transform = pipe(\n // Make sure we don't save the component with a pre-defined ID\n omit('id'),\n // Remove the component data from the original data object ...\n (payload) => omitComponentData(model, payload),\n // ... and assign the newly created component instead\n assign(componentData)\n );\n\n return strapi.db.query(uid).create({ data: transform(data) });\n};\n\n// components can have nested compos so this must be recursive\nconst updateComponent = async <TUID extends UID.Component>(\n uid: TUID,\n componentToUpdate: { id: Modules.EntityService.Params.Attribute.ID },\n data: Modules.EntityService.Params.Data.Input<TUID>\n) => {\n const model = strapi.getModel(uid) as Schema.Component;\n\n const componentData = await updateComponents(uid, componentToUpdate, data);\n\n return strapi.db.query(uid).update({\n where: {\n id: componentToUpdate.id,\n },\n data: Object.assign(omitComponentData(model, data), componentData),\n });\n};\n\nconst updateOrCreateComponent = <TUID extends UID.Component>(\n componentUID: TUID,\n value: Modules.EntityService.Params.Data.Input<TUID>\n) => {\n if (value === null) {\n return null;\n }\n\n // update\n if ('id' in value && typeof value.id !== 'undefined') {\n // TODO: verify the compo is associated with the entity\n return updateComponent(componentUID, { id: value.id }, value);\n }\n\n // create\n return createComponent(componentUID, value);\n};\n\nconst deleteComponent = async <TUID extends UID.Component>(\n uid: TUID,\n componentToDelete: Data.Component<TUID>\n) => {\n await deleteComponents(uid, componentToDelete);\n await strapi.db.query(uid).delete({ where: { id: componentToDelete.id } });\n};\n\ninterface IComponentIdMapping {\n uid: UID.Component;\n oldID: number;\n newID: number;\n}\n\n/**\n * Walk the source data and the newly created entity in parallel and collect\n * the [old ID, new ID] couple of every component instance found in both trees\n * (components & dynamic zones, including nested ones).\n *\n * Unlike a JSON diff, couples are also collected when the ID did not change,\n * so the result is an exhaustive map of every component instance that was\n * re-created with the entity.\n */\nconst collectComponentIdMappings = ({\n data,\n created,\n schema,\n strapi,\n}: {\n data: any;\n created: any;\n schema: Schema.Schema;\n strapi: Core.Strapi;\n}): IComponentIdMapping[] => {\n const mappings: IComponentIdMapping[] = [];\n\n const visitComponent = (uid: UID.Component, oldValue: any, newValue: any) => {\n if (!_.isObjectLike(oldValue) || !_.isObjectLike(newValue)) {\n return;\n }\n\n if (typeof oldValue.id === 'number' && typeof newValue.id === 'number') {\n mappings.push({ uid, oldID: oldValue.id, newID: newValue.id });\n }\n\n const componentSchema = strapi.getModel(uid);\n\n // Collect nested components & dynamic zones\n if (componentSchema) {\n visitSchema(componentSchema, oldValue, newValue);\n }\n };\n\n const visitSchema = (currentSchema: Schema.Schema, oldData: any, newData: any) => {\n if (!_.isObjectLike(oldData) || !_.isObjectLike(newData)) {\n return;\n }\n\n const { attributes = {} } = currentSchema;\n\n for (const [attributeName, attribute] of Object.entries(attributes)) {\n const oldValue = oldData[attributeName];\n const newValue = newData[attributeName];\n\n if (_.isNil(oldValue) || _.isNil(newValue)) {\n continue;\n }\n\n if (attribute.type === 'component') {\n const { component: componentUID, repeatable = false } = attribute;\n\n if (repeatable === true) {\n if (!Array.isArray(oldValue) || !Array.isArray(newValue)) {\n continue;\n }\n\n // Components are created (and thus populated back) in the same\n // order as the source data, pair them by index\n const length = Math.min(oldValue.length, newValue.length);\n\n for (let i = 0; i < length; i += 1) {\n visitComponent(componentUID, oldValue[i], newValue[i]);\n }\n } else {\n visitComponent(componentUID, oldValue, newValue);\n }\n }\n\n if (attribute.type === 'dynamiczone') {\n if (!Array.isArray(oldValue) || !Array.isArray(newValue)) {\n continue;\n }\n\n const length = Math.min(oldValue.length, newValue.length);\n\n for (let i = 0; i < length; i += 1) {\n const oldItem = oldValue[i];\n const newItem = newValue[i];\n const componentUID = oldItem?.__component;\n\n // Both items must reference the same dynamic zone component for the\n // ID couple to be meaningful\n if (!componentUID || (newItem?.__component && newItem.__component !== componentUID)) {\n continue;\n }\n\n visitComponent(componentUID, oldItem, newItem);\n }\n }\n }\n };\n\n visitSchema(schema, data, created);\n\n return mappings;\n};\n\n/**\n * Resolve the component UID of an entity's attribute based\n * on a given path (components & dynamic zones only)\n */\nconst resolveComponentUID = ({\n paths,\n strapi,\n data,\n contentType,\n}: {\n paths: string[];\n strapi: Core.Strapi;\n data: any;\n contentType: Schema.ContentType;\n}): UID.Schema | undefined => {\n let value: unknown = data;\n let cType:\n | Schema.ContentType\n | Schema.Component\n | ((...opts: any[]) => Schema.ContentType | Schema.Component) = contentType;\n for (const path of paths) {\n value = get(path, value);\n\n // Needed when the value of cType should be computed\n // based on the next value (eg: dynamic zones)\n if (typeof cType === 'function') {\n cType = cType(value);\n }\n\n if (path in cType.attributes) {\n const attribute: Schema.Attribute.AnyAttribute = cType.attributes[path];\n\n if (attribute.type === 'component') {\n cType = strapi.getModel(attribute.component);\n }\n\n if (attribute.type === 'dynamiczone') {\n cType = ({ __component }: { __component: UID.Component }) => strapi.getModel(__component);\n }\n }\n }\n\n if ('uid' in cType) {\n return cType.uid;\n }\n\n return undefined;\n};\n\nexport {\n omitComponentData,\n getComponents,\n createComponents,\n updateComponents,\n deleteComponents,\n deleteComponent,\n collectComponentIdMappings,\n resolveComponentUID,\n};\n"],"names":["isDialectMySQL","strapi","db","dialect","client","omitComponentData","contentType","data","attributes","componentAttributes","Object","keys","filter","attributeName","contentTypesUtils","isComponentAttribute","omit","createComponents","uid","getModel","componentBody","attributeNames","attribute","has","type","component","componentUID","repeatable","componentValue","Array","isArray","Error","components","async","map","value","createComponent","concurrency","inTransaction","Infinity","id","__pivot","field","component_type","dynamiczoneValues","createDynamicZoneComponents","__component","getComponents","entity","getComponentAttributes","_","isEmpty","query","load","deleteComponents","entityToDelete","loadComponents","castArray","subValue","deleteComponent","model","componentData","transform","pipe","payload","assign","create","componentToDelete","delete","where","collectComponentIdMappings","created","schema","mappings","visitComponent","oldValue","newValue","isObjectLike","push","oldID","newID","componentSchema","visitSchema","currentSchema","oldData","newData","entries","isNil","length","Math","min","i","oldItem","newItem"],"mappings":";;;;;;;;;;AAuBA,MAAMA,iBAAiB,IAAMC,MAAAA,CAAOC,EAAE,EAAEC,QAAQC,MAAAA,KAAW,OAAA;AAU3D,SAASC,iBAAAA,CACPC,WAAkD,EAClDC,IAAkG,EAAA;IAIlG,MAAM,EAAEC,UAAU,EAAE,GAAGF,WAAAA;AACvB,IAAA,MAAMG,mBAAAA,GAAsBC,MAAAA,CAAOC,IAAI,CAACH,YAAYI,MAAM,CAAC,CAACC,aAAAA,GAC1DC,kBAAAA,CAAkBC,oBAAoB,CAACP,UAAU,CAACK,aAAAA,CAAc,CAAA,CAAA;AAGlE,IAAA,OAAOG,QAAKP,mBAAAA,EAAqBF,IAAAA,CAAAA;AACnC;AAEA;AACA,MAAMU,gBAAAA,GAAmB,OAIvBC,GAAAA,EACAX,IAAAA,GAAAA;IAEA,MAAM,EAAEC,aAAa,EAAE,EAAE,GAAGP,MAAAA,CAAOkB,QAAQ,CAACD,GAAAA,CAAAA;AAE5C,IAAA,MAAME,gBAA+B,EAAC;IAEtC,MAAMC,cAAAA,GAAiBX,MAAAA,CAAOC,IAAI,CAACH,UAAAA,CAAAA;IAEnC,KAAK,MAAMK,iBAAiBQ,cAAAA,CAAgB;QAC1C,MAAMC,SAAAA,GAAYd,UAAU,CAACK,aAAAA,CAAc;QAE3C,IAAI,CA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AA,CAAMC,OAAO,CAAC8C,QAAAA,CAAAA,EAAW;AACxD,oBAAA;AACF,gBAAA;gBAEA,MAAMY,MAAAA,GAASC,KAAKC,GAAG,CAACf,SAASa,MAAM,EAAEZ,SAASY,MAAM,CAAA;AAExD,gBAAA,IAAK,IAAIG,CAAAA,GAAI,CAAA,EAAGA,CAAAA,GAAIH,MAAAA,EAAQG,KAAK,CAAA,CAAG;oBAClC,MAAMC,OAAAA,GAAUjB,QAAQ,CAACgB,CAAAA,CAAE;oBAC3B,MAAME,OAAAA,GAAUjB,QAAQ,CAACe,CAAAA,CAAE;AAC3B,oBAAA,MAAMjE,eAAekE,OAAAA,EAAS9C,WAAAA;;;AAI9B,oBAAA,IAAI,CAACpB,YAAAA,IAAiBmE,OAAAA,EAAS/C,eAAe+C,OAAAA,CAAQ/C,WAAW,KAAKpB,YAAAA,EAAe;AACnF,wBAAA;AACF,oBAAA;AAEAgD,oBAAAA,cAAAA,CAAehD,cAAckE,OAAAA,EAASC,OAAAA,CAAAA;AACxC,gBAAA;AACF,YAAA;AACF,QAAA;AACF,IAAA,CAAA;AAEAX,IAAAA,WAAAA,CAAYV,QAAQjE,IAAAA,EAAMgE,OAAAA,CAAAA;IAE1B,OAAOE,QAAAA;AACT;;;;;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/data-transfer",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.49.0",
|
|
4
4
|
"description": "Data transfer capabilities for Strapi",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"strapi",
|
|
@@ -51,30 +51,32 @@
|
|
|
51
51
|
"watch": "run -T rollup -c -w"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@strapi/logger": "5.
|
|
55
|
-
"@strapi/types": "5.
|
|
56
|
-
"@strapi/utils": "5.
|
|
54
|
+
"@strapi/logger": "5.49.0",
|
|
55
|
+
"@strapi/types": "5.49.0",
|
|
56
|
+
"@strapi/utils": "5.49.0",
|
|
57
57
|
"chalk": "4.1.2",
|
|
58
58
|
"cli-table3": "0.6.5",
|
|
59
59
|
"commander": "8.3.0",
|
|
60
60
|
"fs-extra": "11.3.4",
|
|
61
61
|
"inquirer": "9.3.8",
|
|
62
62
|
"lodash": "4.18.1",
|
|
63
|
+
"mime-types": "2.1.35",
|
|
63
64
|
"ora": "5.4.1",
|
|
64
65
|
"resolve-cwd": "3.0.0",
|
|
65
66
|
"semver": "7.7.4",
|
|
66
67
|
"stream-chain": "2.2.5",
|
|
67
68
|
"stream-json": "1.9.1",
|
|
68
|
-
"tar": "7.5.
|
|
69
|
+
"tar": "7.5.16",
|
|
69
70
|
"tar-stream": "2.2.0",
|
|
70
71
|
"ws": "8.20.1"
|
|
71
72
|
},
|
|
72
73
|
"devDependencies": {
|
|
73
|
-
"@strapi/database": "5.
|
|
74
|
+
"@strapi/database": "5.49.0",
|
|
74
75
|
"@types/fs-extra": "11.0.4",
|
|
75
76
|
"@types/jest": "29.5.2",
|
|
76
77
|
"@types/koa": "2.13.4",
|
|
77
78
|
"@types/lodash": "^4.14.191",
|
|
79
|
+
"@types/mime-types": "2.1.1",
|
|
78
80
|
"@types/node": "24.10.0",
|
|
79
81
|
"@types/semver": "7.5.0",
|
|
80
82
|
"@types/stream-chain": "2.0.1",
|