@strapi/data-transfer 5.0.0-beta.1 → 5.0.0-beta.3

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.
Files changed (38) hide show
  1. package/dist/engine/diagnostic.d.ts.map +1 -1
  2. package/dist/index.js +56 -30
  3. package/dist/index.js.map +1 -1
  4. package/dist/index.mjs +57 -31
  5. package/dist/index.mjs.map +1 -1
  6. package/dist/strapi/providers/local-destination/index.d.ts +2 -2
  7. package/dist/strapi/providers/local-destination/index.d.ts.map +1 -1
  8. package/dist/strapi/providers/local-destination/strategies/restore/configuration.d.ts +2 -2
  9. package/dist/strapi/providers/local-destination/strategies/restore/configuration.d.ts.map +1 -1
  10. package/dist/strapi/providers/local-destination/strategies/restore/entities.d.ts +3 -3
  11. package/dist/strapi/providers/local-destination/strategies/restore/entities.d.ts.map +1 -1
  12. package/dist/strapi/providers/local-destination/strategies/restore/index.d.ts +1 -1
  13. package/dist/strapi/providers/local-destination/strategies/restore/index.d.ts.map +1 -1
  14. package/dist/strapi/providers/local-destination/strategies/restore/links.d.ts +1 -1
  15. package/dist/strapi/providers/local-destination/strategies/restore/links.d.ts.map +1 -1
  16. package/dist/strapi/providers/local-source/assets.d.ts +1 -1
  17. package/dist/strapi/providers/local-source/assets.d.ts.map +1 -1
  18. package/dist/strapi/providers/local-source/configuration.d.ts +1 -1
  19. package/dist/strapi/providers/local-source/configuration.d.ts.map +1 -1
  20. package/dist/strapi/providers/local-source/entities.d.ts +1 -1
  21. package/dist/strapi/providers/local-source/entities.d.ts.map +1 -1
  22. package/dist/strapi/providers/local-source/index.d.ts +2 -2
  23. package/dist/strapi/providers/local-source/index.d.ts.map +1 -1
  24. package/dist/strapi/providers/local-source/links.d.ts +1 -1
  25. package/dist/strapi/providers/local-source/links.d.ts.map +1 -1
  26. package/dist/strapi/providers/remote-source/index.d.ts.map +1 -1
  27. package/dist/strapi/queries/entity.d.ts +1 -1
  28. package/dist/strapi/queries/entity.d.ts.map +1 -1
  29. package/dist/strapi/queries/link.d.ts +1 -1
  30. package/dist/strapi/queries/link.d.ts.map +1 -1
  31. package/dist/strapi/remote/handlers/utils.d.ts.map +1 -1
  32. package/dist/utils/components.d.ts +12 -2
  33. package/dist/utils/components.d.ts.map +1 -1
  34. package/dist/utils/providers.d.ts +1 -1
  35. package/dist/utils/providers.d.ts.map +1 -1
  36. package/dist/utils/transaction.d.ts +1 -1
  37. package/dist/utils/transaction.d.ts.map +1 -1
  38. package/package.json +9 -9
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, difference, set, omit, has, pipe, assign, map as map$1, size, isNil, clone, get, once, castArray, keyBy } from "lodash/fp";
5
+ import { isArray, zip, isObject, uniq, isEqual, mapValues, pick, reject as reject$1, capitalize, isNumber, isEmpty, last, difference, set, omit, get, has, pipe, 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";
@@ -1255,6 +1255,34 @@ const deleteComponent = async (uid, componentToDelete) => {
1255
1255
  await deleteComponents(uid, componentToDelete);
1256
1256
  await strapi.db.query(uid).delete({ where: { id: componentToDelete.id } });
1257
1257
  };
1258
+ const resolveComponentUID = ({
1259
+ paths,
1260
+ strapi: strapi2,
1261
+ data,
1262
+ contentType
1263
+ }) => {
1264
+ let value = data;
1265
+ let cType = contentType;
1266
+ for (const path2 of paths) {
1267
+ value = get(path2, value);
1268
+ if (typeof cType === "function") {
1269
+ cType = cType(value);
1270
+ }
1271
+ if (path2 in cType.attributes) {
1272
+ const attribute = cType.attributes[path2];
1273
+ if (attribute.type === "component") {
1274
+ cType = strapi2.getModel(attribute.component);
1275
+ }
1276
+ if (attribute.type === "dynamiczone") {
1277
+ cType = ({ __component }) => strapi2.getModel(__component);
1278
+ }
1279
+ }
1280
+ }
1281
+ if ("uid" in cType) {
1282
+ return cType.uid;
1283
+ }
1284
+ return void 0;
1285
+ };
1258
1286
  const sanitizeComponentLikeAttributes = (model, data) => {
1259
1287
  const { attributes } = model;
1260
1288
  const componentLikeAttributesKey = Object.entries(attributes).filter(([, attribute]) => attribute.type === "component" || attribute.type === "dynamiczone").map(([key]) => key);
@@ -1616,29 +1644,6 @@ const createEntitiesWriteStream = (options) => {
1616
1644
  const { type, id, data } = entity2;
1617
1645
  const { create, getDeepPopulateComponentLikeQuery } = query(type);
1618
1646
  const contentType = strapi2.getModel(type);
1619
- let cType = contentType;
1620
- const resolveType = (paths) => {
1621
- let value = data;
1622
- for (const path2 of paths) {
1623
- value = get(path2, value);
1624
- if (typeof cType === "function") {
1625
- cType = cType(value);
1626
- }
1627
- if (path2 in cType.attributes) {
1628
- const attribute = cType.attributes[path2];
1629
- if (attribute.type === "component") {
1630
- cType = strapi2.getModel(attribute.component);
1631
- }
1632
- if (attribute.type === "dynamiczone") {
1633
- cType = ({ __component }) => strapi2.getModel(__component);
1634
- }
1635
- }
1636
- }
1637
- if ("uid" in cType) {
1638
- return cType.uid;
1639
- }
1640
- return void 0;
1641
- };
1642
1647
  try {
1643
1648
  const created = await create({
1644
1649
  data,
@@ -1648,8 +1653,8 @@ const createEntitiesWriteStream = (options) => {
1648
1653
  const diffs = diff(data, created);
1649
1654
  updateMappingTable(type, id, created.id);
1650
1655
  diffs.forEach((diff2) => {
1651
- if (diff2.kind === "modified" && last(diff2.path) === "id") {
1652
- const target = resolveType(diff2.path);
1656
+ if (diff2.kind === "modified" && last(diff2.path) === "id" && "kind" in contentType) {
1657
+ const target = resolveComponentUID({ paths: diff2.path, data, contentType, strapi: strapi2 });
1653
1658
  if (!target) {
1654
1659
  return;
1655
1660
  }
@@ -2279,11 +2284,31 @@ function getFileStats(filepath, strapi2, isLocal = false) {
2279
2284
  });
2280
2285
  });
2281
2286
  }
2287
+ async function signFile(file) {
2288
+ const { provider } = strapi.plugins.upload;
2289
+ const { provider: providerName } = strapi.config.get("plugin.upload");
2290
+ const isPrivate = await provider.isPrivate();
2291
+ if (file?.provider === providerName && isPrivate) {
2292
+ const signUrl = async (file2) => {
2293
+ const signedUrl = await provider.getSignedUrl(file2);
2294
+ file2.url = signedUrl.url;
2295
+ };
2296
+ await signUrl(file);
2297
+ if (file.formats) {
2298
+ for (const format of Object.keys(file.formats)) {
2299
+ await signUrl(file.formats[format]);
2300
+ }
2301
+ }
2302
+ }
2303
+ }
2282
2304
  const createAssetsStream = (strapi2) => {
2283
2305
  const generator = async function* () {
2284
2306
  const stream2 = strapi2.db.queryBuilder("plugin::upload.file").select("*").stream();
2285
2307
  for await (const file of stream2) {
2286
2308
  const isLocalProvider = file.provider === "local";
2309
+ if (!isLocalProvider) {
2310
+ await signFile(file);
2311
+ }
2287
2312
  const filepath = isLocalProvider ? join(strapi2.dirs.static.public, file.url) : file.url;
2288
2313
  const stats = await getFileStats(filepath, strapi2, isLocalProvider);
2289
2314
  const stream22 = getFileStream(filepath, strapi2, isLocalProvider);
@@ -2941,9 +2966,7 @@ class RemoteStrapiSourceProvider {
2941
2966
  });
2942
2967
  }
2943
2968
  async getSchemas() {
2944
- const schemas = await this.dispatcher?.dispatchTransferAction(
2945
- "getSchemas"
2946
- );
2969
+ const schemas = await this.dispatcher?.dispatchTransferAction("getSchemas");
2947
2970
  return schemas ?? null;
2948
2971
  }
2949
2972
  async #startStep(step) {
@@ -3082,8 +3105,11 @@ const transformUpgradeHeader = (header = "") => {
3082
3105
  return header.split(",").map((s) => s.trim().toLowerCase());
3083
3106
  };
3084
3107
  let timeouts;
3108
+ const hasHttpServer = () => {
3109
+ return typeof strapi !== "undefined" && !!strapi?.server?.httpServer;
3110
+ };
3085
3111
  const disableTimeouts = () => {
3086
- if (!strapi?.server?.httpServer) {
3112
+ if (!hasHttpServer()) {
3087
3113
  return;
3088
3114
  }
3089
3115
  const { httpServer } = strapi.server;
@@ -3098,7 +3124,7 @@ const disableTimeouts = () => {
3098
3124
  strapi.log.info("[Data transfer] Disabling http timeouts");
3099
3125
  };
3100
3126
  const resetTimeouts = () => {
3101
- if (!strapi?.server?.httpServer || !timeouts) {
3127
+ if (!hasHttpServer() || !timeouts) {
3102
3128
  return;
3103
3129
  }
3104
3130
  const { httpServer } = strapi.server;