@strapi/data-transfer 4.21.0 → 4.22.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/index.js +49 -24
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +50 -25
- package/dist/index.mjs.map +1 -1
- package/dist/strapi/providers/local-destination/strategies/restore/entities.d.ts +2 -2
- package/dist/strapi/providers/local-destination/strategies/restore/entities.d.ts.map +1 -1
- package/dist/strapi/providers/local-source/assets.d.ts.map +1 -1
- package/dist/utils/components.d.ts +12 -2
- package/dist/utils/components.d.ts.map +1 -1
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -1295,6 +1295,34 @@ const deleteComponent = async (uid, componentToDelete) => {
|
|
|
1295
1295
|
await deleteComponents(uid, componentToDelete);
|
|
1296
1296
|
await strapi.query(uid).delete({ where: { id: componentToDelete.id } });
|
|
1297
1297
|
};
|
|
1298
|
+
const resolveComponentUID = ({
|
|
1299
|
+
paths,
|
|
1300
|
+
strapi: strapi2,
|
|
1301
|
+
data,
|
|
1302
|
+
contentType
|
|
1303
|
+
}) => {
|
|
1304
|
+
let value = data;
|
|
1305
|
+
let cType = contentType;
|
|
1306
|
+
for (const path2 of paths) {
|
|
1307
|
+
value = fp.get(path2, value);
|
|
1308
|
+
if (typeof cType === "function") {
|
|
1309
|
+
cType = cType(value);
|
|
1310
|
+
}
|
|
1311
|
+
if (path2 in cType.attributes) {
|
|
1312
|
+
const attribute = cType.attributes[path2];
|
|
1313
|
+
if (attribute.type === "component") {
|
|
1314
|
+
cType = strapi2.getModel(attribute.component);
|
|
1315
|
+
}
|
|
1316
|
+
if (attribute.type === "dynamiczone") {
|
|
1317
|
+
cType = ({ __component }) => strapi2.getModel(__component);
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1321
|
+
if ("uid" in cType) {
|
|
1322
|
+
return cType.uid;
|
|
1323
|
+
}
|
|
1324
|
+
return void 0;
|
|
1325
|
+
};
|
|
1298
1326
|
const sanitizeComponentLikeAttributes = (model, data) => {
|
|
1299
1327
|
const { attributes } = model;
|
|
1300
1328
|
const componentLikeAttributesKey = Object.entries(attributes).filter(([, attribute]) => attribute.type === "component" || attribute.type === "dynamiczone").map(([key]) => key);
|
|
@@ -1660,29 +1688,6 @@ const createEntitiesWriteStream = (options) => {
|
|
|
1660
1688
|
const { type, id, data } = entity2;
|
|
1661
1689
|
const { create, getDeepPopulateComponentLikeQuery } = query(type);
|
|
1662
1690
|
const contentType = strapi2.getModel(type);
|
|
1663
|
-
let cType = contentType;
|
|
1664
|
-
const resolveType = (paths) => {
|
|
1665
|
-
let value = data;
|
|
1666
|
-
for (const path2 of paths) {
|
|
1667
|
-
value = fp.get(path2, value);
|
|
1668
|
-
if (typeof cType === "function") {
|
|
1669
|
-
cType = cType(value);
|
|
1670
|
-
}
|
|
1671
|
-
if (path2 in cType.attributes) {
|
|
1672
|
-
const attribute = cType.attributes[path2];
|
|
1673
|
-
if (attribute.type === "component") {
|
|
1674
|
-
cType = strapi2.getModel(attribute.component);
|
|
1675
|
-
}
|
|
1676
|
-
if (attribute.type === "dynamiczone") {
|
|
1677
|
-
cType = ({ __component }) => strapi2.getModel(__component);
|
|
1678
|
-
}
|
|
1679
|
-
}
|
|
1680
|
-
}
|
|
1681
|
-
if ("uid" in cType) {
|
|
1682
|
-
return cType.uid;
|
|
1683
|
-
}
|
|
1684
|
-
return void 0;
|
|
1685
|
-
};
|
|
1686
1691
|
try {
|
|
1687
1692
|
const created = await create({
|
|
1688
1693
|
data,
|
|
@@ -1693,7 +1698,7 @@ const createEntitiesWriteStream = (options) => {
|
|
|
1693
1698
|
updateMappingTable(type, id, created.id);
|
|
1694
1699
|
diffs.forEach((diff2) => {
|
|
1695
1700
|
if (diff2.kind === "modified" && fp.last(diff2.path) === "id") {
|
|
1696
|
-
const target =
|
|
1701
|
+
const target = resolveComponentUID({ paths: diff2.path, data, contentType, strapi: strapi2 });
|
|
1697
1702
|
if (!target) {
|
|
1698
1703
|
return;
|
|
1699
1704
|
}
|
|
@@ -2309,11 +2314,31 @@ function getFileStats(filepath, isLocal = false) {
|
|
|
2309
2314
|
});
|
|
2310
2315
|
});
|
|
2311
2316
|
}
|
|
2317
|
+
async function signFile(file2) {
|
|
2318
|
+
const { provider } = strapi.plugins.upload;
|
|
2319
|
+
const { provider: providerName } = strapi.config.get("plugin.upload");
|
|
2320
|
+
const isPrivate = await provider.isPrivate();
|
|
2321
|
+
if (file2?.provider === providerName && isPrivate) {
|
|
2322
|
+
const signUrl = async (file22) => {
|
|
2323
|
+
const signedUrl = await provider.getSignedUrl(file22);
|
|
2324
|
+
file22.url = signedUrl.url;
|
|
2325
|
+
};
|
|
2326
|
+
await signUrl(file2);
|
|
2327
|
+
if (file2.formats) {
|
|
2328
|
+
for (const format of Object.keys(file2.formats)) {
|
|
2329
|
+
await signUrl(file2.formats[format]);
|
|
2330
|
+
}
|
|
2331
|
+
}
|
|
2332
|
+
}
|
|
2333
|
+
}
|
|
2312
2334
|
const createAssetsStream = (strapi2) => {
|
|
2313
2335
|
const generator = async function* () {
|
|
2314
2336
|
const stream2 = strapi2.db.queryBuilder("plugin::upload.file").select("*").stream();
|
|
2315
2337
|
for await (const file2 of stream2) {
|
|
2316
2338
|
const isLocalProvider = file2.provider === "local";
|
|
2339
|
+
if (!isLocalProvider) {
|
|
2340
|
+
await signFile(file2);
|
|
2341
|
+
}
|
|
2317
2342
|
const filepath = isLocalProvider ? path.join(strapi2.dirs.static.public, file2.url) : file2.url;
|
|
2318
2343
|
const stats = await getFileStats(filepath, isLocalProvider);
|
|
2319
2344
|
const stream22 = getFileStream(filepath, isLocalProvider);
|