@strapi/data-transfer 4.6.0-alpha.0 → 4.6.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.
Files changed (99) hide show
  1. package/jest.config.js +3 -1
  2. package/{dist → lib}/engine/index.d.ts +17 -10
  3. package/lib/engine/index.js +359 -0
  4. package/lib/engine/validation/index.d.ts +1 -0
  5. package/lib/engine/validation/index.js +28 -0
  6. package/lib/engine/validation/schemas/index.d.ts +7 -0
  7. package/lib/engine/validation/schemas/index.js +53 -0
  8. package/lib/file/index.d.ts +1 -0
  9. package/lib/file/index.js +28 -0
  10. package/{dist/providers/local-file-destination-provider.d.ts → lib/file/providers/destination/index.d.ts} +10 -6
  11. package/{dist/providers/local-file-destination-provider.js → lib/file/providers/destination/index.js} +59 -87
  12. package/lib/file/providers/destination/utils.d.ts +9 -0
  13. package/lib/file/providers/destination/utils.js +61 -0
  14. package/lib/file/providers/index.d.ts +2 -0
  15. package/{dist → lib/file}/providers/index.js +2 -6
  16. package/lib/file/providers/source/index.d.ts +40 -0
  17. package/{dist/providers/local-file-source-provider.js → lib/file/providers/source/index.js} +94 -51
  18. package/lib/index.d.ts +4 -0
  19. package/lib/index.js +31 -0
  20. package/lib/strapi/index.d.ts +4 -0
  21. package/lib/strapi/index.js +35 -0
  22. package/lib/strapi/providers/index.d.ts +3 -0
  23. package/lib/strapi/providers/index.js +22 -0
  24. package/lib/strapi/providers/local-destination/index.d.ts +32 -0
  25. package/lib/strapi/providers/local-destination/index.js +195 -0
  26. package/lib/strapi/providers/local-destination/strategies/index.d.ts +1 -0
  27. package/lib/strapi/providers/local-destination/strategies/index.js +28 -0
  28. package/lib/strapi/providers/local-destination/strategies/restore/configuration.d.ts +5 -0
  29. package/lib/strapi/providers/local-destination/strategies/restore/configuration.js +44 -0
  30. package/lib/strapi/providers/local-destination/strategies/restore/entities.d.ts +9 -0
  31. package/lib/strapi/providers/local-destination/strategies/restore/entities.js +100 -0
  32. package/lib/strapi/providers/local-destination/strategies/restore/index.d.ts +32 -0
  33. package/lib/strapi/providers/local-destination/strategies/restore/index.js +106 -0
  34. package/lib/strapi/providers/local-destination/strategies/restore/links.d.ts +3 -0
  35. package/lib/strapi/providers/local-destination/strategies/restore/links.js +29 -0
  36. package/lib/strapi/providers/local-source/assets.d.ts +5 -0
  37. package/lib/strapi/providers/local-source/assets.js +31 -0
  38. package/{dist/providers/local-strapi-source-provider → lib/strapi/providers/local-source}/configuration.d.ts +0 -0
  39. package/{dist/providers/local-strapi-source-provider → lib/strapi/providers/local-source}/configuration.js +13 -14
  40. package/{dist/providers/local-strapi-source-provider → lib/strapi/providers/local-source}/entities.d.ts +0 -0
  41. package/lib/strapi/providers/local-source/entities.js +85 -0
  42. package/{dist/providers/local-strapi-source-provider → lib/strapi/providers/local-source}/index.d.ts +9 -8
  43. package/{dist/providers/local-strapi-source-provider → lib/strapi/providers/local-source}/index.js +36 -6
  44. package/{dist/providers/local-strapi-source-provider/links/index.d.ts → lib/strapi/providers/local-source/links.d.ts} +1 -1
  45. package/lib/strapi/providers/local-source/links.js +23 -0
  46. package/lib/strapi/providers/remote-destination/index.d.ts +40 -0
  47. package/lib/strapi/providers/remote-destination/index.js +171 -0
  48. package/lib/strapi/providers/remote-destination/utils.d.ts +31 -0
  49. package/lib/strapi/providers/remote-destination/utils.js +72 -0
  50. package/lib/strapi/queries/entity.d.ts +19 -0
  51. package/lib/strapi/queries/entity.js +130 -0
  52. package/lib/strapi/queries/index.d.ts +2 -0
  53. package/lib/strapi/queries/index.js +29 -0
  54. package/lib/strapi/queries/link.d.ts +6 -0
  55. package/lib/strapi/queries/link.js +201 -0
  56. package/lib/strapi/register.d.ts +7 -0
  57. package/lib/strapi/register.js +13 -0
  58. package/lib/strapi/remote/constants.d.ts +1 -0
  59. package/lib/strapi/remote/constants.js +5 -0
  60. package/lib/strapi/remote/controllers/index.d.ts +1 -0
  61. package/{dist → lib/strapi/remote/controllers}/index.js +1 -2
  62. package/lib/strapi/remote/controllers/push.d.ts +25 -0
  63. package/lib/strapi/remote/controllers/push.js +95 -0
  64. package/lib/strapi/remote/handlers.d.ts +3 -0
  65. package/lib/strapi/remote/handlers.js +177 -0
  66. package/lib/strapi/remote/index.d.ts +3 -0
  67. package/lib/strapi/remote/index.js +30 -0
  68. package/lib/strapi/remote/routes.d.ts +21 -0
  69. package/lib/strapi/remote/routes.js +22 -0
  70. package/lib/utils/encryption/decrypt.d.ts +11 -0
  71. package/{dist → lib/utils}/encryption/decrypt.js +12 -4
  72. package/lib/utils/encryption/encrypt.d.ts +11 -0
  73. package/{dist → lib/utils}/encryption/encrypt.js +12 -4
  74. package/{dist → lib/utils}/encryption/index.d.ts +0 -0
  75. package/{dist → lib/utils}/encryption/index.js +0 -0
  76. package/lib/utils/index.d.ts +4 -0
  77. package/lib/utils/index.js +31 -0
  78. package/lib/utils/json.d.ts +30 -0
  79. package/{dist/utils.js → lib/utils/json.js} +16 -38
  80. package/lib/utils/schema.d.ts +7 -0
  81. package/lib/utils/schema.js +29 -0
  82. package/lib/utils/stream.d.ts +27 -0
  83. package/lib/utils/stream.js +59 -0
  84. package/package.json +19 -12
  85. package/dist/encryption/decrypt.d.ts +0 -3
  86. package/dist/encryption/encrypt.d.ts +0 -3
  87. package/dist/engine/index.js +0 -324
  88. package/dist/index.d.ts +0 -2
  89. package/dist/providers/index.d.ts +0 -4
  90. package/dist/providers/local-file-source-provider.d.ts +0 -43
  91. package/dist/providers/local-strapi-destination-provider.d.ts +0 -22
  92. package/dist/providers/local-strapi-destination-provider.js +0 -78
  93. package/dist/providers/local-strapi-source-provider/entities.js +0 -58
  94. package/dist/providers/local-strapi-source-provider/links/index.js +0 -37
  95. package/dist/providers/local-strapi-source-provider/links/utils.d.ts +0 -27
  96. package/dist/providers/local-strapi-source-provider/links/utils.js +0 -155
  97. package/dist/strategies/index.d.ts +0 -7
  98. package/dist/strategies/index.js +0 -29
  99. package/dist/utils.d.ts +0 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/data-transfer",
3
- "version": "4.6.0-alpha.0",
3
+ "version": "4.6.0-beta.2",
4
4
  "description": "Data transfer capabilities for Strapi",
5
5
  "keywords": [
6
6
  "strapi",
@@ -24,21 +24,23 @@
24
24
  "url": "https://strapi.io"
25
25
  }
26
26
  ],
27
- "main": "./dist/index.js",
28
- "types": "./dist/index.d.ts",
27
+ "main": "./lib/index.js",
28
+ "types": "./lib/index.d.ts",
29
29
  "scripts": {
30
- "build": "tsc -p tsconfig.json",
31
- "clean": "rimraf ./dist",
30
+ "build": "yarn build:ts",
31
+ "build:ts": "tsc -p tsconfig.json",
32
32
  "build:clean": "yarn clean && yarn build",
33
- "watch": "yarn build -w",
34
- "test:unit": "jest --verbose"
33
+ "clean": "rimraf ./dist",
34
+ "prepublishOnly": "yarn build:clean",
35
+ "test:unit": "jest --verbose",
36
+ "watch": "yarn build:ts -w --preserveWatchOutput"
35
37
  },
36
38
  "directories": {
37
- "lib": "./dist"
39
+ "lib": "./lib"
38
40
  },
39
41
  "dependencies": {
40
- "@strapi/logger": "4.6.0-alpha.0",
41
- "@strapi/strapi": "4.6.0-alpha.0",
42
+ "@strapi/logger": "4.6.0-beta.2",
43
+ "@strapi/strapi": "4.6.0-beta.2",
42
44
  "chalk": "4.1.2",
43
45
  "fs-extra": "10.0.0",
44
46
  "lodash": "4.17.21",
@@ -47,17 +49,22 @@
47
49
  "stream-chain": "2.2.5",
48
50
  "stream-json": "1.7.4",
49
51
  "tar": "6.1.12",
50
- "tar-stream": "2.2.0"
52
+ "tar-stream": "2.2.0",
53
+ "uuid": "9.0.0",
54
+ "ws": "8.11.0"
51
55
  },
52
56
  "devDependencies": {
53
57
  "@tsconfig/node16": "1.0.3",
54
58
  "@types/fs-extra": "9.0.13",
55
59
  "@types/jest": "29.2.0",
60
+ "@types/koa": "2.13.4",
56
61
  "@types/semver": "7.3.13",
57
62
  "@types/stream-chain": "2.0.1",
58
63
  "@types/stream-json": "1.7.2",
59
64
  "@types/tar": "6.1.3",
60
65
  "@types/tar-stream": "2.2.2",
66
+ "@types/uuid": "9.0.0",
67
+ "koa": "2.13.4",
61
68
  "rimraf": "3.0.2",
62
69
  "typescript": "4.6.2"
63
70
  },
@@ -65,5 +72,5 @@
65
72
  "node": ">=14.19.1 <=18.x.x",
66
73
  "npm": ">=6.0.0"
67
74
  },
68
- "gitHead": "b7a87dcffc6f44e18eedef92e354096ffe32ce0c"
75
+ "gitHead": "b852090f931cd21868c4016f24db2f9fdfc7a7ab"
69
76
  }
@@ -1,3 +0,0 @@
1
- import { Cipher } from 'crypto';
2
- import { Algorithm } from '../../types';
3
- export declare const createDecryptionCipher: (key: string, algorithm?: Algorithm) => Cipher;
@@ -1,3 +0,0 @@
1
- import { Cipher } from 'crypto';
2
- import { Algorithm } from '../../types';
3
- export declare const createEncryptionCipher: (key: string, algorithm?: Algorithm) => Cipher;
@@ -1,324 +0,0 @@
1
- "use strict";
2
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
5
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
- };
7
- var __importDefault = (this && this.__importDefault) || function (mod) {
8
- return (mod && mod.__esModule) ? mod : { "default": mod };
9
- };
10
- var _TransferEngine_instances, _TransferEngine_metadata, _TransferEngine_transferProgress, _TransferEngine_progressStream, _TransferEngine_increaseTransferProgress, _TransferEngine_countRecorder, _TransferEngine_updateStage, _TransferEngine_assertStrapiVersionIntegrity, _TransferEngine_assertSchemasMatching, _TransferEngine_resolveProviderResource;
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.createTransferEngine = exports.VALID_STRATEGIES = void 0;
13
- const stream_chain_1 = require("stream-chain");
14
- const fp_1 = require("lodash/fp");
15
- const semverDiff = require('semver/functions/diff');
16
- const strategies_1 = __importDefault(require("../strategies"));
17
- exports.VALID_STRATEGIES = ['restore', 'merge'];
18
- class TransferEngine {
19
- constructor(sourceProvider, destinationProvider, options) {
20
- _TransferEngine_instances.add(this);
21
- _TransferEngine_metadata.set(this, {});
22
- _TransferEngine_transferProgress.set(this, {});
23
- // TODO: Type the stream chunks. Doesn't seem trivial, especially since PassThrough doesn't provide a PassThroughOptions type
24
- _TransferEngine_progressStream.set(this, new stream_chain_1.PassThrough({ objectMode: true }));
25
- _TransferEngine_countRecorder.set(this, (transferStage, aggregateKey) => {
26
- return new stream_chain_1.PassThrough({
27
- objectMode: true,
28
- transform: (data, _encoding, callback) => {
29
- __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_increaseTransferProgress).call(this, transferStage, data, aggregateKey);
30
- __classPrivateFieldGet(this, _TransferEngine_updateStage, "f").call(this, 'progress', transferStage);
31
- callback(null, data);
32
- },
33
- });
34
- });
35
- _TransferEngine_updateStage.set(this, (type, transferStage) => {
36
- __classPrivateFieldGet(this, _TransferEngine_progressStream, "f").emit(type, {
37
- data: __classPrivateFieldGet(this, _TransferEngine_transferProgress, "f"),
38
- stage: transferStage,
39
- });
40
- });
41
- if (sourceProvider.type !== 'source') {
42
- throw new Error("SourceProvider does not have type 'source'");
43
- }
44
- if (destinationProvider.type !== 'destination') {
45
- throw new Error("DestinationProvider does not have type 'destination'");
46
- }
47
- this.sourceProvider = sourceProvider;
48
- this.destinationProvider = destinationProvider;
49
- this.options = options;
50
- }
51
- get progress() {
52
- return {
53
- data: __classPrivateFieldGet(this, _TransferEngine_transferProgress, "f"),
54
- stream: __classPrivateFieldGet(this, _TransferEngine_progressStream, "f"),
55
- };
56
- }
57
- async init() {
58
- // Resolve providers' resource and store
59
- // them in the engine's internal state
60
- await __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_resolveProviderResource).call(this);
61
- // Update the destination provider's source metadata
62
- const { source: sourceMetadata } = __classPrivateFieldGet(this, _TransferEngine_metadata, "f");
63
- if (sourceMetadata) {
64
- this.destinationProvider.setMetadata?.('source', sourceMetadata);
65
- }
66
- }
67
- async bootstrap() {
68
- await Promise.all([this.sourceProvider.bootstrap?.(), this.destinationProvider.bootstrap?.()]);
69
- }
70
- async close() {
71
- await Promise.all([this.sourceProvider.close?.(), this.destinationProvider.close?.()]);
72
- }
73
- async integrityCheck() {
74
- try {
75
- const sourceMetadata = await this.sourceProvider.getMetadata();
76
- const destinationMetadata = await this.destinationProvider.getMetadata();
77
- if (sourceMetadata && destinationMetadata) {
78
- __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_assertStrapiVersionIntegrity).call(this, sourceMetadata?.strapi?.version, destinationMetadata?.strapi?.version);
79
- }
80
- const sourceSchemas = await this.sourceProvider.getSchemas?.();
81
- const destinationSchemas = await this.destinationProvider.getSchemas?.();
82
- if (sourceSchemas && destinationSchemas) {
83
- __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_assertSchemasMatching).call(this, sourceSchemas, destinationSchemas);
84
- }
85
- return true;
86
- }
87
- catch (error) {
88
- return false;
89
- }
90
- }
91
- validateTransferOptions() {
92
- if (!exports.VALID_STRATEGIES.includes(this.options.strategy)) {
93
- throw new Error('Invalid stategy ' + this.options.strategy);
94
- }
95
- }
96
- async transfer() {
97
- try {
98
- this.validateTransferOptions();
99
- await this.bootstrap();
100
- await this.init();
101
- const isValidTransfer = await this.integrityCheck();
102
- if (!isValidTransfer) {
103
- throw new Error(`Unable to transfer the data between ${this.sourceProvider.name} and ${this.destinationProvider.name}.\nPlease refer to the log above for more information.`);
104
- }
105
- // Run the transfer stages
106
- await this.transferSchemas();
107
- await this.transferEntities();
108
- await this.transferMedia();
109
- await this.transferLinks();
110
- await this.transferConfiguration();
111
- // Gracefully close the providers
112
- await this.close();
113
- }
114
- catch (e) {
115
- // Rollback the destination provider if an exception is thrown during the transfer
116
- // Note: This will be configurable in the future
117
- await this.destinationProvider.rollback?.(e);
118
- throw e;
119
- }
120
- return {
121
- source: this.sourceProvider.results,
122
- destination: this.destinationProvider.results,
123
- };
124
- }
125
- async transferSchemas() {
126
- const stageName = 'schemas';
127
- const inStream = await this.sourceProvider.streamSchemas?.();
128
- if (!inStream) {
129
- return;
130
- }
131
- const outStream = await this.destinationProvider.getSchemasStream?.();
132
- if (!outStream) {
133
- return;
134
- }
135
- __classPrivateFieldGet(this, _TransferEngine_updateStage, "f").call(this, 'start', stageName);
136
- return new Promise((resolve, reject) => {
137
- inStream
138
- // Throw on error in the source
139
- .on('error', reject);
140
- outStream
141
- // Throw on error in the destination
142
- .on('error', reject)
143
- // Resolve the promise when the destination has finished reading all the data from the source
144
- .on('close', () => {
145
- __classPrivateFieldGet(this, _TransferEngine_updateStage, "f").call(this, 'complete', stageName);
146
- resolve();
147
- });
148
- inStream.pipe(__classPrivateFieldGet(this, _TransferEngine_countRecorder, "f").call(this, stageName)).pipe(outStream);
149
- });
150
- }
151
- async transferEntities() {
152
- const stageName = 'entities';
153
- const inStream = await this.sourceProvider.streamEntities?.();
154
- if (!inStream) {
155
- return;
156
- }
157
- const outStream = await this.destinationProvider.getEntitiesStream?.();
158
- if (!outStream) {
159
- return;
160
- }
161
- __classPrivateFieldGet(this, _TransferEngine_updateStage, "f").call(this, 'start', stageName);
162
- return new Promise((resolve, reject) => {
163
- inStream
164
- // Throw on error in the source
165
- .on('error', (e) => {
166
- reject(e);
167
- });
168
- outStream
169
- // Throw on error in the destination
170
- .on('error', (e) => {
171
- reject(e);
172
- })
173
- // Resolve the promise when the destination has finished reading all the data from the source
174
- .on('close', () => {
175
- __classPrivateFieldGet(this, _TransferEngine_updateStage, "f").call(this, 'complete', stageName);
176
- resolve();
177
- });
178
- inStream.pipe(__classPrivateFieldGet(this, _TransferEngine_countRecorder, "f").call(this, stageName, 'type')).pipe(outStream);
179
- });
180
- }
181
- async transferLinks() {
182
- const stageName = 'links';
183
- const inStream = await this.sourceProvider.streamLinks?.();
184
- if (!inStream) {
185
- return;
186
- }
187
- const outStream = await this.destinationProvider.getLinksStream?.();
188
- if (!outStream) {
189
- return;
190
- }
191
- __classPrivateFieldGet(this, _TransferEngine_updateStage, "f").call(this, 'start', 'links');
192
- return new Promise((resolve, reject) => {
193
- inStream
194
- // Throw on error in the source
195
- .on('error', reject);
196
- outStream
197
- // Throw on error in the destination
198
- .on('error', reject)
199
- // Resolve the promise when the destination has finished reading all the data from the source
200
- .on('close', () => {
201
- __classPrivateFieldGet(this, _TransferEngine_updateStage, "f").call(this, 'complete', stageName);
202
- resolve();
203
- });
204
- inStream.pipe(__classPrivateFieldGet(this, _TransferEngine_countRecorder, "f").call(this, stageName)).pipe(outStream);
205
- });
206
- }
207
- async transferMedia() {
208
- const stageName = 'media';
209
- __classPrivateFieldGet(this, _TransferEngine_updateStage, "f").call(this, 'start', stageName);
210
- console.warn('transferMedia not yet implemented');
211
- return new Promise((resolve) => (() => {
212
- __classPrivateFieldGet(this, _TransferEngine_updateStage, "f").call(this, 'complete', stageName);
213
- resolve();
214
- })());
215
- }
216
- async transferConfiguration() {
217
- const stageName = 'configuration';
218
- const inStream = await this.sourceProvider.streamConfiguration?.();
219
- if (!inStream) {
220
- return;
221
- }
222
- const outStream = await this.destinationProvider.getConfigurationStream?.();
223
- if (!outStream) {
224
- return;
225
- }
226
- __classPrivateFieldGet(this, _TransferEngine_updateStage, "f").call(this, 'start', stageName);
227
- return new Promise((resolve, reject) => {
228
- inStream
229
- // Throw on error in the source
230
- .on('error', reject);
231
- outStream
232
- // Throw on error in the destination
233
- .on('error', reject)
234
- // Resolve the promise when the destination has finished reading all the data from the source
235
- .on('close', () => {
236
- __classPrivateFieldGet(this, _TransferEngine_updateStage, "f").call(this, 'complete', stageName);
237
- resolve();
238
- });
239
- inStream.pipe(__classPrivateFieldGet(this, _TransferEngine_countRecorder, "f").call(this, stageName)).pipe(outStream);
240
- });
241
- }
242
- }
243
- _TransferEngine_metadata = new WeakMap(), _TransferEngine_transferProgress = new WeakMap(), _TransferEngine_progressStream = new WeakMap(), _TransferEngine_countRecorder = new WeakMap(), _TransferEngine_updateStage = new WeakMap(), _TransferEngine_instances = new WeakSet(), _TransferEngine_increaseTransferProgress = function _TransferEngine_increaseTransferProgress(transferStage, data, aggregateKey) {
244
- if (!__classPrivateFieldGet(this, _TransferEngine_transferProgress, "f")[transferStage]) {
245
- __classPrivateFieldGet(this, _TransferEngine_transferProgress, "f")[transferStage] = { count: 0, bytes: 0 };
246
- }
247
- __classPrivateFieldGet(this, _TransferEngine_transferProgress, "f")[transferStage].count += 1;
248
- const size = JSON.stringify(data).length;
249
- __classPrivateFieldGet(this, _TransferEngine_transferProgress, "f")[transferStage].bytes += size;
250
- if (aggregateKey && data && data[aggregateKey]) {
251
- const aggKeyValue = data[aggregateKey];
252
- if (!__classPrivateFieldGet(this, _TransferEngine_transferProgress, "f")[transferStage]['aggregates']) {
253
- __classPrivateFieldGet(this, _TransferEngine_transferProgress, "f")[transferStage].aggregates = {};
254
- }
255
- if (!(__classPrivateFieldGet(this, _TransferEngine_transferProgress, "f")[transferStage].aggregates &&
256
- __classPrivateFieldGet(this, _TransferEngine_transferProgress, "f")[transferStage].aggregates[aggKeyValue])) {
257
- __classPrivateFieldGet(this, _TransferEngine_transferProgress, "f")[transferStage].aggregates[aggKeyValue] = { count: 0, bytes: 0 };
258
- }
259
- __classPrivateFieldGet(this, _TransferEngine_transferProgress, "f")[transferStage].aggregates[aggKeyValue].count += 1;
260
- __classPrivateFieldGet(this, _TransferEngine_transferProgress, "f")[transferStage].aggregates[aggKeyValue].bytes += size;
261
- }
262
- }, _TransferEngine_assertStrapiVersionIntegrity = function _TransferEngine_assertStrapiVersionIntegrity(sourceVersion, destinationVersion) {
263
- const strategy = this.options.versionMatching;
264
- if (!sourceVersion ||
265
- !destinationVersion ||
266
- strategy === 'ignore' ||
267
- destinationVersion === sourceVersion) {
268
- return;
269
- }
270
- let diff;
271
- try {
272
- diff = semverDiff(sourceVersion, destinationVersion);
273
- }
274
- catch (e) {
275
- throw new Error(`Strapi versions doesn't match (${strategy} check): ${sourceVersion} does not match with ${destinationVersion}`);
276
- }
277
- if (!diff) {
278
- return;
279
- }
280
- const validPatch = ['prelease', 'build'];
281
- const validMinor = [...validPatch, 'patch', 'prepatch'];
282
- const validMajor = [...validMinor, 'minor', 'preminor'];
283
- if (strategy === 'patch' && validPatch.includes(diff)) {
284
- return;
285
- }
286
- if (strategy === 'minor' && validMinor.includes(diff)) {
287
- return;
288
- }
289
- if (strategy === 'major' && validMajor.includes(diff)) {
290
- return;
291
- }
292
- throw new Error(`Strapi versions doesn't match (${strategy} check): ${sourceVersion} does not match with ${destinationVersion}`);
293
- }, _TransferEngine_assertSchemasMatching = function _TransferEngine_assertSchemasMatching(sourceSchemas, destinationSchemas) {
294
- const strategy = this.options.schemasMatching || 'strict';
295
- const keys = (0, fp_1.uniq)(Object.keys(sourceSchemas).concat(Object.keys(destinationSchemas)));
296
- const diffs = {};
297
- keys.forEach((key) => {
298
- const sourceSchema = sourceSchemas[key];
299
- const destinationSchema = destinationSchemas[key];
300
- const schemaDiffs = (0, strategies_1.default)(sourceSchema, destinationSchema, strategy);
301
- if (schemaDiffs.length) {
302
- diffs[key] = schemaDiffs;
303
- }
304
- });
305
- if (!(0, fp_1.isEmpty)(diffs)) {
306
- throw new Error(`Import process failed because the project doesn't have a matching data structure
307
- ${JSON.stringify(diffs, null, 2)}
308
- `);
309
- }
310
- }, _TransferEngine_resolveProviderResource = async function _TransferEngine_resolveProviderResource() {
311
- const sourceMetadata = await this.sourceProvider.getMetadata();
312
- const destinationMetadata = await this.destinationProvider.getMetadata();
313
- if (sourceMetadata) {
314
- __classPrivateFieldGet(this, _TransferEngine_metadata, "f").source = sourceMetadata;
315
- }
316
- if (destinationMetadata) {
317
- __classPrivateFieldGet(this, _TransferEngine_metadata, "f").destination = destinationMetadata;
318
- }
319
- };
320
- const createTransferEngine = (sourceProvider, destinationProvider, options) => {
321
- return new TransferEngine(sourceProvider, destinationProvider, options);
322
- };
323
- exports.createTransferEngine = createTransferEngine;
324
- //# sourceMappingURL=index.js.map
package/dist/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from './engine';
2
- export * from './providers';
@@ -1,4 +0,0 @@
1
- export * from './local-file-source-provider';
2
- export * from './local-strapi-source-provider';
3
- export * from './local-file-destination-provider';
4
- export * from './local-strapi-destination-provider';
@@ -1,43 +0,0 @@
1
- /// <reference types="lodash" />
2
- /// <reference types="node" />
3
- import type { IMetadata, ISourceProvider, ProviderType } from '../../types';
4
- /**
5
- * Provider options
6
- */
7
- export interface ILocalFileSourceProviderOptions {
8
- /**
9
- * Path to the backup archive
10
- */
11
- backupFilePath: string;
12
- /**
13
- * Whether the backup data is encrypted or not
14
- */
15
- encrypted?: boolean;
16
- /**
17
- * Encryption key used to decrypt the encrypted data (if necessary)
18
- */
19
- encryptionKey?: string;
20
- /**
21
- * Whether the backup data is compressed or not
22
- */
23
- compressed?: boolean;
24
- }
25
- export declare const createLocalFileSourceProvider: (options: ILocalFileSourceProviderOptions) => LocalFileSourceProvider;
26
- declare class LocalFileSourceProvider implements ISourceProvider {
27
- #private;
28
- type: ProviderType;
29
- name: string;
30
- options: ILocalFileSourceProviderOptions;
31
- constructor(options: ILocalFileSourceProviderOptions);
32
- /**
33
- * Pre flight checks regarding the provided options (making sure that the provided path is correct, etc...)
34
- */
35
- bootstrap(): void;
36
- getMetadata(): Promise<IMetadata>;
37
- getSchemas(): Promise<import("lodash").Dictionary<unknown>>;
38
- streamEntities(): NodeJS.ReadableStream;
39
- streamSchemas(): NodeJS.ReadableStream | Promise<NodeJS.ReadableStream>;
40
- streamLinks(): NodeJS.ReadableStream;
41
- streamConfiguration(): NodeJS.ReadableStream;
42
- }
43
- export {};
@@ -1,22 +0,0 @@
1
- /// <reference types="node" />
2
- import type { IDestinationProvider, IMetadata, ProviderType } from '../../types';
3
- import { Duplex } from 'stream';
4
- interface ILocalStrapiDestinationProviderOptions {
5
- getStrapi(): Promise<Strapi.Strapi>;
6
- }
7
- export declare const createLocalStrapiDestinationProvider: (options: ILocalStrapiDestinationProviderOptions) => LocalStrapiDestinationProvider;
8
- declare class LocalStrapiDestinationProvider implements IDestinationProvider {
9
- name: string;
10
- type: ProviderType;
11
- options: ILocalStrapiDestinationProviderOptions;
12
- strapi?: Strapi.Strapi;
13
- constructor(options: ILocalStrapiDestinationProviderOptions);
14
- bootstrap(): Promise<void>;
15
- close(): Promise<void>;
16
- getMetadata(): IMetadata | Promise<IMetadata>;
17
- getSchemas(): {
18
- [x: string]: Partial<any>;
19
- };
20
- getEntitiesStream(): Duplex;
21
- }
22
- export {};
@@ -1,78 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.createLocalStrapiDestinationProvider = void 0;
7
- const chalk_1 = __importDefault(require("chalk"));
8
- const stream_1 = require("stream");
9
- const utils_1 = require("../utils");
10
- // TODO: getting some type errors with @strapi/logger that need to be resolved first
11
- // const log = createLogger();
12
- const log = console;
13
- const createLocalStrapiDestinationProvider = (options) => {
14
- return new LocalStrapiDestinationProvider(options);
15
- };
16
- exports.createLocalStrapiDestinationProvider = createLocalStrapiDestinationProvider;
17
- class LocalStrapiDestinationProvider {
18
- constructor(options) {
19
- this.name = 'destination::local-strapi';
20
- this.type = 'destination';
21
- this.options = options;
22
- }
23
- async bootstrap() {
24
- this.strapi = await this.options.getStrapi();
25
- }
26
- async close() {
27
- await this.strapi?.destroy?.();
28
- }
29
- // TODO
30
- getMetadata() {
31
- return {};
32
- }
33
- getSchemas() {
34
- if (!this.strapi) {
35
- throw new Error('Not able to get Schemas. Strapi instance not found');
36
- }
37
- const schemas = {
38
- ...this.strapi.contentTypes,
39
- ...this.strapi.components,
40
- };
41
- return (0, utils_1.mapSchemasValues)(schemas);
42
- }
43
- getEntitiesStream() {
44
- const self = this;
45
- return new stream_1.Duplex({
46
- objectMode: true,
47
- async write(entity, _encoding, callback) {
48
- if (!self.strapi) {
49
- callback(new Error('Strapi instance not found'));
50
- }
51
- const { type: uid, id, data } = entity;
52
- try {
53
- await strapi.entityService.create(uid, { data });
54
- }
55
- catch (e) {
56
- // TODO: remove "any" cast
57
- log.warn(chalk_1.default.bold(`Failed to import ${chalk_1.default.yellowBright(uid)} (${chalk_1.default.greenBright(id)})`));
58
- e.details.errors
59
- .map((err, i) => {
60
- // TODO: add correct error type
61
- const info = {
62
- uid: chalk_1.default.yellowBright(`[${uid}]`),
63
- path: chalk_1.default.blueBright(`[${err.path.join('.')}]`),
64
- id: chalk_1.default.greenBright(`[${id}]`),
65
- message: err.message,
66
- };
67
- return `(${i}) ${info.uid}${info.id}${info.path}: ${info.message}`;
68
- })
69
- .forEach((message) => log.warn(message));
70
- }
71
- finally {
72
- callback();
73
- }
74
- },
75
- });
76
- }
77
- }
78
- //# sourceMappingURL=local-strapi-destination-provider.js.map
@@ -1,58 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createEntitiesTransformStream = exports.createEntitiesStream = void 0;
4
- const stream_1 = require("stream");
5
- /**
6
- * Generate and consume content-types streams in order to stream each entity individually
7
- */
8
- const createEntitiesStream = (strapi) => {
9
- const contentTypes = Object.values(strapi.contentTypes);
10
- async function* contentTypeStreamGenerator() {
11
- for (const contentType of contentTypes) {
12
- const stream = strapi.db
13
- // Create a query builder instance (default type is 'select')
14
- .queryBuilder(contentType.uid)
15
- // Apply the populate
16
- .populate(getPopulateAttributes(contentType))
17
- // Get a readable stream
18
- .stream();
19
- yield { contentType, stream };
20
- }
21
- }
22
- return stream_1.Readable.from((async function* () {
23
- for await (const { stream, contentType } of contentTypeStreamGenerator()) {
24
- for await (const entity of stream) {
25
- yield { entity, contentType };
26
- }
27
- stream.destroy();
28
- }
29
- })());
30
- };
31
- exports.createEntitiesStream = createEntitiesStream;
32
- /**
33
- * Create an entity transform stream which convert the output of
34
- * the multi-content-types stream to the transfer entity format
35
- */
36
- const createEntitiesTransformStream = () => {
37
- return new stream_1.PassThrough({
38
- objectMode: true,
39
- transform(data, _encoding, callback) {
40
- const { entity, contentType } = data;
41
- const { id, ...attributes } = entity;
42
- callback(null, {
43
- type: contentType.uid,
44
- id,
45
- data: attributes,
46
- });
47
- },
48
- });
49
- };
50
- exports.createEntitiesTransformStream = createEntitiesTransformStream;
51
- /**
52
- * Get the list of attributes that needs to be populated for the entities streaming
53
- */
54
- const getPopulateAttributes = (contentType) => {
55
- const { attributes } = contentType;
56
- return Object.keys(attributes).filter((key) => ['component', 'dynamiczone'].includes(attributes[key].type));
57
- };
58
- //# sourceMappingURL=entities.js.map
@@ -1,37 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createLinksStream = void 0;
4
- const stream_1 = require("stream");
5
- const fp_1 = require("lodash/fp");
6
- const utils_1 = require("./utils");
7
- /**
8
- * Create a Duplex instance which will stream all the links from a Strapi instance
9
- */
10
- const createLinksStream = (strapi) => {
11
- const schemas = Object.values(strapi.contentTypes);
12
- // Destroy the Duplex stream instance
13
- const destroy = () => {
14
- if (!stream.destroyed) {
15
- stream.destroy();
16
- }
17
- };
18
- // Async generator stream that returns every link from a Strapi instance
19
- const stream = stream_1.Readable.from((async function* () {
20
- for (const schema of schemas) {
21
- const populate = (0, utils_1.getDeepPopulateQuery)(schema, strapi);
22
- const query = { fields: ['id'], populate };
23
- // TODO: Replace with the DB stream API
24
- const results = await strapi.entityService.findMany(schema.uid, query);
25
- for (const entity of (0, fp_1.castArray)(results)) {
26
- const links = (0, utils_1.parseEntityLinks)(entity, populate, schema, strapi);
27
- for (const link of links) {
28
- yield link;
29
- }
30
- }
31
- }
32
- destroy();
33
- })());
34
- return stream;
35
- };
36
- exports.createLinksStream = createLinksStream;
37
- //# sourceMappingURL=index.js.map