@strapi/data-transfer 4.10.0-beta.0 → 4.10.0-beta.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.
Files changed (163) hide show
  1. package/dist/engine/diagnostic.js.map +1 -0
  2. package/dist/engine/errors.js.map +1 -0
  3. package/dist/engine/index.js.map +1 -0
  4. package/dist/engine/validation/index.js.map +1 -0
  5. package/dist/engine/validation/provider.js.map +1 -0
  6. package/dist/engine/validation/schemas/index.d.ts +3 -3
  7. package/dist/engine/validation/schemas/index.js +29 -12
  8. package/dist/engine/validation/schemas/index.js.map +1 -0
  9. package/dist/errors/base.js.map +1 -0
  10. package/dist/errors/constants.js.map +1 -0
  11. package/dist/errors/index.js.map +1 -0
  12. package/dist/errors/providers.js.map +1 -0
  13. package/dist/file/index.js.map +1 -0
  14. package/dist/file/providers/destination/index.js.map +1 -0
  15. package/dist/file/providers/destination/utils.js.map +1 -0
  16. package/dist/file/providers/index.js.map +1 -0
  17. package/dist/file/providers/source/index.js.map +1 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/strapi/index.js.map +1 -0
  20. package/dist/strapi/providers/index.js.map +1 -0
  21. package/dist/strapi/providers/local-destination/index.js.map +1 -0
  22. package/dist/strapi/providers/local-destination/strategies/index.js.map +1 -0
  23. package/dist/strapi/providers/local-destination/strategies/restore/configuration.js.map +1 -0
  24. package/dist/strapi/providers/local-destination/strategies/restore/entities.js.map +1 -0
  25. package/dist/strapi/providers/local-destination/strategies/restore/index.js.map +1 -0
  26. package/dist/strapi/providers/local-destination/strategies/restore/links.js.map +1 -0
  27. package/dist/strapi/providers/local-source/assets.js.map +1 -0
  28. package/dist/strapi/providers/local-source/configuration.js.map +1 -0
  29. package/dist/strapi/providers/local-source/entities.js.map +1 -0
  30. package/dist/strapi/providers/local-source/index.js.map +1 -0
  31. package/dist/strapi/providers/local-source/links.js.map +1 -0
  32. package/dist/strapi/providers/remote-destination/index.js +4 -19
  33. package/dist/strapi/providers/remote-destination/index.js.map +1 -0
  34. package/dist/strapi/providers/remote-source/index.js +3 -4
  35. package/dist/strapi/providers/remote-source/index.js.map +1 -0
  36. package/dist/strapi/providers/utils.d.ts +7 -2
  37. package/dist/strapi/providers/utils.js +22 -1
  38. package/dist/strapi/providers/utils.js.map +1 -0
  39. package/dist/strapi/queries/entity.js.map +1 -0
  40. package/dist/strapi/queries/index.js.map +1 -0
  41. package/dist/strapi/queries/link.js.map +1 -0
  42. package/dist/strapi/remote/constants.js.map +1 -0
  43. package/dist/strapi/remote/flows/default.js.map +1 -0
  44. package/dist/strapi/remote/flows/index.js.map +1 -0
  45. package/dist/strapi/remote/handlers/abstract.js.map +1 -0
  46. package/dist/strapi/remote/handlers/constants.js.map +1 -0
  47. package/dist/strapi/remote/handlers/index.js.map +1 -0
  48. package/dist/strapi/remote/handlers/pull.js.map +1 -0
  49. package/dist/strapi/remote/handlers/push.js.map +1 -0
  50. package/dist/strapi/remote/handlers/utils.js.map +1 -0
  51. package/dist/strapi/remote/index.js.map +1 -0
  52. package/dist/utils/encryption/decrypt.js.map +1 -0
  53. package/dist/utils/encryption/encrypt.js.map +1 -0
  54. package/dist/utils/encryption/index.js.map +1 -0
  55. package/dist/utils/index.js.map +1 -0
  56. package/dist/utils/json.d.ts +1 -1
  57. package/dist/utils/json.js.map +1 -0
  58. package/dist/utils/providers.js.map +1 -0
  59. package/dist/utils/schema.js.map +1 -0
  60. package/dist/utils/stream.js.map +1 -0
  61. package/dist/utils/transaction.js.map +1 -0
  62. package/package.json +17 -16
  63. package/jest.config.js +0 -14
  64. package/lib/engine/diagnostic.d.ts +0 -40
  65. package/lib/engine/diagnostic.js +0 -50
  66. package/lib/engine/errors.d.ts +0 -28
  67. package/lib/engine/errors.js +0 -29
  68. package/lib/engine/index.d.ts +0 -44
  69. package/lib/engine/index.js +0 -506
  70. package/lib/engine/validation/index.d.ts +0 -2
  71. package/lib/engine/validation/index.js +0 -19
  72. package/lib/engine/validation/provider.d.ts +0 -3
  73. package/lib/engine/validation/provider.js +0 -18
  74. package/lib/engine/validation/schemas/index.d.ts +0 -7
  75. package/lib/engine/validation/schemas/index.js +0 -53
  76. package/lib/errors/base.d.ts +0 -8
  77. package/lib/errors/base.js +0 -13
  78. package/lib/errors/constants.d.ts +0 -3
  79. package/lib/errors/constants.js +0 -9
  80. package/lib/errors/index.d.ts +0 -2
  81. package/lib/errors/index.js +0 -19
  82. package/lib/errors/providers.d.ts +0 -21
  83. package/lib/errors/providers.js +0 -32
  84. package/lib/file/index.d.ts +0 -1
  85. package/lib/file/index.js +0 -28
  86. package/lib/file/providers/destination/index.d.ts +0 -45
  87. package/lib/file/providers/destination/index.js +0 -174
  88. package/lib/file/providers/destination/utils.d.ts +0 -9
  89. package/lib/file/providers/destination/utils.js +0 -61
  90. package/lib/file/providers/index.d.ts +0 -2
  91. package/lib/file/providers/index.js +0 -19
  92. package/lib/file/providers/source/index.d.ts +0 -40
  93. package/lib/file/providers/source/index.js +0 -220
  94. package/lib/index.d.ts +0 -4
  95. package/lib/index.js +0 -31
  96. package/lib/strapi/index.d.ts +0 -3
  97. package/lib/strapi/index.js +0 -30
  98. package/lib/strapi/providers/index.d.ts +0 -3
  99. package/lib/strapi/providers/index.js +0 -22
  100. package/lib/strapi/providers/local-destination/index.d.ts +0 -34
  101. package/lib/strapi/providers/local-destination/index.js +0 -220
  102. package/lib/strapi/providers/local-destination/strategies/index.d.ts +0 -1
  103. package/lib/strapi/providers/local-destination/strategies/index.js +0 -28
  104. package/lib/strapi/providers/local-destination/strategies/restore/configuration.d.ts +0 -5
  105. package/lib/strapi/providers/local-destination/strategies/restore/configuration.js +0 -51
  106. package/lib/strapi/providers/local-destination/strategies/restore/entities.d.ts +0 -11
  107. package/lib/strapi/providers/local-destination/strategies/restore/entities.js +0 -103
  108. package/lib/strapi/providers/local-destination/strategies/restore/index.d.ts +0 -32
  109. package/lib/strapi/providers/local-destination/strategies/restore/index.js +0 -107
  110. package/lib/strapi/providers/local-destination/strategies/restore/links.d.ts +0 -4
  111. package/lib/strapi/providers/local-destination/strategies/restore/links.js +0 -32
  112. package/lib/strapi/providers/local-source/assets.d.ts +0 -5
  113. package/lib/strapi/providers/local-source/assets.js +0 -31
  114. package/lib/strapi/providers/local-source/configuration.d.ts +0 -5
  115. package/lib/strapi/providers/local-source/configuration.js +0 -36
  116. package/lib/strapi/providers/local-source/entities.d.ts +0 -10
  117. package/lib/strapi/providers/local-source/entities.js +0 -85
  118. package/lib/strapi/providers/local-source/index.d.ts +0 -27
  119. package/lib/strapi/providers/local-source/index.js +0 -98
  120. package/lib/strapi/providers/local-source/links.d.ts +0 -5
  121. package/lib/strapi/providers/local-source/links.js +0 -23
  122. package/lib/strapi/providers/remote-destination/index.d.ts +0 -37
  123. package/lib/strapi/providers/remote-destination/index.js +0 -284
  124. package/lib/strapi/providers/remote-destination/utils.d.ts +0 -31
  125. package/lib/strapi/providers/remote-destination/utils.js +0 -72
  126. package/lib/strapi/queries/entity.d.ts +0 -19
  127. package/lib/strapi/queries/entity.js +0 -130
  128. package/lib/strapi/queries/index.d.ts +0 -2
  129. package/lib/strapi/queries/index.js +0 -29
  130. package/lib/strapi/queries/link.d.ts +0 -6
  131. package/lib/strapi/queries/link.js +0 -215
  132. package/lib/strapi/remote/constants.d.ts +0 -2
  133. package/lib/strapi/remote/constants.js +0 -6
  134. package/lib/strapi/remote/controllers/index.d.ts +0 -1
  135. package/lib/strapi/remote/controllers/index.js +0 -18
  136. package/lib/strapi/remote/controllers/push.d.ts +0 -26
  137. package/lib/strapi/remote/controllers/push.js +0 -116
  138. package/lib/strapi/remote/flows/default.d.ts +0 -3
  139. package/lib/strapi/remote/flows/default.js +0 -41
  140. package/lib/strapi/remote/flows/index.d.ts +0 -18
  141. package/lib/strapi/remote/flows/index.js +0 -59
  142. package/lib/strapi/remote/handlers.d.ts +0 -10
  143. package/lib/strapi/remote/handlers.js +0 -285
  144. package/lib/strapi/remote/index.d.ts +0 -3
  145. package/lib/strapi/remote/index.js +0 -30
  146. package/lib/utils/encryption/decrypt.d.ts +0 -11
  147. package/lib/utils/encryption/decrypt.js +0 -47
  148. package/lib/utils/encryption/encrypt.d.ts +0 -11
  149. package/lib/utils/encryption/encrypt.js +0 -47
  150. package/lib/utils/encryption/index.d.ts +0 -2
  151. package/lib/utils/encryption/index.js +0 -19
  152. package/lib/utils/index.d.ts +0 -5
  153. package/lib/utils/index.js +0 -32
  154. package/lib/utils/json.d.ts +0 -30
  155. package/lib/utils/json.js +0 -68
  156. package/lib/utils/providers.d.ts +0 -2
  157. package/lib/utils/providers.js +0 -11
  158. package/lib/utils/schema.d.ts +0 -7
  159. package/lib/utils/schema.js +0 -29
  160. package/lib/utils/stream.d.ts +0 -27
  161. package/lib/utils/stream.js +0 -59
  162. package/lib/utils/transaction.d.ts +0 -3
  163. package/lib/utils/transaction.js +0 -88
@@ -1,506 +0,0 @@
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
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
26
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
27
- 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");
28
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
29
- };
30
- var _TransferEngine_instances, _TransferEngine_metadata, _TransferEngine_panic, _TransferEngine_reportError, _TransferEngine_reportWarning, _TransferEngine_reportInfo, _TransferEngine_createStageTransformStream, _TransferEngine_updateTransferProgress, _TransferEngine_progressTracker, _TransferEngine_emitTransferUpdate, _TransferEngine_emitStageUpdate, _TransferEngine_assertStrapiVersionIntegrity, _TransferEngine_assertSchemasMatching, _TransferEngine_transferStage, _TransferEngine_resolveProviderResource;
31
- Object.defineProperty(exports, "__esModule", { value: true });
32
- exports.errors = exports.createTransferEngine = exports.DEFAULT_SCHEMA_STRATEGY = exports.DEFAULT_VERSION_STRATEGY = exports.TransferGroupPresets = exports.TRANSFER_STAGES = void 0;
33
- const stream_1 = require("stream");
34
- const path_1 = require("path");
35
- const os_1 = require("os");
36
- const fp_1 = require("lodash/fp");
37
- const semver_1 = require("semver");
38
- const validation_1 = require("./validation");
39
- const stream_2 = require("../utils/stream");
40
- const errors_1 = require("./errors");
41
- const diagnostic_1 = require("./diagnostic");
42
- exports.TRANSFER_STAGES = Object.freeze([
43
- 'entities',
44
- 'links',
45
- 'assets',
46
- 'schemas',
47
- 'configuration',
48
- ]);
49
- /**
50
- * Preset filters for only/exclude options
51
- * */
52
- exports.TransferGroupPresets = {
53
- content: {
54
- links: true,
55
- entities: true,
56
- // TODO: If we need to implement filtering on a running stage, it would be done like this, but we still need to implement it
57
- // [
58
- // // Example: content processes the entities stage, but filters individual entities
59
- // {
60
- // filter(data) {
61
- // return shouldIncludeThisData(data);
62
- // },
63
- // },
64
- // ],
65
- },
66
- files: {
67
- assets: true,
68
- links: true,
69
- },
70
- config: {
71
- configuration: true,
72
- },
73
- };
74
- exports.DEFAULT_VERSION_STRATEGY = 'ignore';
75
- exports.DEFAULT_SCHEMA_STRATEGY = 'strict';
76
- class TransferEngine {
77
- constructor(sourceProvider, destinationProvider, options) {
78
- _TransferEngine_instances.add(this);
79
- _TransferEngine_metadata.set(this, {});
80
- this.diagnostics = (0, diagnostic_1.createDiagnosticReporter)();
81
- (0, validation_1.validateProvider)('source', sourceProvider);
82
- (0, validation_1.validateProvider)('destination', destinationProvider);
83
- this.sourceProvider = sourceProvider;
84
- this.destinationProvider = destinationProvider;
85
- this.options = options;
86
- this.progress = { data: {}, stream: new stream_1.PassThrough({ objectMode: true }) };
87
- }
88
- shouldSkipStage(stage) {
89
- const { exclude, only } = this.options;
90
- // schemas must always be included
91
- if (stage === 'schemas') {
92
- return false;
93
- }
94
- // everything is included by default unless 'only' has been set
95
- let included = (0, fp_1.isEmpty)(only);
96
- if (only?.length > 0) {
97
- included = only.some((transferGroup) => {
98
- return exports.TransferGroupPresets[transferGroup][stage];
99
- });
100
- }
101
- if (exclude?.length > 0) {
102
- if (included) {
103
- included = !exclude.some((transferGroup) => {
104
- return exports.TransferGroupPresets[transferGroup][stage];
105
- });
106
- }
107
- }
108
- return !included;
109
- }
110
- async init() {
111
- // Resolve providers' resource and store
112
- // them in the engine's internal state
113
- await __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_resolveProviderResource).call(this);
114
- // Update the destination provider's source metadata
115
- const { source: sourceMetadata } = __classPrivateFieldGet(this, _TransferEngine_metadata, "f");
116
- if (sourceMetadata) {
117
- this.destinationProvider.setMetadata?.('source', sourceMetadata);
118
- }
119
- }
120
- /**
121
- * Run the bootstrap method in both source and destination providers
122
- */
123
- async bootstrap() {
124
- const results = await Promise.allSettled([
125
- this.sourceProvider.bootstrap?.(),
126
- this.destinationProvider.bootstrap?.(),
127
- ]);
128
- results.forEach((result) => {
129
- if (result.status === 'rejected') {
130
- __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_panic).call(this, result.reason);
131
- }
132
- });
133
- }
134
- /**
135
- * Run the close method in both source and destination providers
136
- */
137
- async close() {
138
- const results = await Promise.allSettled([
139
- this.sourceProvider.close?.(),
140
- this.destinationProvider.close?.(),
141
- ]);
142
- results.forEach((result) => {
143
- if (result.status === 'rejected') {
144
- __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_panic).call(this, result.reason);
145
- }
146
- });
147
- }
148
- async integrityCheck() {
149
- try {
150
- const sourceMetadata = await this.sourceProvider.getMetadata();
151
- const destinationMetadata = await this.destinationProvider.getMetadata();
152
- if (sourceMetadata && destinationMetadata) {
153
- __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_assertStrapiVersionIntegrity).call(this, sourceMetadata?.strapi?.version, destinationMetadata?.strapi?.version);
154
- }
155
- const sourceSchemas = (await this.sourceProvider.getSchemas?.());
156
- const destinationSchemas = (await this.destinationProvider.getSchemas?.());
157
- if (sourceSchemas && destinationSchemas) {
158
- __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_assertSchemasMatching).call(this, sourceSchemas, destinationSchemas);
159
- }
160
- }
161
- catch (error) {
162
- if (error instanceof Error) {
163
- __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_panic).call(this, error);
164
- }
165
- throw error;
166
- }
167
- }
168
- async transfer() {
169
- // reset data between transfers
170
- this.progress.data = {};
171
- try {
172
- __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_emitTransferUpdate).call(this, 'init');
173
- await this.bootstrap();
174
- await this.init();
175
- await this.integrityCheck();
176
- __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_emitTransferUpdate).call(this, 'start');
177
- await this.beforeTransfer();
178
- // Run the transfer stages
179
- await this.transferSchemas();
180
- await this.transferEntities();
181
- await this.transferAssets();
182
- await this.transferLinks();
183
- await this.transferConfiguration();
184
- // Gracefully close the providers
185
- await this.close();
186
- __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_emitTransferUpdate).call(this, 'finish');
187
- }
188
- catch (e) {
189
- __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_emitTransferUpdate).call(this, 'error', { error: e });
190
- const lastDiagnostic = (0, fp_1.last)(this.diagnostics.stack.items);
191
- // Do not report an error diagnostic if the last one reported the same error
192
- if (e instanceof Error &&
193
- (!lastDiagnostic || lastDiagnostic.kind !== 'error' || lastDiagnostic.details.error !== e)) {
194
- __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_reportError).call(this, e, e.severity || 'fatal');
195
- }
196
- // Rollback the destination provider if an exception is thrown during the transfer
197
- // Note: This will be configurable in the future
198
- await this.destinationProvider.rollback?.(e);
199
- throw e;
200
- }
201
- return {
202
- source: this.sourceProvider.results,
203
- destination: this.destinationProvider.results,
204
- engine: this.progress.data,
205
- };
206
- }
207
- async beforeTransfer() {
208
- const runWithDiagnostic = async (provider) => {
209
- try {
210
- await provider.beforeTransfer?.();
211
- }
212
- catch (error) {
213
- // Error happening during the before transfer step should be considered fatal errors
214
- if (error instanceof Error) {
215
- __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_panic).call(this, error);
216
- }
217
- else {
218
- __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_panic).call(this, new Error(`Unknwon error when executing "beforeTransfer" on the ${origin} provider`));
219
- }
220
- }
221
- };
222
- await runWithDiagnostic(this.sourceProvider);
223
- await runWithDiagnostic(this.destinationProvider);
224
- }
225
- async transferSchemas() {
226
- const stage = 'schemas';
227
- const source = await this.sourceProvider.createSchemasReadStream?.();
228
- const destination = await this.destinationProvider.createSchemasWriteStream?.();
229
- const transform = __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_createStageTransformStream).call(this, stage);
230
- const tracker = __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_progressTracker).call(this, stage, { key: (value) => value.modelType });
231
- await __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_transferStage).call(this, { stage, source, destination, transform, tracker });
232
- }
233
- async transferEntities() {
234
- const stage = 'entities';
235
- const source = await this.sourceProvider.createEntitiesReadStream?.();
236
- const destination = await this.destinationProvider.createEntitiesWriteStream?.();
237
- const transform = __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_createStageTransformStream).call(this, stage);
238
- const tracker = __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_progressTracker).call(this, stage, { key: (value) => value.type });
239
- await __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_transferStage).call(this, { stage, source, destination, transform, tracker });
240
- }
241
- async transferLinks() {
242
- const stage = 'links';
243
- const source = await this.sourceProvider.createLinksReadStream?.();
244
- const destination = await this.destinationProvider.createLinksWriteStream?.();
245
- const transform = __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_createStageTransformStream).call(this, stage);
246
- const tracker = __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_progressTracker).call(this, stage);
247
- await __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_transferStage).call(this, { stage, source, destination, transform, tracker });
248
- }
249
- async transferAssets() {
250
- const stage = 'assets';
251
- const source = await this.sourceProvider.createAssetsReadStream?.();
252
- const destination = await this.destinationProvider.createAssetsWriteStream?.();
253
- const transform = __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_createStageTransformStream).call(this, stage);
254
- const tracker = __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_progressTracker).call(this, stage, {
255
- size: (value) => value.stats.size,
256
- key: (value) => (0, path_1.extname)(value.filename) || 'No extension',
257
- });
258
- await __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_transferStage).call(this, { stage, source, destination, transform, tracker });
259
- }
260
- async transferConfiguration() {
261
- const stage = 'configuration';
262
- const source = await this.sourceProvider.createConfigurationReadStream?.();
263
- const destination = await this.destinationProvider.createConfigurationWriteStream?.();
264
- const transform = __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_createStageTransformStream).call(this, stage);
265
- const tracker = __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_progressTracker).call(this, stage);
266
- await __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_transferStage).call(this, { stage, source, destination, transform, tracker });
267
- }
268
- }
269
- _TransferEngine_metadata = new WeakMap(), _TransferEngine_instances = new WeakSet(), _TransferEngine_panic = function _TransferEngine_panic(error) {
270
- __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_reportError).call(this, error, 'fatal');
271
- throw error;
272
- }, _TransferEngine_reportError = function _TransferEngine_reportError(error, severity) {
273
- this.diagnostics.report({
274
- kind: 'error',
275
- details: {
276
- severity,
277
- createdAt: new Date(),
278
- name: error.name,
279
- message: error.message,
280
- error,
281
- },
282
- });
283
- }, _TransferEngine_reportWarning = function _TransferEngine_reportWarning(message, origin) {
284
- this.diagnostics.report({
285
- kind: 'warning',
286
- details: { createdAt: new Date(), message, origin },
287
- });
288
- }, _TransferEngine_reportInfo = function _TransferEngine_reportInfo(message, params) {
289
- this.diagnostics.report({
290
- kind: 'info',
291
- details: { createdAt: new Date(), message, params },
292
- });
293
- }, _TransferEngine_createStageTransformStream = function _TransferEngine_createStageTransformStream(key, options = {}) {
294
- const { includeGlobal = true } = options;
295
- const { global: globalTransforms, [key]: stageTransforms } = this.options?.transforms ?? {};
296
- let stream = new stream_1.PassThrough({ objectMode: true });
297
- const applyTransforms = (transforms = []) => {
298
- for (const transform of transforms) {
299
- if ('filter' in transform) {
300
- stream = stream.pipe((0, stream_2.filter)(transform.filter));
301
- }
302
- if ('map' in transform) {
303
- stream = stream.pipe((0, stream_2.map)(transform.map));
304
- }
305
- }
306
- };
307
- if (includeGlobal) {
308
- applyTransforms(globalTransforms);
309
- }
310
- applyTransforms(stageTransforms);
311
- return stream;
312
- }, _TransferEngine_updateTransferProgress = function _TransferEngine_updateTransferProgress(stage, data, aggregate) {
313
- if (!this.progress.data[stage]) {
314
- this.progress.data[stage] = { count: 0, bytes: 0, startTime: Date.now() };
315
- }
316
- const stageProgress = this.progress.data[stage];
317
- if (!stageProgress) {
318
- return;
319
- }
320
- const size = aggregate?.size?.(data) ?? JSON.stringify(data).length;
321
- const key = aggregate?.key?.(data);
322
- stageProgress.count += 1;
323
- stageProgress.bytes += size;
324
- // Handle aggregate updates if necessary
325
- if (key) {
326
- if (!stageProgress.aggregates) {
327
- stageProgress.aggregates = {};
328
- }
329
- const { aggregates } = stageProgress;
330
- if (!aggregates[key]) {
331
- aggregates[key] = { count: 0, bytes: 0 };
332
- }
333
- aggregates[key].count += 1;
334
- aggregates[key].bytes += size;
335
- }
336
- }, _TransferEngine_progressTracker = function _TransferEngine_progressTracker(stage, aggregate) {
337
- return new stream_1.PassThrough({
338
- objectMode: true,
339
- transform: (data, _encoding, callback) => {
340
- __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_updateTransferProgress).call(this, stage, data, aggregate);
341
- __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_emitStageUpdate).call(this, 'progress', stage);
342
- callback(null, data);
343
- },
344
- });
345
- }, _TransferEngine_emitTransferUpdate = function _TransferEngine_emitTransferUpdate(type, payload) {
346
- this.progress.stream.emit(`transfer::${type}`, payload);
347
- }, _TransferEngine_emitStageUpdate = function _TransferEngine_emitStageUpdate(type, transferStage) {
348
- this.progress.stream.emit(`stage::${type}`, {
349
- data: this.progress.data,
350
- stage: transferStage,
351
- });
352
- }, _TransferEngine_assertStrapiVersionIntegrity = function _TransferEngine_assertStrapiVersionIntegrity(sourceVersion, destinationVersion) {
353
- const strategy = this.options.versionStrategy || exports.DEFAULT_VERSION_STRATEGY;
354
- const reject = () => {
355
- throw new errors_1.TransferEngineValidationError(`The source and destination provide are targeting incompatible Strapi versions (using the "${strategy}" strategy). The source (${this.sourceProvider.name}) version is ${sourceVersion} and the destination (${this.destinationProvider.name}) version is ${destinationVersion}`, {
356
- check: 'strapi.version',
357
- strategy,
358
- versions: { source: sourceVersion, destination: destinationVersion },
359
- });
360
- };
361
- if (!sourceVersion ||
362
- !destinationVersion ||
363
- strategy === 'ignore' ||
364
- destinationVersion === sourceVersion) {
365
- return;
366
- }
367
- let diff;
368
- try {
369
- diff = (0, semver_1.diff)(sourceVersion, destinationVersion);
370
- }
371
- catch {
372
- reject();
373
- }
374
- if (!diff) {
375
- return;
376
- }
377
- const validPatch = ['prelease', 'build'];
378
- const validMinor = [...validPatch, 'patch', 'prepatch'];
379
- const validMajor = [...validMinor, 'minor', 'preminor'];
380
- if (strategy === 'patch' && validPatch.includes(diff)) {
381
- return;
382
- }
383
- if (strategy === 'minor' && validMinor.includes(diff)) {
384
- return;
385
- }
386
- if (strategy === 'major' && validMajor.includes(diff)) {
387
- return;
388
- }
389
- reject();
390
- }, _TransferEngine_assertSchemasMatching = function _TransferEngine_assertSchemasMatching(sourceSchemas, destinationSchemas) {
391
- const strategy = this.options.schemaStrategy || exports.DEFAULT_SCHEMA_STRATEGY;
392
- if (strategy === 'ignore') {
393
- return;
394
- }
395
- const keys = (0, fp_1.uniq)(Object.keys(sourceSchemas).concat(Object.keys(destinationSchemas)));
396
- const diffs = {};
397
- keys.forEach((key) => {
398
- const sourceSchema = sourceSchemas[key];
399
- const destinationSchema = destinationSchemas[key];
400
- const schemaDiffs = (0, validation_1.compareSchemas)(sourceSchema, destinationSchema, strategy);
401
- if (schemaDiffs.length) {
402
- diffs[key] = schemaDiffs;
403
- }
404
- });
405
- if (!(0, fp_1.isEmpty)(diffs)) {
406
- const formattedDiffs = Object.entries(diffs)
407
- .map(([uid, ctDiffs]) => {
408
- let msg = `- ${uid}:${os_1.EOL}`;
409
- msg += ctDiffs
410
- .sort((a, b) => (a.kind > b.kind ? -1 : 1))
411
- .map((diff) => {
412
- const path = diff.path.join('.');
413
- if (diff.kind === 'added') {
414
- return `${path} exists in destination schema but not in source schema`;
415
- }
416
- if (diff.kind === 'deleted') {
417
- return `${path} exists in source schema but not in destination schema`;
418
- }
419
- if (diff.kind === 'modified') {
420
- if (diff.types[0] === diff.types[1]) {
421
- return `Schema value changed at "${path}": "${diff.values[0]}" (${diff.types[0]}) => "${diff.values[1]}" (${diff.types[1]})`;
422
- }
423
- return `Schema has differing data types at "${path}": "${diff.values[0]}" (${diff.types[0]}) => "${diff.values[1]}" (${diff.types[1]})`;
424
- }
425
- throw new errors_1.TransferEngineValidationError(`Invalid diff found for "${uid}"`, {
426
- check: `schema on ${uid}`,
427
- });
428
- })
429
- .map((line) => ` - ${line}`)
430
- .join(os_1.EOL);
431
- return msg;
432
- })
433
- .join(os_1.EOL);
434
- throw new errors_1.TransferEngineValidationError(`Invalid schema changes detected during integrity checks (using the ${strategy} strategy). Please find a summary of the changes below:\n${formattedDiffs}`, {
435
- check: 'schema.changes',
436
- strategy,
437
- diffs,
438
- });
439
- }
440
- }, _TransferEngine_transferStage = async function _TransferEngine_transferStage(options) {
441
- const { stage, source, destination, transform, tracker } = options;
442
- const updateEndTime = () => {
443
- const stageData = this.progress.data[stage];
444
- if (stageData) {
445
- stageData.endTime = Date.now();
446
- }
447
- };
448
- if (!source || !destination || this.shouldSkipStage(stage)) {
449
- // Wait until source and destination are closed
450
- const results = await Promise.allSettled([source, destination].map((stream) => {
451
- // if stream is undefined or already closed, resolve immediately
452
- if (!stream || stream.destroyed) {
453
- return Promise.resolve();
454
- }
455
- // Wait until the close event is produced and then destroy the stream and resolve
456
- return new Promise((resolve, reject) => {
457
- stream.on('close', resolve).on('error', reject).destroy();
458
- });
459
- }));
460
- results.forEach((state) => {
461
- if (state.status === 'rejected') {
462
- __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_reportWarning).call(this, state.reason, `transfer(${stage})`);
463
- }
464
- });
465
- __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_emitStageUpdate).call(this, 'skip', stage);
466
- return;
467
- }
468
- __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_emitStageUpdate).call(this, 'start', stage);
469
- await new Promise((resolve, reject) => {
470
- let stream = source;
471
- if (transform) {
472
- stream = stream.pipe(transform);
473
- }
474
- if (tracker) {
475
- stream = stream.pipe(tracker);
476
- }
477
- stream
478
- .pipe(destination)
479
- .on('error', (e) => {
480
- updateEndTime();
481
- __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_reportError).call(this, e, 'error');
482
- destination.destroy(e);
483
- reject(e);
484
- })
485
- .on('close', () => {
486
- updateEndTime();
487
- resolve();
488
- });
489
- });
490
- __classPrivateFieldGet(this, _TransferEngine_instances, "m", _TransferEngine_emitStageUpdate).call(this, 'finish', stage);
491
- }, _TransferEngine_resolveProviderResource = async function _TransferEngine_resolveProviderResource() {
492
- const sourceMetadata = await this.sourceProvider.getMetadata();
493
- const destinationMetadata = await this.destinationProvider.getMetadata();
494
- if (sourceMetadata) {
495
- __classPrivateFieldGet(this, _TransferEngine_metadata, "f").source = sourceMetadata;
496
- }
497
- if (destinationMetadata) {
498
- __classPrivateFieldGet(this, _TransferEngine_metadata, "f").destination = destinationMetadata;
499
- }
500
- };
501
- const createTransferEngine = (sourceProvider, destinationProvider, options) => {
502
- return new TransferEngine(sourceProvider, destinationProvider, options);
503
- };
504
- exports.createTransferEngine = createTransferEngine;
505
- exports.errors = __importStar(require("./errors"));
506
- //# sourceMappingURL=index.js.map
@@ -1,2 +0,0 @@
1
- export * from './schemas';
2
- export * from './provider';
@@ -1,19 +0,0 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./schemas"), exports);
18
- __exportStar(require("./provider"), exports);
19
- //# sourceMappingURL=index.js.map
@@ -1,3 +0,0 @@
1
- import type { IDestinationProvider, ISourceProvider, ProviderType } from '../../../types';
2
- declare const validateProvider: <T extends ProviderType>(type: ProviderType, provider?: ([T] extends ["source"] ? ISourceProvider : IDestinationProvider) | null | undefined) => undefined;
3
- export { validateProvider };
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateProvider = void 0;
4
- const fp_1 = require("lodash/fp");
5
- const errors_1 = require("../errors");
6
- const reject = (reason) => {
7
- throw new errors_1.TransferEngineValidationError(`Invalid provider supplied. ${reason}`);
8
- };
9
- const validateProvider = (type, provider) => {
10
- if (!provider) {
11
- return reject(`Expected an instance of "${(0, fp_1.capitalize)(type)}Provider", but got "${typeof provider}" instead.`);
12
- }
13
- if (provider.type !== type) {
14
- return reject(`Expected the provider to be of type "${type}" but got "${provider.type}" instead.`);
15
- }
16
- };
17
- exports.validateProvider = validateProvider;
18
- //# sourceMappingURL=provider.js.map
@@ -1,7 +0,0 @@
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 };
@@ -1,53 +0,0 @@
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
@@ -1,8 +0,0 @@
1
- import { Severity } from './constants';
2
- declare class DataTransferError<T = unknown> extends Error {
3
- origin: string;
4
- severity: Severity;
5
- details: T | null;
6
- constructor(origin: string, severity: Severity, message?: string, details?: T | null);
7
- }
8
- export { DataTransferError };
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DataTransferError = void 0;
4
- class DataTransferError extends Error {
5
- constructor(origin, severity, message, details) {
6
- super(message);
7
- this.origin = origin;
8
- this.severity = severity;
9
- this.details = details ?? null;
10
- }
11
- }
12
- exports.DataTransferError = DataTransferError;
13
- //# sourceMappingURL=base.js.map
@@ -1,3 +0,0 @@
1
- import { ErrorDiagnosticSeverity } from '../engine/diagnostic';
2
- export declare const SeverityKind: Record<string, ErrorDiagnosticSeverity>;
3
- export declare type Severity = (typeof SeverityKind)[keyof typeof SeverityKind];
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SeverityKind = void 0;
4
- exports.SeverityKind = {
5
- FATAL: 'fatal',
6
- ERROR: 'error',
7
- SILLY: 'silly',
8
- };
9
- //# sourceMappingURL=constants.js.map
@@ -1,2 +0,0 @@
1
- export * from './constants';
2
- export * from './base';