@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/jest.config.js CHANGED
@@ -5,8 +5,10 @@ const pkg = require('./package.json');
5
5
 
6
6
  module.exports = {
7
7
  ...baseConfig,
8
- preset: 'ts-jest',
9
8
  displayName: (pkg.strapi && pkg.strapi.name) || pkg.name,
10
9
  roots: [__dirname],
11
10
  testMatch: ['**/__tests__/**/*.test.ts'],
11
+ transform: {
12
+ '^.+\\.(t|j)sx?$': ['@swc/jest'],
13
+ },
12
14
  };
@@ -1,28 +1,35 @@
1
1
  /// <reference types="node" />
2
- import { PassThrough } from 'stream-chain';
3
- import type { IDestinationProvider, ISourceProvider, ITransferEngine, ITransferEngineOptions, ITransferResults } from '../../types';
4
- declare type TransferEngineProgress = {
5
- data: any;
6
- stream: PassThrough;
7
- };
8
- export declare const VALID_STRATEGIES: string[];
2
+ import { PassThrough } from 'stream';
3
+ import type { IDestinationProvider, ISourceProvider, ITransferEngine, ITransferEngineOptions, TransferProgress, ITransferResults, TransferStage, TransferFilters, TransferFilterPreset } from '../../types';
4
+ export declare const TRANSFER_STAGES: ReadonlyArray<TransferStage>;
5
+ export declare type TransferGroupFilter = Record<TransferFilterPreset, TransferFilters>;
6
+ /**
7
+ * Preset filters for only/exclude options
8
+ * */
9
+ export declare const TransferGroupPresets: TransferGroupFilter;
10
+ export declare const DEFAULT_VERSION_STRATEGY = "ignore";
11
+ export declare const DEFAULT_SCHEMA_STRATEGY = "strict";
9
12
  declare class TransferEngine<S extends ISourceProvider = ISourceProvider, D extends IDestinationProvider = IDestinationProvider> implements ITransferEngine {
10
13
  #private;
11
14
  sourceProvider: ISourceProvider;
12
15
  destinationProvider: IDestinationProvider;
13
16
  options: ITransferEngineOptions;
14
- get progress(): TransferEngineProgress;
17
+ progress: {
18
+ data: TransferProgress;
19
+ stream: PassThrough;
20
+ };
15
21
  constructor(sourceProvider: ISourceProvider, destinationProvider: IDestinationProvider, options: ITransferEngineOptions);
22
+ shouldSkipStage(stage: TransferStage): boolean;
16
23
  init(): Promise<void>;
17
24
  bootstrap(): Promise<void>;
18
25
  close(): Promise<void>;
19
26
  integrityCheck(): Promise<boolean>;
20
- validateTransferOptions(): void;
21
27
  transfer(): Promise<ITransferResults<S, D>>;
28
+ beforeTransfer(): Promise<void>;
22
29
  transferSchemas(): Promise<void>;
23
30
  transferEntities(): Promise<void>;
24
31
  transferLinks(): Promise<void>;
25
- transferMedia(): Promise<void>;
32
+ transferAssets(): Promise<void>;
26
33
  transferConfiguration(): Promise<void>;
27
34
  }
28
35
  export declare const createTransferEngine: <S extends ISourceProvider = ISourceProvider, D extends IDestinationProvider = IDestinationProvider>(sourceProvider: S, destinationProvider: D, options: ITransferEngineOptions) => TransferEngine<S, D>;
@@ -0,0 +1,359 @@
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 _TransferEngine_instances, _TransferEngine_metadata, _TransferEngine_createStageTransformStream, _TransferEngine_updateTransferProgress, _TransferEngine_progressTracker, _TransferEngine_emitTransferUpdate, _TransferEngine_emitStageUpdate, _TransferEngine_assertStrapiVersionIntegrity, _TransferEngine_assertSchemasMatching, _TransferEngine_transferStage, _TransferEngine_resolveProviderResource;
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.createTransferEngine = exports.DEFAULT_SCHEMA_STRATEGY = exports.DEFAULT_VERSION_STRATEGY = exports.TransferGroupPresets = exports.TRANSFER_STAGES = void 0;
10
+ const stream_1 = require("stream");
11
+ const path_1 = require("path");
12
+ const fp_1 = require("lodash/fp");
13
+ const semver_1 = require("semver");
14
+ const schemas_1 = require("./validation/schemas");
15
+ const stream_2 = require("../utils/stream");
16
+ exports.TRANSFER_STAGES = Object.freeze([
17
+ 'entities',
18
+ 'links',
19
+ 'assets',
20
+ 'schemas',
21
+ 'configuration',
22
+ ]);
23
+ /**
24
+ * Preset filters for only/exclude options
25
+ * */
26
+ exports.TransferGroupPresets = {
27
+ content: {
28
+ links: true,
29
+ entities: true,
30
+ // TODO: If we need to implement filtering on a running stage, it would be done like this, but we still need to implement it
31
+ // [
32
+ // // Example: content processes the entities stage, but filters individual entities
33
+ // {
34
+ // filter(data) {
35
+ // return shouldIncludeThisData(data);
36
+ // },
37
+ // },
38
+ // ],
39
+ },
40
+ files: {
41
+ assets: true,
42
+ links: true,
43
+ },
44
+ config: {
45
+ configuration: true,
46
+ },
47
+ };
48
+ exports.DEFAULT_VERSION_STRATEGY = 'ignore';
49
+ exports.DEFAULT_SCHEMA_STRATEGY = 'strict';
50
+ class TransferEngine {
51
+ constructor(sourceProvider, destinationProvider, options) {
52
+ _TransferEngine_instances.add(this);
53
+ _TransferEngine_metadata.set(this, {});
54
+ if (sourceProvider.type !== 'source') {
55
+ throw new Error("SourceProvider does not have type 'source'");
56
+ }
57
+ if (destinationProvider.type !== 'destination') {
58
+ throw new Error("DestinationProvider does not have type 'destination'");
59
+ }
60
+ this.sourceProvider = sourceProvider;
61
+ this.destinationProvider = destinationProvider;
62
+ this.options = options;
63
+ this.progress = { data: {}, stream: new stream_1.PassThrough({ objectMode: true }) };
64
+ }
65
+ shouldSkipStage(stage) {
66
+ const { exclude, only } = this.options;
67
+ // schemas must always be included
68
+ if (stage === 'schemas') {
69
+ return false;
70
+ }
71
+ // everything is included by default unless 'only' has been set
72
+ let included = (0, fp_1.isEmpty)(only);
73
+ if (only?.length > 0) {
74
+ included = only.some((transferGroup) => {
75
+ return exports.TransferGroupPresets[transferGroup][stage];
76
+ });
77
+ }
78
+ if (exclude?.length > 0) {
79
+ if (included) {
80
+ included = !exclude.some((transferGroup) => {
81
+ return exports.TransferGroupPresets[transferGroup][stage];
82
+ });
83
+ }
84
+ }
85
+ return !included;
86
+ }
87
+ async init() {
88
+ // Resolve providers' resource and store
89
+ // them in the engine's internal state
90
+ await __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_resolveProviderResource).call(this);
91
+ // Update the destination provider's source metadata
92
+ const { source: sourceMetadata } = __classPrivateFieldGet(this, _TransferEngine_metadata, "f");
93
+ if (sourceMetadata) {
94
+ this.destinationProvider.setMetadata?.('source', sourceMetadata);
95
+ }
96
+ }
97
+ async bootstrap() {
98
+ await Promise.all([this.sourceProvider.bootstrap?.(), this.destinationProvider.bootstrap?.()]);
99
+ }
100
+ async close() {
101
+ await Promise.all([this.sourceProvider.close?.(), this.destinationProvider.close?.()]);
102
+ }
103
+ async integrityCheck() {
104
+ try {
105
+ const sourceMetadata = await this.sourceProvider.getMetadata();
106
+ const destinationMetadata = await this.destinationProvider.getMetadata();
107
+ if (sourceMetadata && destinationMetadata) {
108
+ __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_assertStrapiVersionIntegrity).call(this, sourceMetadata?.strapi?.version, destinationMetadata?.strapi?.version);
109
+ }
110
+ const sourceSchemas = (await this.sourceProvider.getSchemas?.());
111
+ const destinationSchemas = (await this.destinationProvider.getSchemas?.());
112
+ if (sourceSchemas && destinationSchemas) {
113
+ __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_assertSchemasMatching).call(this, sourceSchemas, destinationSchemas);
114
+ }
115
+ return true;
116
+ }
117
+ catch (error) {
118
+ return false;
119
+ }
120
+ }
121
+ async transfer() {
122
+ // reset data between transfers
123
+ this.progress.data = {};
124
+ try {
125
+ __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_emitTransferUpdate).call(this, 'init');
126
+ await this.bootstrap();
127
+ await this.init();
128
+ const isValidTransfer = await this.integrityCheck();
129
+ if (!isValidTransfer) {
130
+ // TODO: provide the log from the integrity check
131
+ 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.`);
132
+ }
133
+ __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_emitTransferUpdate).call(this, 'start');
134
+ await this.beforeTransfer();
135
+ // Run the transfer stages
136
+ await this.transferSchemas();
137
+ await this.transferEntities();
138
+ await this.transferAssets();
139
+ await this.transferLinks();
140
+ await this.transferConfiguration();
141
+ // Gracefully close the providers
142
+ await this.close();
143
+ __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_emitTransferUpdate).call(this, 'finish');
144
+ }
145
+ catch (e) {
146
+ __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_emitTransferUpdate).call(this, 'error', { error: e });
147
+ // Rollback the destination provider if an exception is thrown during the transfer
148
+ // Note: This will be configurable in the future
149
+ await this.destinationProvider.rollback?.(e);
150
+ throw e;
151
+ }
152
+ return {
153
+ source: this.sourceProvider.results,
154
+ destination: this.destinationProvider.results,
155
+ engine: this.progress.data,
156
+ };
157
+ }
158
+ async beforeTransfer() {
159
+ await this.sourceProvider.beforeTransfer?.();
160
+ await this.destinationProvider.beforeTransfer?.();
161
+ }
162
+ async transferSchemas() {
163
+ const stage = 'schemas';
164
+ const source = await this.sourceProvider.createSchemasReadStream?.();
165
+ const destination = await this.destinationProvider.createSchemasWriteStream?.();
166
+ const transform = __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_createStageTransformStream).call(this, stage);
167
+ const tracker = __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_progressTracker).call(this, stage, { key: (value) => value.modelType });
168
+ await __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_transferStage).call(this, { stage, source, destination, transform, tracker });
169
+ }
170
+ async transferEntities() {
171
+ const stage = 'entities';
172
+ const source = await this.sourceProvider.createEntitiesReadStream?.();
173
+ const destination = await this.destinationProvider.createEntitiesWriteStream?.();
174
+ const transform = __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_createStageTransformStream).call(this, stage);
175
+ const tracker = __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_progressTracker).call(this, stage, { key: (value) => value.type });
176
+ await __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_transferStage).call(this, { stage, source, destination, transform, tracker });
177
+ }
178
+ async transferLinks() {
179
+ const stage = 'links';
180
+ const source = await this.sourceProvider.createLinksReadStream?.();
181
+ const destination = await this.destinationProvider.createLinksWriteStream?.();
182
+ const transform = __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_createStageTransformStream).call(this, stage);
183
+ const tracker = __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_progressTracker).call(this, stage);
184
+ await __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_transferStage).call(this, { stage, source, destination, transform, tracker });
185
+ }
186
+ async transferAssets() {
187
+ const stage = 'assets';
188
+ const source = await this.sourceProvider.createAssetsReadStream?.();
189
+ const destination = await this.destinationProvider.createAssetsWriteStream?.();
190
+ const transform = __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_createStageTransformStream).call(this, stage);
191
+ const tracker = __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_progressTracker).call(this, stage, {
192
+ size: (value) => value.stats.size,
193
+ key: (value) => (0, path_1.extname)(value.filename),
194
+ });
195
+ await __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_transferStage).call(this, { stage, source, destination, transform, tracker });
196
+ }
197
+ async transferConfiguration() {
198
+ const stage = 'configuration';
199
+ const source = await this.sourceProvider.createConfigurationReadStream?.();
200
+ const destination = await this.destinationProvider.createConfigurationWriteStream?.();
201
+ const transform = __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_createStageTransformStream).call(this, stage);
202
+ const tracker = __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_progressTracker).call(this, stage);
203
+ await __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_transferStage).call(this, { stage, source, destination, transform, tracker });
204
+ }
205
+ }
206
+ _TransferEngine_metadata = new WeakMap(), _TransferEngine_instances = new WeakSet(), _TransferEngine_createStageTransformStream = function _TransferEngine_createStageTransformStream(key, options = {}) {
207
+ const { includeGlobal = true } = options;
208
+ const { global: globalTransforms, [key]: stageTransforms } = this.options?.transforms ?? {};
209
+ let stream = new stream_1.PassThrough({ objectMode: true });
210
+ const applyTransforms = (transforms = []) => {
211
+ for (const transform of transforms) {
212
+ if ('filter' in transform) {
213
+ stream = stream.pipe((0, stream_2.filter)(transform.filter));
214
+ }
215
+ if ('map' in transform) {
216
+ stream = stream.pipe((0, stream_2.map)(transform.map));
217
+ }
218
+ }
219
+ };
220
+ if (includeGlobal) {
221
+ applyTransforms(globalTransforms);
222
+ }
223
+ applyTransforms(stageTransforms);
224
+ return stream;
225
+ }, _TransferEngine_updateTransferProgress = function _TransferEngine_updateTransferProgress(stage, data, aggregate) {
226
+ if (!this.progress.data[stage]) {
227
+ this.progress.data[stage] = { count: 0, bytes: 0 };
228
+ }
229
+ const stageProgress = this.progress.data[stage];
230
+ if (!stageProgress) {
231
+ return;
232
+ }
233
+ const size = aggregate?.size?.(data) ?? JSON.stringify(data).length;
234
+ const key = aggregate?.key?.(data);
235
+ stageProgress.count += 1;
236
+ stageProgress.bytes += size;
237
+ // Handle aggregate updates if necessary
238
+ if (key) {
239
+ if (!stageProgress.aggregates) {
240
+ stageProgress.aggregates = {};
241
+ }
242
+ const { aggregates } = stageProgress;
243
+ if (!aggregates[key]) {
244
+ aggregates[key] = { count: 0, bytes: 0 };
245
+ }
246
+ aggregates[key].count += 1;
247
+ aggregates[key].bytes += size;
248
+ }
249
+ }, _TransferEngine_progressTracker = function _TransferEngine_progressTracker(stage, aggregate) {
250
+ return new stream_1.PassThrough({
251
+ objectMode: true,
252
+ transform: (data, _encoding, callback) => {
253
+ __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_updateTransferProgress).call(this, stage, data, aggregate);
254
+ __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_emitStageUpdate).call(this, 'progress', stage);
255
+ callback(null, data);
256
+ },
257
+ });
258
+ }, _TransferEngine_emitTransferUpdate = function _TransferEngine_emitTransferUpdate(type, payload) {
259
+ this.progress.stream.emit(`transfer::${type}`, payload);
260
+ }, _TransferEngine_emitStageUpdate = function _TransferEngine_emitStageUpdate(type, transferStage) {
261
+ this.progress.stream.emit(`stage::${type}`, {
262
+ data: this.progress.data,
263
+ stage: transferStage,
264
+ });
265
+ }, _TransferEngine_assertStrapiVersionIntegrity = function _TransferEngine_assertStrapiVersionIntegrity(sourceVersion, destinationVersion) {
266
+ const strategy = this.options.versionStrategy || exports.DEFAULT_VERSION_STRATEGY;
267
+ if (!sourceVersion ||
268
+ !destinationVersion ||
269
+ strategy === 'ignore' ||
270
+ destinationVersion === sourceVersion) {
271
+ return;
272
+ }
273
+ let diff;
274
+ try {
275
+ diff = (0, semver_1.diff)(sourceVersion, destinationVersion);
276
+ }
277
+ catch (e) {
278
+ throw new Error(`Strapi versions doesn't match (${strategy} check): ${sourceVersion} does not match with ${destinationVersion}`);
279
+ }
280
+ if (!diff) {
281
+ return;
282
+ }
283
+ const validPatch = ['prelease', 'build'];
284
+ const validMinor = [...validPatch, 'patch', 'prepatch'];
285
+ const validMajor = [...validMinor, 'minor', 'preminor'];
286
+ if (strategy === 'patch' && validPatch.includes(diff)) {
287
+ return;
288
+ }
289
+ if (strategy === 'minor' && validMinor.includes(diff)) {
290
+ return;
291
+ }
292
+ if (strategy === 'major' && validMajor.includes(diff)) {
293
+ return;
294
+ }
295
+ throw new Error(`Strapi versions doesn't match (${strategy} check): ${sourceVersion} does not match with ${destinationVersion}`);
296
+ }, _TransferEngine_assertSchemasMatching = function _TransferEngine_assertSchemasMatching(sourceSchemas, destinationSchemas) {
297
+ const strategy = this.options.schemaStrategy || exports.DEFAULT_SCHEMA_STRATEGY;
298
+ if (strategy === 'ignore') {
299
+ return;
300
+ }
301
+ const keys = (0, fp_1.uniq)(Object.keys(sourceSchemas).concat(Object.keys(destinationSchemas)));
302
+ const diffs = {};
303
+ keys.forEach((key) => {
304
+ const sourceSchema = sourceSchemas[key];
305
+ const destinationSchema = destinationSchemas[key];
306
+ const schemaDiffs = (0, schemas_1.compareSchemas)(sourceSchema, destinationSchema, strategy);
307
+ if (schemaDiffs.length) {
308
+ diffs[key] = schemaDiffs;
309
+ }
310
+ });
311
+ if (!(0, fp_1.isEmpty)(diffs)) {
312
+ throw new Error(`Import process failed because the project doesn't have a matching data structure
313
+ ${JSON.stringify(diffs, null, 2)}
314
+ `);
315
+ }
316
+ }, _TransferEngine_transferStage = async function _TransferEngine_transferStage(options) {
317
+ const { stage, source, destination, transform, tracker } = options;
318
+ if (!source || !destination || this.shouldSkipStage(stage)) {
319
+ // Wait until source and destination are closed
320
+ await Promise.allSettled([source, destination].map((stream) => {
321
+ // if stream is undefined or already closed, resolve immediately
322
+ if (!stream || stream.destroyed) {
323
+ return Promise.resolve();
324
+ }
325
+ // Wait until the close event is produced and then destroy the stream and resolve
326
+ return new Promise((resolve, reject) => {
327
+ stream.on('close', resolve).on('error', reject).destroy();
328
+ });
329
+ }));
330
+ __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_emitStageUpdate).call(this, 'skip', stage);
331
+ return;
332
+ }
333
+ __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_emitStageUpdate).call(this, 'start', stage);
334
+ await new Promise((resolve, reject) => {
335
+ let stream = source;
336
+ if (transform) {
337
+ stream = stream.pipe(transform);
338
+ }
339
+ if (tracker) {
340
+ stream = stream.pipe(tracker);
341
+ }
342
+ stream.pipe(destination).on('error', reject).on('close', resolve);
343
+ });
344
+ __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_emitStageUpdate).call(this, 'finish', stage);
345
+ }, _TransferEngine_resolveProviderResource = async function _TransferEngine_resolveProviderResource() {
346
+ const sourceMetadata = await this.sourceProvider.getMetadata();
347
+ const destinationMetadata = await this.destinationProvider.getMetadata();
348
+ if (sourceMetadata) {
349
+ __classPrivateFieldGet(this, _TransferEngine_metadata, "f").source = sourceMetadata;
350
+ }
351
+ if (destinationMetadata) {
352
+ __classPrivateFieldGet(this, _TransferEngine_metadata, "f").destination = destinationMetadata;
353
+ }
354
+ };
355
+ const createTransferEngine = (sourceProvider, destinationProvider, options) => {
356
+ return new TransferEngine(sourceProvider, destinationProvider, options);
357
+ };
358
+ exports.createTransferEngine = createTransferEngine;
359
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ export * as schemas from './schemas';
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.schemas = void 0;
27
+ exports.schemas = __importStar(require("./schemas"));
28
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ import type { Diff } from '../../../utils/json';
2
+ declare const strategies: {
3
+ exact(diffs: Diff[]): Diff[];
4
+ strict(diffs: Diff[]): Diff[];
5
+ };
6
+ declare const compareSchemas: <T, P>(a: T, b: P, strategy: keyof typeof strategies) => Diff[];
7
+ export { compareSchemas };
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.compareSchemas = void 0;
27
+ const utils = __importStar(require("../../../utils"));
28
+ const strategies = {
29
+ // No diffs
30
+ exact(diffs) {
31
+ return diffs;
32
+ },
33
+ // Diffs allowed on specific attributes properties
34
+ strict(diffs) {
35
+ const isIgnorableDiff = ({ path }) => {
36
+ return (path.length === 3 &&
37
+ // Root property must be attributes
38
+ path[0] === 'attributes' &&
39
+ // Need a valid string attribute name
40
+ typeof path[1] === 'string' &&
41
+ // The diff must be on ignorable attribute properties
42
+ ['private', 'required', 'configurable'].includes(path[2]));
43
+ };
44
+ const shouldKeepDiff = (diff) => !isIgnorableDiff(diff);
45
+ return diffs.filter(shouldKeepDiff);
46
+ },
47
+ };
48
+ const compareSchemas = (a, b, strategy) => {
49
+ const diffs = utils.json.diff(a, b);
50
+ return strategies[strategy](diffs);
51
+ };
52
+ exports.compareSchemas = compareSchemas;
53
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ export * as providers from './providers';
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.providers = void 0;
27
+ exports.providers = __importStar(require("./providers"));
28
+ //# sourceMappingURL=index.js.map
@@ -1,6 +1,8 @@
1
- /// <reference types="stream-chain" />
2
1
  /// <reference types="node" />
3
- import type { IDestinationProvider, IDestinationProviderTransferResults, IMetadata, ProviderType } from '../../types';
2
+ /// <reference types="stream-chain" />
3
+ import zlib from 'zlib';
4
+ import { Writable } from 'stream';
5
+ import type { IDestinationProvider, IDestinationProviderTransferResults, IMetadata, ProviderType } from '../../../../types';
4
6
  export interface ILocalFileDestinationProviderOptions {
5
7
  encryption: {
6
8
  enabled: boolean;
@@ -29,13 +31,15 @@ declare class LocalFileDestinationProvider implements IDestinationProvider {
29
31
  results: ILocalFileDestinationProviderTransferResults;
30
32
  constructor(options: ILocalFileDestinationProviderOptions);
31
33
  setMetadata(target: ProviderType, metadata: IMetadata): IDestinationProvider;
34
+ createGzip(): zlib.Gzip;
32
35
  bootstrap(): void | Promise<void>;
33
36
  close(): Promise<void>;
34
37
  rollback(): Promise<void>;
35
38
  getMetadata(): null;
36
- getSchemasStream(): import("stream-chain");
37
- getEntitiesStream(): NodeJS.WritableStream;
38
- getLinksStream(): NodeJS.WritableStream;
39
- getConfigurationStream(): NodeJS.WritableStream;
39
+ createSchemasWriteStream(): import("stream-chain");
40
+ createEntitiesWriteStream(): Writable;
41
+ createLinksWriteStream(): Writable;
42
+ createConfigurationWriteStream(): Writable;
43
+ createAssetsWriteStream(): Writable;
40
44
  }
41
45
  export {};