@strapi/data-transfer 4.6.0 → 4.6.1

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.
@@ -374,7 +374,7 @@ _TransferEngine_metadata = new WeakMap(), _TransferEngine_instances = new WeakSe
374
374
  keys.forEach((key) => {
375
375
  const sourceSchema = sourceSchemas[key];
376
376
  const destinationSchema = destinationSchemas[key];
377
- const schemaDiffs = (0, validation_1.compareSchemas)(destinationSchema, sourceSchema, strategy);
377
+ const schemaDiffs = (0, validation_1.compareSchemas)(sourceSchema, destinationSchema, strategy);
378
378
  if (schemaDiffs.length) {
379
379
  diffs[key] = schemaDiffs;
380
380
  }
@@ -388,13 +388,16 @@ _TransferEngine_metadata = new WeakMap(), _TransferEngine_instances = new WeakSe
388
388
  .map((diff) => {
389
389
  const path = diff.path.join('.');
390
390
  if (diff.kind === 'added') {
391
- return `Added "${path}": "${diff.value}" (${diff.type})`;
391
+ return `${path} exists in destination schema but not in source schema`;
392
392
  }
393
393
  if (diff.kind === 'deleted') {
394
- return `Removed "${path}"`;
394
+ return `${path} exists in source schema but not in destination schema`;
395
395
  }
396
396
  if (diff.kind === 'modified') {
397
- return `Modified "${path}": "${diff.values[0]}" (${diff.types[0]}) => "${diff.values[1]}" (${diff.types[1]})`;
397
+ if (diff.types[0] === diff.types[1]) {
398
+ return `Schema value changed at "${path}": "${diff.values[0]}" (${diff.types[0]}) => "${diff.values[1]}" (${diff.types[1]})`;
399
+ }
400
+ return `Schema has differing data types at "${path}": "${diff.values[0]}" (${diff.types[0]}) => "${diff.values[1]}" (${diff.types[1]})`;
398
401
  }
399
402
  throw new errors_1.TransferEngineValidationError(`Invalid diff found for "${uid}"`, {
400
403
  check: `schema on ${uid}`,
@@ -26,6 +26,7 @@ const stream_1 = require("stream");
26
26
  const Parser_1 = require("stream-json/jsonl/Parser");
27
27
  const encryption_1 = require("../../../utils/encryption");
28
28
  const stream_2 = require("../../../utils/stream");
29
+ const providers_1 = require("../../../errors/providers");
29
30
  /**
30
31
  * Constant for the metadata file path
31
32
  */
@@ -56,7 +57,10 @@ class LocalFileSourceProvider {
56
57
  __classPrivateFieldSet(this, _LocalFileSourceProvider_metadata, await this.getMetadata(), "f");
57
58
  }
58
59
  catch (e) {
59
- throw new Error(`Can't read file "${filePath}".`);
60
+ if (this.options?.encryption?.enabled) {
61
+ throw new providers_1.ProviderInitializationError(`Key is incorrect or the file '${filePath}' is not a valid Strapi data file.`);
62
+ }
63
+ throw new providers_1.ProviderInitializationError(`File '${filePath}' is not a valid Strapi data file.`);
60
64
  }
61
65
  }
62
66
  getMetadata() {
@@ -147,13 +151,24 @@ _LocalFileSourceProvider_metadata = new WeakMap(), _LocalFileSourceProvider_inst
147
151
  async onentry(entry) {
148
152
  const transforms = [
149
153
  // JSONL parser to read the data chunks one by one (line by line)
150
- (0, Parser_1.parser)(),
154
+ (0, Parser_1.parser)({
155
+ checkErrors: true,
156
+ }),
151
157
  // The JSONL parser returns each line as key/value
152
158
  (line) => line.value,
153
159
  ];
154
160
  const stream = entry.pipe((0, stream_chain_1.chain)(transforms));
155
- for await (const chunk of stream) {
156
- outStream.write(chunk);
161
+ try {
162
+ for await (const chunk of stream) {
163
+ outStream.write(chunk);
164
+ }
165
+ }
166
+ catch (e) {
167
+ outStream.destroy(new providers_1.ProviderTransferError(`Error parsing backup files from backup file ${entry.path}: ${e.message}`, {
168
+ details: {
169
+ error: e,
170
+ },
171
+ }));
157
172
  }
158
173
  },
159
174
  }),
@@ -163,7 +178,9 @@ _LocalFileSourceProvider_metadata = new WeakMap(), _LocalFileSourceProvider_inst
163
178
  outStream.end();
164
179
  });
165
180
  return outStream;
166
- }, _LocalFileSourceProvider_parseJSONFile = async function _LocalFileSourceProvider_parseJSONFile(fileStream, filePath) {
181
+ }, _LocalFileSourceProvider_parseJSONFile =
182
+ // For collecting an entire JSON file then parsing it, not for streaming JSONL
183
+ async function _LocalFileSourceProvider_parseJSONFile(fileStream, filePath) {
167
184
  return new Promise((resolve, reject) => {
168
185
  (0, stream_1.pipeline)([
169
186
  fileStream,
@@ -136,7 +136,7 @@ class LocalStrapiDestinationProvider {
136
136
  (0, providers_2.assertValidStrapi)(this.strapi, 'Not able to stream Assets');
137
137
  const assetsDirectory = path_1.default.join(this.strapi.dirs.static.public, 'uploads');
138
138
  const backupDirectory = path_1.default.join(this.strapi.dirs.static.public, `uploads_backup_${Date.now()}`);
139
- await fse.rename(assetsDirectory, backupDirectory);
139
+ await fse.move(assetsDirectory, backupDirectory);
140
140
  await fse.mkdir(assetsDirectory);
141
141
  // Create a .gitkeep file to ensure the directory is not empty
142
142
  await fse.outputFile(path_1.default.join(assetsDirectory, '.gitkeep'), '');
@@ -155,7 +155,7 @@ class LocalStrapiDestinationProvider {
155
155
  .on('error', async (error) => {
156
156
  try {
157
157
  await fse.rm(assetsDirectory, { recursive: true, force: true });
158
- await fse.rename(backupDirectory, assetsDirectory);
158
+ await fse.move(backupDirectory, assetsDirectory);
159
159
  this.destroy(new providers_1.ProviderTransferError(`There was an error during the transfer process. The original files have been restored to ${assetsDirectory}`));
160
160
  }
161
161
  catch (err) {
package/lib/utils/json.js CHANGED
@@ -33,12 +33,6 @@ const diff = (a, b, ctx = createContext()) => {
33
33
  });
34
34
  return diffs;
35
35
  };
36
- if (aType === 'undefined') {
37
- return added();
38
- }
39
- if (bType === 'undefined') {
40
- return deleted();
41
- }
42
36
  if ((0, fp_1.isArray)(a) && (0, fp_1.isArray)(b)) {
43
37
  let k = 0;
44
38
  for (const [aItem, bItem] of (0, fp_1.zip)(a, b)) {
@@ -60,6 +54,12 @@ const diff = (a, b, ctx = createContext()) => {
60
54
  return diffs;
61
55
  }
62
56
  if (!(0, fp_1.isEqual)(a, b)) {
57
+ if (aType === 'undefined') {
58
+ return added();
59
+ }
60
+ if (bType === 'undefined') {
61
+ return deleted();
62
+ }
63
63
  return modified();
64
64
  }
65
65
  return diffs;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/data-transfer",
3
- "version": "4.6.0",
3
+ "version": "4.6.1",
4
4
  "description": "Data transfer capabilities for Strapi",
5
5
  "keywords": [
6
6
  "strapi",
@@ -39,8 +39,8 @@
39
39
  "lib": "./lib"
40
40
  },
41
41
  "dependencies": {
42
- "@strapi/logger": "4.6.0",
43
- "@strapi/strapi": "4.6.0",
42
+ "@strapi/logger": "4.6.1",
43
+ "@strapi/strapi": "4.6.1",
44
44
  "chalk": "4.1.2",
45
45
  "fs-extra": "10.0.0",
46
46
  "lodash": "4.17.21",
@@ -60,7 +60,7 @@
60
60
  "@types/koa": "2.13.4",
61
61
  "@types/semver": "7.3.13",
62
62
  "@types/stream-chain": "2.0.1",
63
- "@types/stream-json": "1.7.2",
63
+ "@types/stream-json": "1.7.3",
64
64
  "@types/tar": "6.1.3",
65
65
  "@types/tar-stream": "2.2.2",
66
66
  "@types/uuid": "9.0.0",
@@ -73,5 +73,5 @@
73
73
  "node": ">=14.19.1 <=18.x.x",
74
74
  "npm": ">=6.0.0"
75
75
  },
76
- "gitHead": "a9e55435c489f3379d88565bf3f729deb29bfb45"
76
+ "gitHead": "17a7845e3d453ea2e7911bda6ec25ed196dd5f16"
77
77
  }