@strapi/data-transfer 5.0.0-beta.0 → 5.0.0-beta.10
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/engine/diagnostic.d.ts.map +1 -1
- package/dist/engine/index.d.ts.map +1 -1
- package/dist/engine/validation/provider.d.ts +1 -1
- package/dist/engine/validation/provider.d.ts.map +1 -1
- package/dist/engine/validation/schemas/index.d.ts.map +1 -1
- package/dist/file/providers/destination/utils.d.ts.map +1 -1
- package/dist/file/providers/source/index.d.ts +1 -3
- package/dist/file/providers/source/index.d.ts.map +1 -1
- package/dist/index.js +84 -53
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +85 -54
- package/dist/index.mjs.map +1 -1
- package/dist/strapi/providers/local-destination/index.d.ts +4 -4
- package/dist/strapi/providers/local-destination/index.d.ts.map +1 -1
- package/dist/strapi/providers/local-destination/strategies/restore/configuration.d.ts +3 -3
- package/dist/strapi/providers/local-destination/strategies/restore/configuration.d.ts.map +1 -1
- package/dist/strapi/providers/local-destination/strategies/restore/entities.d.ts +5 -5
- package/dist/strapi/providers/local-destination/strategies/restore/entities.d.ts.map +1 -1
- package/dist/strapi/providers/local-destination/strategies/restore/index.d.ts +3 -3
- package/dist/strapi/providers/local-destination/strategies/restore/index.d.ts.map +1 -1
- package/dist/strapi/providers/local-destination/strategies/restore/links.d.ts +2 -2
- package/dist/strapi/providers/local-destination/strategies/restore/links.d.ts.map +1 -1
- package/dist/strapi/providers/local-source/assets.d.ts +2 -2
- package/dist/strapi/providers/local-source/assets.d.ts.map +1 -1
- package/dist/strapi/providers/local-source/configuration.d.ts +2 -2
- package/dist/strapi/providers/local-source/configuration.d.ts.map +1 -1
- package/dist/strapi/providers/local-source/entities.d.ts +2 -2
- package/dist/strapi/providers/local-source/entities.d.ts.map +1 -1
- package/dist/strapi/providers/local-source/index.d.ts +4 -4
- package/dist/strapi/providers/local-source/index.d.ts.map +1 -1
- package/dist/strapi/providers/local-source/links.d.ts +2 -2
- package/dist/strapi/providers/local-source/links.d.ts.map +1 -1
- package/dist/strapi/providers/remote-destination/index.d.ts +2 -2
- package/dist/strapi/providers/remote-source/index.d.ts +2 -2
- package/dist/strapi/providers/remote-source/index.d.ts.map +1 -1
- package/dist/strapi/providers/utils.d.ts +1 -1
- package/dist/strapi/providers/utils.d.ts.map +1 -1
- package/dist/strapi/queries/entity.d.ts +2 -2
- package/dist/strapi/queries/entity.d.ts.map +1 -1
- package/dist/strapi/queries/link.d.ts +3 -2
- package/dist/strapi/queries/link.d.ts.map +1 -1
- package/dist/strapi/remote/handlers/utils.d.ts.map +1 -1
- package/dist/utils/components.d.ts +23 -13
- package/dist/utils/components.d.ts.map +1 -1
- package/dist/utils/middleware.d.ts.map +1 -1
- package/dist/utils/providers.d.ts +2 -2
- package/dist/utils/providers.d.ts.map +1 -1
- package/dist/utils/schema.d.ts +3 -2
- package/dist/utils/schema.d.ts.map +1 -1
- package/dist/utils/stream.d.ts.map +1 -1
- package/dist/utils/transaction.d.ts +2 -2
- package/dist/utils/transaction.d.ts.map +1 -1
- package/package.json +11 -11
package/dist/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { Transform, PassThrough, Writable, Readable, Duplex, pipeline } from "st
|
|
|
2
2
|
import path, { extname, join, posix } from "path";
|
|
3
3
|
import { EOL } from "os";
|
|
4
4
|
import { chain } from "stream-chain";
|
|
5
|
-
import { isArray, zip, isObject, uniq, isEqual, mapValues, pick, reject as reject$1, capitalize, isNumber, isEmpty, last,
|
|
5
|
+
import { isArray, zip, isObject, uniq, isEqual, mapValues, pick, reject as reject$1, capitalize, isNumber, isEmpty, last, set, get, has, pipe, omit, assign, map as map$1, size, isNil, clone, once, castArray, keyBy } from "lodash/fp";
|
|
6
6
|
import { diff as diff$1 } from "semver";
|
|
7
7
|
import { scryptSync, createCipheriv, createDecipheriv, randomUUID } from "crypto";
|
|
8
8
|
import { EventEmitter } from "events";
|
|
@@ -196,9 +196,13 @@ const VALID_SCHEMA_PROPERTIES = [
|
|
|
196
196
|
const mapSchemasValues = (schemas) => {
|
|
197
197
|
return mapValues(pick(VALID_SCHEMA_PROPERTIES), schemas);
|
|
198
198
|
};
|
|
199
|
+
const schemasToValidJSON = (schemas) => {
|
|
200
|
+
return JSON.parse(JSON.stringify(schemas));
|
|
201
|
+
};
|
|
199
202
|
const schema = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
200
203
|
__proto__: null,
|
|
201
|
-
mapSchemasValues
|
|
204
|
+
mapSchemasValues,
|
|
205
|
+
schemasToValidJSON
|
|
202
206
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
203
207
|
const createTransaction = (strapi2) => {
|
|
204
208
|
const fns = [];
|
|
@@ -308,7 +312,7 @@ const isAttributeIgnorable = (diff2) => {
|
|
|
308
312
|
return diff2.path.length === 3 && // Root property must be attributes
|
|
309
313
|
diff2.path[0] === "attributes" && // Need a valid string attribute name
|
|
310
314
|
typeof diff2.path[1] === "string" && // The diff must be on ignorable attribute properties
|
|
311
|
-
["private", "required", "configurable"].includes(diff2.path[2]);
|
|
315
|
+
["private", "required", "configurable", "default"].includes(diff2.path[2]);
|
|
312
316
|
};
|
|
313
317
|
const isOptionalAdminType = (diff2) => {
|
|
314
318
|
if ("value" in diff2 && isObject(diff2.value)) {
|
|
@@ -1040,8 +1044,8 @@ ${formattedDiffs}`,
|
|
|
1040
1044
|
}
|
|
1041
1045
|
const { type, data } = entity2;
|
|
1042
1046
|
const attributes = schemas[type].attributes;
|
|
1043
|
-
const
|
|
1044
|
-
const updatedEntity = set("data",
|
|
1047
|
+
const attributesToKeep = Object.keys(attributes).concat("documentId");
|
|
1048
|
+
const updatedEntity = set("data", pick(attributesToKeep, data), entity2);
|
|
1045
1049
|
callback(null, updatedEntity);
|
|
1046
1050
|
}
|
|
1047
1051
|
})
|
|
@@ -1255,6 +1259,34 @@ const deleteComponent = async (uid, componentToDelete) => {
|
|
|
1255
1259
|
await deleteComponents(uid, componentToDelete);
|
|
1256
1260
|
await strapi.db.query(uid).delete({ where: { id: componentToDelete.id } });
|
|
1257
1261
|
};
|
|
1262
|
+
const resolveComponentUID = ({
|
|
1263
|
+
paths,
|
|
1264
|
+
strapi: strapi2,
|
|
1265
|
+
data,
|
|
1266
|
+
contentType
|
|
1267
|
+
}) => {
|
|
1268
|
+
let value = data;
|
|
1269
|
+
let cType = contentType;
|
|
1270
|
+
for (const path2 of paths) {
|
|
1271
|
+
value = get(path2, value);
|
|
1272
|
+
if (typeof cType === "function") {
|
|
1273
|
+
cType = cType(value);
|
|
1274
|
+
}
|
|
1275
|
+
if (path2 in cType.attributes) {
|
|
1276
|
+
const attribute = cType.attributes[path2];
|
|
1277
|
+
if (attribute.type === "component") {
|
|
1278
|
+
cType = strapi2.getModel(attribute.component);
|
|
1279
|
+
}
|
|
1280
|
+
if (attribute.type === "dynamiczone") {
|
|
1281
|
+
cType = ({ __component }) => strapi2.getModel(__component);
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
if ("uid" in cType) {
|
|
1286
|
+
return cType.uid;
|
|
1287
|
+
}
|
|
1288
|
+
return void 0;
|
|
1289
|
+
};
|
|
1258
1290
|
const sanitizeComponentLikeAttributes = (model, data) => {
|
|
1259
1291
|
const { attributes } = model;
|
|
1260
1292
|
const componentLikeAttributesKey = Object.entries(attributes).filter(([, attribute]) => attribute.type === "component" || attribute.type === "dynamiczone").map(([key]) => key);
|
|
@@ -1273,13 +1305,9 @@ const createEntityQuery = (strapi2) => {
|
|
|
1273
1305
|
return getComponents(uid, entity2);
|
|
1274
1306
|
},
|
|
1275
1307
|
delete(uid, componentsToDelete) {
|
|
1276
|
-
return deleteComponents(
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
{
|
|
1280
|
-
loadComponents: false
|
|
1281
|
-
}
|
|
1282
|
-
);
|
|
1308
|
+
return deleteComponents(uid, componentsToDelete, {
|
|
1309
|
+
loadComponents: false
|
|
1310
|
+
});
|
|
1283
1311
|
}
|
|
1284
1312
|
};
|
|
1285
1313
|
const query = (uid) => {
|
|
@@ -1508,6 +1536,9 @@ const createLinkQuery = (strapi2, trx) => {
|
|
|
1508
1536
|
const metadata = strapi2.db.metadata.get(left.type);
|
|
1509
1537
|
const attribute = metadata.attributes[left.field];
|
|
1510
1538
|
const payload = {};
|
|
1539
|
+
if (!attribute) {
|
|
1540
|
+
return;
|
|
1541
|
+
}
|
|
1511
1542
|
if (attribute.type !== "relation") {
|
|
1512
1543
|
throw new Error(`Attribute ${left.field} is not a relation`);
|
|
1513
1544
|
}
|
|
@@ -1585,9 +1616,7 @@ const filterValidRelationalAttributes = (attributes) => {
|
|
|
1585
1616
|
const isOwner = (attribute) => {
|
|
1586
1617
|
return attribute.owner || !attribute.mappedBy && !attribute.morphBy;
|
|
1587
1618
|
};
|
|
1588
|
-
const isComponentLike = (attribute) =>
|
|
1589
|
-
return attribute.component || attribute.components;
|
|
1590
|
-
};
|
|
1619
|
+
const isComponentLike = (attribute) => attribute.joinTable?.name.endsWith("_cmps");
|
|
1591
1620
|
return Object.entries(attributes).filter(([, attribute]) => {
|
|
1592
1621
|
return attribute.type === "relation" && isOwner(attribute) && !isComponentLike(attribute);
|
|
1593
1622
|
}).reduce((acc, [key, attribute]) => ({ ...acc, [key]: attribute }), {});
|
|
@@ -1603,7 +1632,8 @@ const getLinkKind = (attribute, uid) => {
|
|
|
1603
1632
|
};
|
|
1604
1633
|
const link = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
1605
1634
|
__proto__: null,
|
|
1606
|
-
createLinkQuery
|
|
1635
|
+
createLinkQuery,
|
|
1636
|
+
filterValidRelationalAttributes
|
|
1607
1637
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
1608
1638
|
const index$6 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
1609
1639
|
__proto__: null,
|
|
@@ -1620,29 +1650,6 @@ const createEntitiesWriteStream = (options) => {
|
|
|
1620
1650
|
const { type, id, data } = entity2;
|
|
1621
1651
|
const { create, getDeepPopulateComponentLikeQuery } = query(type);
|
|
1622
1652
|
const contentType = strapi2.getModel(type);
|
|
1623
|
-
let cType = contentType;
|
|
1624
|
-
const resolveType = (paths) => {
|
|
1625
|
-
let value = data;
|
|
1626
|
-
for (const path2 of paths) {
|
|
1627
|
-
value = get(path2, value);
|
|
1628
|
-
if (typeof cType === "function") {
|
|
1629
|
-
cType = cType(value);
|
|
1630
|
-
}
|
|
1631
|
-
if (path2 in cType.attributes) {
|
|
1632
|
-
const attribute = cType.attributes[path2];
|
|
1633
|
-
if (attribute.type === "component") {
|
|
1634
|
-
cType = strapi2.getModel(attribute.component);
|
|
1635
|
-
}
|
|
1636
|
-
if (attribute.type === "dynamiczone") {
|
|
1637
|
-
cType = ({ __component }) => strapi2.getModel(__component);
|
|
1638
|
-
}
|
|
1639
|
-
}
|
|
1640
|
-
}
|
|
1641
|
-
if ("uid" in cType) {
|
|
1642
|
-
return cType.uid;
|
|
1643
|
-
}
|
|
1644
|
-
return void 0;
|
|
1645
|
-
};
|
|
1646
1653
|
try {
|
|
1647
1654
|
const created = await create({
|
|
1648
1655
|
data,
|
|
@@ -1652,8 +1659,8 @@ const createEntitiesWriteStream = (options) => {
|
|
|
1652
1659
|
const diffs = diff(data, created);
|
|
1653
1660
|
updateMappingTable(type, id, created.id);
|
|
1654
1661
|
diffs.forEach((diff2) => {
|
|
1655
|
-
if (diff2.kind === "modified" && last(diff2.path) === "id") {
|
|
1656
|
-
const target =
|
|
1662
|
+
if (diff2.kind === "modified" && last(diff2.path) === "id" && "kind" in contentType) {
|
|
1663
|
+
const target = resolveComponentUID({ paths: diff2.path, data, contentType, strapi: strapi2 });
|
|
1657
1664
|
if (!target) {
|
|
1658
1665
|
return;
|
|
1659
1666
|
}
|
|
@@ -1966,10 +1973,10 @@ class LocalStrapiDestinationProvider {
|
|
|
1966
1973
|
}
|
|
1967
1974
|
getSchemas() {
|
|
1968
1975
|
assertValidStrapi(this.strapi, "Not able to get Schemas");
|
|
1969
|
-
const schemas = {
|
|
1976
|
+
const schemas = schemasToValidJSON({
|
|
1970
1977
|
...this.strapi.contentTypes,
|
|
1971
1978
|
...this.strapi.components
|
|
1972
|
-
};
|
|
1979
|
+
});
|
|
1973
1980
|
return mapSchemasValues(schemas);
|
|
1974
1981
|
}
|
|
1975
1982
|
createEntitiesWriteStream() {
|
|
@@ -2283,11 +2290,31 @@ function getFileStats(filepath, strapi2, isLocal = false) {
|
|
|
2283
2290
|
});
|
|
2284
2291
|
});
|
|
2285
2292
|
}
|
|
2293
|
+
async function signFile(file) {
|
|
2294
|
+
const { provider } = strapi.plugins.upload;
|
|
2295
|
+
const { provider: providerName } = strapi.config.get("plugin.upload");
|
|
2296
|
+
const isPrivate = await provider.isPrivate();
|
|
2297
|
+
if (file?.provider === providerName && isPrivate) {
|
|
2298
|
+
const signUrl = async (file2) => {
|
|
2299
|
+
const signedUrl = await provider.getSignedUrl(file2);
|
|
2300
|
+
file2.url = signedUrl.url;
|
|
2301
|
+
};
|
|
2302
|
+
await signUrl(file);
|
|
2303
|
+
if (file.formats) {
|
|
2304
|
+
for (const format of Object.keys(file.formats)) {
|
|
2305
|
+
await signUrl(file.formats[format]);
|
|
2306
|
+
}
|
|
2307
|
+
}
|
|
2308
|
+
}
|
|
2309
|
+
}
|
|
2286
2310
|
const createAssetsStream = (strapi2) => {
|
|
2287
2311
|
const generator = async function* () {
|
|
2288
2312
|
const stream2 = strapi2.db.queryBuilder("plugin::upload.file").select("*").stream();
|
|
2289
2313
|
for await (const file of stream2) {
|
|
2290
2314
|
const isLocalProvider = file.provider === "local";
|
|
2315
|
+
if (!isLocalProvider) {
|
|
2316
|
+
await signFile(file);
|
|
2317
|
+
}
|
|
2291
2318
|
const filepath = isLocalProvider ? join(strapi2.dirs.static.public, file.url) : file.url;
|
|
2292
2319
|
const stats = await getFileStats(filepath, strapi2, isLocalProvider);
|
|
2293
2320
|
const stream22 = getFileStream(filepath, strapi2, isLocalProvider);
|
|
@@ -2367,10 +2394,10 @@ class LocalStrapiSourceProvider {
|
|
|
2367
2394
|
}
|
|
2368
2395
|
getSchemas() {
|
|
2369
2396
|
assertValidStrapi(this.strapi, "Not able to get Schemas");
|
|
2370
|
-
const schemas = {
|
|
2397
|
+
const schemas = schemasToValidJSON({
|
|
2371
2398
|
...this.strapi.contentTypes,
|
|
2372
2399
|
...this.strapi.components
|
|
2373
|
-
};
|
|
2400
|
+
});
|
|
2374
2401
|
return mapSchemasValues(schemas);
|
|
2375
2402
|
}
|
|
2376
2403
|
createSchemasReadStream() {
|
|
@@ -2945,10 +2972,8 @@ class RemoteStrapiSourceProvider {
|
|
|
2945
2972
|
});
|
|
2946
2973
|
}
|
|
2947
2974
|
async getSchemas() {
|
|
2948
|
-
const schemas = await this.dispatcher?.dispatchTransferAction(
|
|
2949
|
-
|
|
2950
|
-
) ?? null;
|
|
2951
|
-
return schemas;
|
|
2975
|
+
const schemas = await this.dispatcher?.dispatchTransferAction("getSchemas");
|
|
2976
|
+
return schemas ?? null;
|
|
2952
2977
|
}
|
|
2953
2978
|
async #startStep(step) {
|
|
2954
2979
|
try {
|
|
@@ -3086,8 +3111,11 @@ const transformUpgradeHeader = (header = "") => {
|
|
|
3086
3111
|
return header.split(",").map((s) => s.trim().toLowerCase());
|
|
3087
3112
|
};
|
|
3088
3113
|
let timeouts;
|
|
3114
|
+
const hasHttpServer = () => {
|
|
3115
|
+
return typeof strapi !== "undefined" && !!strapi?.server?.httpServer;
|
|
3116
|
+
};
|
|
3089
3117
|
const disableTimeouts = () => {
|
|
3090
|
-
if (!
|
|
3118
|
+
if (!hasHttpServer()) {
|
|
3091
3119
|
return;
|
|
3092
3120
|
}
|
|
3093
3121
|
const { httpServer } = strapi.server;
|
|
@@ -3102,7 +3130,7 @@ const disableTimeouts = () => {
|
|
|
3102
3130
|
strapi.log.info("[Data transfer] Disabling http timeouts");
|
|
3103
3131
|
};
|
|
3104
3132
|
const resetTimeouts = () => {
|
|
3105
|
-
if (!
|
|
3133
|
+
if (!hasHttpServer() || !timeouts) {
|
|
3106
3134
|
return;
|
|
3107
3135
|
}
|
|
3108
3136
|
const { httpServer } = strapi.server;
|
|
@@ -3945,11 +3973,14 @@ class LocalFileSourceProvider {
|
|
|
3945
3973
|
return this.#metadata ?? null;
|
|
3946
3974
|
}
|
|
3947
3975
|
async getSchemas() {
|
|
3948
|
-
const
|
|
3949
|
-
|
|
3976
|
+
const schemaCollection = await collect(
|
|
3977
|
+
this.createSchemasReadStream()
|
|
3978
|
+
);
|
|
3979
|
+
if (isEmpty(schemaCollection)) {
|
|
3950
3980
|
throw new ProviderInitializationError("Could not load schemas from Strapi data file.");
|
|
3951
3981
|
}
|
|
3952
|
-
|
|
3982
|
+
const schemas = keyBy("uid", schemaCollection);
|
|
3983
|
+
return schemasToValidJSON(schemas);
|
|
3953
3984
|
}
|
|
3954
3985
|
createEntitiesReadStream() {
|
|
3955
3986
|
return this.#streamJsonlDirectory("entities");
|