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

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.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) {