@strapi/data-transfer 4.14.4 → 4.15.0

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 (271) hide show
  1. package/dist/commands/commander.d.ts +1 -0
  2. package/dist/commands/commander.d.ts.map +1 -0
  3. package/dist/commands/data-transfer.d.ts +2 -1
  4. package/dist/commands/data-transfer.d.ts.map +1 -0
  5. package/dist/commands/export/action.d.ts +1 -0
  6. package/dist/commands/export/action.d.ts.map +1 -0
  7. package/dist/commands/export/command.d.ts +1 -0
  8. package/dist/commands/export/command.d.ts.map +1 -0
  9. package/dist/commands/helpers.d.ts +1 -0
  10. package/dist/commands/helpers.d.ts.map +1 -0
  11. package/dist/commands/import/action.d.ts +1 -0
  12. package/dist/commands/import/action.d.ts.map +1 -0
  13. package/dist/commands/import/command.d.ts +1 -0
  14. package/dist/commands/import/command.d.ts.map +1 -0
  15. package/dist/commands/index.d.ts +1 -0
  16. package/dist/commands/index.d.ts.map +1 -0
  17. package/dist/commands/transfer/action.d.ts +1 -0
  18. package/dist/commands/transfer/action.d.ts.map +1 -0
  19. package/dist/commands/transfer/command.d.ts +1 -0
  20. package/dist/commands/transfer/command.d.ts.map +1 -0
  21. package/dist/engine/diagnostic.d.ts +1 -0
  22. package/dist/engine/diagnostic.d.ts.map +1 -0
  23. package/dist/engine/errors.d.ts +1 -0
  24. package/dist/engine/errors.d.ts.map +1 -0
  25. package/dist/engine/index.d.ts +1 -0
  26. package/dist/engine/index.d.ts.map +1 -0
  27. package/dist/engine/validation/index.d.ts +1 -0
  28. package/dist/engine/validation/index.d.ts.map +1 -0
  29. package/dist/engine/validation/provider.d.ts +1 -0
  30. package/dist/engine/validation/provider.d.ts.map +1 -0
  31. package/dist/engine/validation/schemas/index.d.ts +1 -0
  32. package/dist/engine/validation/schemas/index.d.ts.map +1 -0
  33. package/dist/errors/base.d.ts +1 -0
  34. package/dist/errors/base.d.ts.map +1 -0
  35. package/dist/errors/constants.d.ts +1 -0
  36. package/dist/errors/constants.d.ts.map +1 -0
  37. package/dist/errors/index.d.ts +1 -0
  38. package/dist/errors/index.d.ts.map +1 -0
  39. package/dist/errors/providers.d.ts +1 -0
  40. package/dist/errors/providers.d.ts.map +1 -0
  41. package/dist/file/index.d.ts +1 -0
  42. package/dist/file/index.d.ts.map +1 -0
  43. package/dist/file/providers/destination/index.d.ts +1 -0
  44. package/dist/file/providers/destination/index.d.ts.map +1 -0
  45. package/dist/file/providers/destination/utils.d.ts +1 -0
  46. package/dist/file/providers/destination/utils.d.ts.map +1 -0
  47. package/dist/file/providers/index.d.ts +1 -0
  48. package/dist/file/providers/index.d.ts.map +1 -0
  49. package/dist/file/providers/source/index.d.ts +1 -0
  50. package/dist/file/providers/source/index.d.ts.map +1 -0
  51. package/dist/file/providers/source/utils.d.ts +1 -0
  52. package/dist/file/providers/source/utils.d.ts.map +1 -0
  53. package/dist/index.d.ts +1 -0
  54. package/dist/index.d.ts.map +1 -0
  55. package/dist/index.js +5242 -30
  56. package/dist/index.js.map +1 -1
  57. package/dist/index.mjs +5213 -0
  58. package/dist/index.mjs.map +1 -0
  59. package/dist/strapi/index.d.ts +1 -0
  60. package/dist/strapi/index.d.ts.map +1 -0
  61. package/dist/strapi/providers/index.d.ts +1 -0
  62. package/dist/strapi/providers/index.d.ts.map +1 -0
  63. package/dist/strapi/providers/local-destination/index.d.ts +1 -0
  64. package/dist/strapi/providers/local-destination/index.d.ts.map +1 -0
  65. package/dist/strapi/providers/local-destination/strategies/index.d.ts +1 -0
  66. package/dist/strapi/providers/local-destination/strategies/index.d.ts.map +1 -0
  67. package/dist/strapi/providers/local-destination/strategies/restore/configuration.d.ts +1 -0
  68. package/dist/strapi/providers/local-destination/strategies/restore/configuration.d.ts.map +1 -0
  69. package/dist/strapi/providers/local-destination/strategies/restore/entities.d.ts +1 -0
  70. package/dist/strapi/providers/local-destination/strategies/restore/entities.d.ts.map +1 -0
  71. package/dist/strapi/providers/local-destination/strategies/restore/index.d.ts +1 -0
  72. package/dist/strapi/providers/local-destination/strategies/restore/index.d.ts.map +1 -0
  73. package/dist/strapi/providers/local-destination/strategies/restore/links.d.ts +1 -0
  74. package/dist/strapi/providers/local-destination/strategies/restore/links.d.ts.map +1 -0
  75. package/dist/strapi/providers/local-source/assets.d.ts +1 -0
  76. package/dist/strapi/providers/local-source/assets.d.ts.map +1 -0
  77. package/dist/strapi/providers/local-source/configuration.d.ts +1 -0
  78. package/dist/strapi/providers/local-source/configuration.d.ts.map +1 -0
  79. package/dist/strapi/providers/local-source/entities.d.ts +1 -0
  80. package/dist/strapi/providers/local-source/entities.d.ts.map +1 -0
  81. package/dist/strapi/providers/local-source/index.d.ts +1 -0
  82. package/dist/strapi/providers/local-source/index.d.ts.map +1 -0
  83. package/dist/strapi/providers/local-source/links.d.ts +1 -0
  84. package/dist/strapi/providers/local-source/links.d.ts.map +1 -0
  85. package/dist/strapi/providers/remote-destination/index.d.ts +1 -0
  86. package/dist/strapi/providers/remote-destination/index.d.ts.map +1 -0
  87. package/dist/strapi/providers/remote-source/index.d.ts +1 -0
  88. package/dist/strapi/providers/remote-source/index.d.ts.map +1 -0
  89. package/dist/strapi/providers/utils.d.ts +1 -0
  90. package/dist/strapi/providers/utils.d.ts.map +1 -0
  91. package/dist/strapi/queries/entity.d.ts +1 -0
  92. package/dist/strapi/queries/entity.d.ts.map +1 -0
  93. package/dist/strapi/queries/index.d.ts +1 -0
  94. package/dist/strapi/queries/index.d.ts.map +1 -0
  95. package/dist/strapi/queries/link.d.ts +1 -0
  96. package/dist/strapi/queries/link.d.ts.map +1 -0
  97. package/dist/strapi/remote/constants.d.ts +1 -0
  98. package/dist/strapi/remote/constants.d.ts.map +1 -0
  99. package/dist/strapi/remote/flows/default.d.ts +1 -0
  100. package/dist/strapi/remote/flows/default.d.ts.map +1 -0
  101. package/dist/strapi/remote/flows/index.d.ts +1 -0
  102. package/dist/strapi/remote/flows/index.d.ts.map +1 -0
  103. package/dist/strapi/remote/handlers/abstract.d.ts +1 -0
  104. package/dist/strapi/remote/handlers/abstract.d.ts.map +1 -0
  105. package/dist/strapi/remote/handlers/constants.d.ts +1 -0
  106. package/dist/strapi/remote/handlers/constants.d.ts.map +1 -0
  107. package/dist/strapi/remote/handlers/index.d.ts +4 -3
  108. package/dist/strapi/remote/handlers/index.d.ts.map +1 -0
  109. package/dist/strapi/remote/handlers/pull.d.ts +1 -0
  110. package/dist/strapi/remote/handlers/pull.d.ts.map +1 -0
  111. package/dist/strapi/remote/handlers/push.d.ts +1 -0
  112. package/dist/strapi/remote/handlers/push.d.ts.map +1 -0
  113. package/dist/strapi/remote/handlers/utils.d.ts +1 -0
  114. package/dist/strapi/remote/handlers/utils.d.ts.map +1 -0
  115. package/dist/strapi/remote/index.d.ts +1 -0
  116. package/dist/strapi/remote/index.d.ts.map +1 -0
  117. package/dist/utils/components.d.ts +1 -0
  118. package/dist/utils/components.d.ts.map +1 -0
  119. package/dist/utils/encryption/decrypt.d.ts +1 -0
  120. package/dist/utils/encryption/decrypt.d.ts.map +1 -0
  121. package/dist/utils/encryption/encrypt.d.ts +1 -0
  122. package/dist/utils/encryption/encrypt.d.ts.map +1 -0
  123. package/dist/utils/encryption/index.d.ts +1 -0
  124. package/dist/utils/encryption/index.d.ts.map +1 -0
  125. package/dist/utils/index.d.ts +1 -0
  126. package/dist/utils/index.d.ts.map +1 -0
  127. package/dist/utils/json.d.ts +1 -0
  128. package/dist/utils/json.d.ts.map +1 -0
  129. package/dist/utils/middleware.d.ts +1 -0
  130. package/dist/utils/middleware.d.ts.map +1 -0
  131. package/dist/utils/providers.d.ts +1 -0
  132. package/dist/utils/providers.d.ts.map +1 -0
  133. package/dist/utils/schema.d.ts +1 -0
  134. package/dist/utils/schema.d.ts.map +1 -0
  135. package/dist/utils/stream.d.ts +1 -0
  136. package/dist/utils/stream.d.ts.map +1 -0
  137. package/dist/utils/transaction.d.ts +1 -0
  138. package/dist/utils/transaction.d.ts.map +1 -0
  139. package/package.json +19 -17
  140. package/dist/commands/commander.js +0 -138
  141. package/dist/commands/commander.js.map +0 -1
  142. package/dist/commands/data-transfer.js +0 -359
  143. package/dist/commands/data-transfer.js.map +0 -1
  144. package/dist/commands/export/action.js +0 -156
  145. package/dist/commands/export/action.js.map +0 -1
  146. package/dist/commands/export/command.js +0 -30
  147. package/dist/commands/export/command.js.map +0 -1
  148. package/dist/commands/helpers.js +0 -87
  149. package/dist/commands/helpers.js.map +0 -1
  150. package/dist/commands/import/action.js +0 -139
  151. package/dist/commands/import/action.js.map +0 -1
  152. package/dist/commands/import/command.js +0 -75
  153. package/dist/commands/import/command.js.map +0 -1
  154. package/dist/commands/index.js +0 -13
  155. package/dist/commands/index.js.map +0 -1
  156. package/dist/commands/transfer/action.js +0 -161
  157. package/dist/commands/transfer/action.js.map +0 -1
  158. package/dist/commands/transfer/command.js +0 -69
  159. package/dist/commands/transfer/command.js.map +0 -1
  160. package/dist/engine/diagnostic.js +0 -50
  161. package/dist/engine/diagnostic.js.map +0 -1
  162. package/dist/engine/errors.js +0 -29
  163. package/dist/engine/errors.js.map +0 -1
  164. package/dist/engine/index.js +0 -708
  165. package/dist/engine/index.js.map +0 -1
  166. package/dist/engine/validation/index.js +0 -19
  167. package/dist/engine/validation/index.js.map +0 -1
  168. package/dist/engine/validation/provider.js +0 -18
  169. package/dist/engine/validation/provider.js.map +0 -1
  170. package/dist/engine/validation/schemas/index.js +0 -70
  171. package/dist/engine/validation/schemas/index.js.map +0 -1
  172. package/dist/errors/base.js +0 -16
  173. package/dist/errors/base.js.map +0 -1
  174. package/dist/errors/constants.js +0 -9
  175. package/dist/errors/constants.js.map +0 -1
  176. package/dist/errors/index.js +0 -19
  177. package/dist/errors/index.js.map +0 -1
  178. package/dist/errors/providers.js +0 -32
  179. package/dist/errors/providers.js.map +0 -1
  180. package/dist/file/index.js +0 -28
  181. package/dist/file/index.js.map +0 -1
  182. package/dist/file/providers/destination/index.js +0 -177
  183. package/dist/file/providers/destination/index.js.map +0 -1
  184. package/dist/file/providers/destination/utils.js +0 -62
  185. package/dist/file/providers/destination/utils.js.map +0 -1
  186. package/dist/file/providers/index.js +0 -19
  187. package/dist/file/providers/index.js.map +0 -1
  188. package/dist/file/providers/source/index.js +0 -234
  189. package/dist/file/providers/source/index.js.map +0 -1
  190. package/dist/file/providers/source/utils.js +0 -62
  191. package/dist/file/providers/source/utils.js.map +0 -1
  192. package/dist/strapi/index.js +0 -30
  193. package/dist/strapi/index.js.map +0 -1
  194. package/dist/strapi/providers/index.js +0 -23
  195. package/dist/strapi/providers/index.js.map +0 -1
  196. package/dist/strapi/providers/local-destination/index.js +0 -360
  197. package/dist/strapi/providers/local-destination/index.js.map +0 -1
  198. package/dist/strapi/providers/local-destination/strategies/index.js +0 -28
  199. package/dist/strapi/providers/local-destination/strategies/index.js.map +0 -1
  200. package/dist/strapi/providers/local-destination/strategies/restore/configuration.js +0 -51
  201. package/dist/strapi/providers/local-destination/strategies/restore/configuration.js.map +0 -1
  202. package/dist/strapi/providers/local-destination/strategies/restore/entities.js +0 -106
  203. package/dist/strapi/providers/local-destination/strategies/restore/entities.js.map +0 -1
  204. package/dist/strapi/providers/local-destination/strategies/restore/index.js +0 -109
  205. package/dist/strapi/providers/local-destination/strategies/restore/index.js.map +0 -1
  206. package/dist/strapi/providers/local-destination/strategies/restore/links.js +0 -32
  207. package/dist/strapi/providers/local-destination/strategies/restore/links.js.map +0 -1
  208. package/dist/strapi/providers/local-source/assets.js +0 -102
  209. package/dist/strapi/providers/local-source/assets.js.map +0 -1
  210. package/dist/strapi/providers/local-source/configuration.js +0 -36
  211. package/dist/strapi/providers/local-source/configuration.js.map +0 -1
  212. package/dist/strapi/providers/local-source/entities.js +0 -85
  213. package/dist/strapi/providers/local-source/entities.js.map +0 -1
  214. package/dist/strapi/providers/local-source/index.js +0 -100
  215. package/dist/strapi/providers/local-source/index.js.map +0 -1
  216. package/dist/strapi/providers/local-source/links.js +0 -23
  217. package/dist/strapi/providers/local-source/links.js.map +0 -1
  218. package/dist/strapi/providers/remote-destination/index.js +0 -270
  219. package/dist/strapi/providers/remote-destination/index.js.map +0 -1
  220. package/dist/strapi/providers/remote-source/index.js +0 -239
  221. package/dist/strapi/providers/remote-source/index.js.map +0 -1
  222. package/dist/strapi/providers/utils.js +0 -138
  223. package/dist/strapi/providers/utils.js.map +0 -1
  224. package/dist/strapi/queries/entity.js +0 -130
  225. package/dist/strapi/queries/entity.js.map +0 -1
  226. package/dist/strapi/queries/index.js +0 -29
  227. package/dist/strapi/queries/index.js.map +0 -1
  228. package/dist/strapi/queries/link.js +0 -224
  229. package/dist/strapi/queries/link.js.map +0 -1
  230. package/dist/strapi/remote/constants.js +0 -6
  231. package/dist/strapi/remote/constants.js.map +0 -1
  232. package/dist/strapi/remote/flows/default.js +0 -41
  233. package/dist/strapi/remote/flows/default.js.map +0 -1
  234. package/dist/strapi/remote/flows/index.js +0 -59
  235. package/dist/strapi/remote/flows/index.js.map +0 -1
  236. package/dist/strapi/remote/handlers/abstract.js +0 -3
  237. package/dist/strapi/remote/handlers/abstract.js.map +0 -1
  238. package/dist/strapi/remote/handlers/constants.js +0 -5
  239. package/dist/strapi/remote/handlers/constants.js.map +0 -1
  240. package/dist/strapi/remote/handlers/index.js +0 -10
  241. package/dist/strapi/remote/handlers/index.js.map +0 -1
  242. package/dist/strapi/remote/handlers/pull.js +0 -243
  243. package/dist/strapi/remote/handlers/pull.js.map +0 -1
  244. package/dist/strapi/remote/handlers/push.js +0 -311
  245. package/dist/strapi/remote/handlers/push.js.map +0 -1
  246. package/dist/strapi/remote/handlers/utils.js +0 -298
  247. package/dist/strapi/remote/handlers/utils.js.map +0 -1
  248. package/dist/strapi/remote/index.js +0 -29
  249. package/dist/strapi/remote/index.js.map +0 -1
  250. package/dist/utils/components.js +0 -381
  251. package/dist/utils/components.js.map +0 -1
  252. package/dist/utils/encryption/decrypt.js +0 -47
  253. package/dist/utils/encryption/decrypt.js.map +0 -1
  254. package/dist/utils/encryption/encrypt.js +0 -47
  255. package/dist/utils/encryption/encrypt.js.map +0 -1
  256. package/dist/utils/encryption/index.js +0 -19
  257. package/dist/utils/encryption/index.js.map +0 -1
  258. package/dist/utils/index.js +0 -33
  259. package/dist/utils/index.js.map +0 -1
  260. package/dist/utils/json.js +0 -68
  261. package/dist/utils/json.js.map +0 -1
  262. package/dist/utils/middleware.js +0 -14
  263. package/dist/utils/middleware.js.map +0 -1
  264. package/dist/utils/providers.js +0 -11
  265. package/dist/utils/providers.js.map +0 -1
  266. package/dist/utils/schema.js +0 -29
  267. package/dist/utils/schema.js.map +0 -1
  268. package/dist/utils/stream.js +0 -59
  269. package/dist/utils/stream.js.map +0 -1
  270. package/dist/utils/transaction.js +0 -88
  271. package/dist/utils/transaction.js.map +0 -1
@@ -1,708 +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.errors = exports.createTransferEngine = exports.DEFAULT_SCHEMA_STRATEGY = exports.DEFAULT_VERSION_STRATEGY = exports.TransferGroupPresets = exports.TRANSFER_STAGES = void 0;
27
- const stream_1 = require("stream");
28
- const path_1 = require("path");
29
- const os_1 = require("os");
30
- const stream_chain_1 = require("stream-chain");
31
- const fp_1 = require("lodash/fp");
32
- const semver_1 = require("semver");
33
- const validation_1 = require("./validation");
34
- const errors_1 = require("./errors");
35
- const diagnostic_1 = require("./diagnostic");
36
- const utils = __importStar(require("../utils"));
37
- const providers_1 = require("../errors/providers");
38
- exports.TRANSFER_STAGES = Object.freeze([
39
- 'entities',
40
- 'links',
41
- 'assets',
42
- 'schemas',
43
- 'configuration',
44
- ]);
45
- /**
46
- * Preset filters for only/exclude options
47
- * */
48
- exports.TransferGroupPresets = {
49
- content: {
50
- links: true,
51
- entities: true,
52
- // TODO: If we need to implement filtering on a running stage, it would be done like this, but we still need to implement it
53
- // [
54
- // // Example: content processes the entities stage, but filters individual entities
55
- // {
56
- // filter(data) {
57
- // return shouldIncludeThisData(data);
58
- // },
59
- // },
60
- // ],
61
- },
62
- files: {
63
- assets: true,
64
- },
65
- config: {
66
- configuration: true,
67
- },
68
- };
69
- exports.DEFAULT_VERSION_STRATEGY = 'ignore';
70
- exports.DEFAULT_SCHEMA_STRATEGY = 'strict';
71
- class TransferEngine {
72
- sourceProvider;
73
- destinationProvider;
74
- options;
75
- #metadata = {};
76
- #schema = {};
77
- // Progress of the current stage
78
- progress;
79
- diagnostics;
80
- #handlers = {
81
- schemaDiff: [],
82
- errors: {},
83
- };
84
- onSchemaDiff(handler) {
85
- this.#handlers?.schemaDiff?.push(handler);
86
- }
87
- addErrorHandler(handlerName, handler) {
88
- if (!this.#handlers.errors[handlerName]) {
89
- this.#handlers.errors[handlerName] = [];
90
- }
91
- this.#handlers.errors[handlerName]?.push(handler);
92
- }
93
- async attemptResolveError(error) {
94
- const context = {};
95
- if (error instanceof providers_1.ProviderTransferError && error.details?.details.code) {
96
- const errorCode = error.details?.details.code;
97
- if (!this.#handlers.errors[errorCode]) {
98
- this.#handlers.errors[errorCode] = [];
99
- }
100
- await utils.middleware.runMiddleware(context ?? {}, this.#handlers.errors[errorCode] ?? []);
101
- }
102
- return !!context.ignore;
103
- }
104
- // Save the currently open stream so that we can access it at any time
105
- #currentStream;
106
- constructor(sourceProvider, destinationProvider, options) {
107
- this.diagnostics = (0, diagnostic_1.createDiagnosticReporter)();
108
- (0, validation_1.validateProvider)('source', sourceProvider);
109
- (0, validation_1.validateProvider)('destination', destinationProvider);
110
- this.sourceProvider = sourceProvider;
111
- this.destinationProvider = destinationProvider;
112
- this.options = options;
113
- this.progress = { data: {}, stream: new stream_1.PassThrough({ objectMode: true }) };
114
- }
115
- /**
116
- * Report a fatal error and throw it
117
- */
118
- panic(error) {
119
- this.reportError(error, 'fatal');
120
- throw error;
121
- }
122
- /**
123
- * Report an error diagnostic
124
- */
125
- reportError(error, severity) {
126
- this.diagnostics.report({
127
- kind: 'error',
128
- details: {
129
- severity,
130
- createdAt: new Date(),
131
- name: error.name,
132
- message: error.message,
133
- error,
134
- },
135
- });
136
- }
137
- /**
138
- * Report a warning diagnostic
139
- */
140
- reportWarning(message, origin) {
141
- this.diagnostics.report({
142
- kind: 'warning',
143
- details: { createdAt: new Date(), message, origin },
144
- });
145
- }
146
- /**
147
- * Report an info diagnostic
148
- */
149
- reportInfo(message, params) {
150
- this.diagnostics.report({
151
- kind: 'info',
152
- details: { createdAt: new Date(), message, params },
153
- });
154
- }
155
- /**
156
- * Create and return a transform stream based on the given stage and options.
157
- *
158
- * Allowed transformations includes 'filter' and 'map'.
159
- */
160
- #createStageTransformStream(key, options = {}) {
161
- const { includeGlobal = true } = options;
162
- const { throttle } = this.options;
163
- const { global: globalTransforms, [key]: stageTransforms } = this.options?.transforms ?? {};
164
- let stream = new stream_1.PassThrough({ objectMode: true });
165
- const applyTransforms = (transforms = []) => {
166
- const chainTransforms = [];
167
- for (const transform of transforms) {
168
- if ('filter' in transform) {
169
- chainTransforms.push(utils.stream.filter(transform.filter));
170
- }
171
- if ('map' in transform) {
172
- chainTransforms.push(utils.stream.map(transform.map));
173
- }
174
- }
175
- if (chainTransforms.length) {
176
- stream = stream.pipe((0, stream_chain_1.chain)(chainTransforms));
177
- }
178
- };
179
- if (includeGlobal) {
180
- applyTransforms(globalTransforms);
181
- }
182
- if ((0, fp_1.isNumber)(throttle) && throttle > 0) {
183
- stream = stream.pipe(new stream_1.PassThrough({
184
- objectMode: true,
185
- async transform(data, _encoding, callback) {
186
- await new Promise((resolve) => {
187
- setTimeout(resolve, throttle);
188
- });
189
- callback(null, data);
190
- },
191
- }));
192
- }
193
- applyTransforms(stageTransforms);
194
- return stream;
195
- }
196
- /**
197
- * Update the Engine's transfer progress data for a given stage.
198
- *
199
- * Providing aggregate options enable custom computation to get the size (bytes) or the aggregate key associated with the data
200
- */
201
- #updateTransferProgress(stage, data, aggregate) {
202
- if (!this.progress.data[stage]) {
203
- this.progress.data[stage] = { count: 0, bytes: 0, startTime: Date.now() };
204
- }
205
- const stageProgress = this.progress.data[stage];
206
- if (!stageProgress) {
207
- return;
208
- }
209
- const size = aggregate?.size?.(data) ?? JSON.stringify(data).length;
210
- const key = aggregate?.key?.(data);
211
- stageProgress.count += 1;
212
- stageProgress.bytes += size;
213
- // Handle aggregate updates if necessary
214
- if (key) {
215
- if (!stageProgress.aggregates) {
216
- stageProgress.aggregates = {};
217
- }
218
- const { aggregates } = stageProgress;
219
- if (!aggregates[key]) {
220
- aggregates[key] = { count: 0, bytes: 0 };
221
- }
222
- aggregates[key].count += 1;
223
- aggregates[key].bytes += size;
224
- }
225
- }
226
- /**
227
- * Create and return a PassThrough stream.
228
- *
229
- * Upon writing data into it, it'll update the Engine's transfer progress data and trigger stage update events.
230
- */
231
- #progressTracker(stage, aggregate) {
232
- return new stream_1.PassThrough({
233
- objectMode: true,
234
- transform: (data, _encoding, callback) => {
235
- this.#updateTransferProgress(stage, data, aggregate);
236
- this.#emitStageUpdate('progress', stage);
237
- callback(null, data);
238
- },
239
- });
240
- }
241
- /**
242
- * Shorthand method used to trigger transfer update events to every listeners
243
- */
244
- #emitTransferUpdate(type, payload) {
245
- this.progress.stream.emit(`transfer::${type}`, payload);
246
- }
247
- /**
248
- * Shorthand method used to trigger stage update events to every listeners
249
- */
250
- #emitStageUpdate(type, transferStage) {
251
- this.progress.stream.emit(`stage::${type}`, {
252
- data: this.progress.data,
253
- stage: transferStage,
254
- });
255
- }
256
- /**
257
- * Run a version check between two strapi version (source and destination) using the strategy given to the engine during initialization.
258
- *
259
- * If there is a mismatch, throws a validation error.
260
- */
261
- #assertStrapiVersionIntegrity(sourceVersion, destinationVersion) {
262
- const strategy = this.options.versionStrategy || exports.DEFAULT_VERSION_STRATEGY;
263
- const reject = () => {
264
- 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}`, {
265
- check: 'strapi.version',
266
- strategy,
267
- versions: { source: sourceVersion, destination: destinationVersion },
268
- });
269
- };
270
- if (!sourceVersion ||
271
- !destinationVersion ||
272
- strategy === 'ignore' ||
273
- destinationVersion === sourceVersion) {
274
- return;
275
- }
276
- let diff;
277
- try {
278
- diff = (0, semver_1.diff)(sourceVersion, destinationVersion);
279
- }
280
- catch {
281
- reject();
282
- }
283
- if (!diff) {
284
- return;
285
- }
286
- const validPatch = ['prelease', 'build'];
287
- const validMinor = [...validPatch, 'patch', 'prepatch'];
288
- const validMajor = [...validMinor, 'minor', 'preminor'];
289
- if (strategy === 'patch' && validPatch.includes(diff)) {
290
- return;
291
- }
292
- if (strategy === 'minor' && validMinor.includes(diff)) {
293
- return;
294
- }
295
- if (strategy === 'major' && validMajor.includes(diff)) {
296
- return;
297
- }
298
- reject();
299
- }
300
- /**
301
- * Run a check between two set of schemas (source and destination) using the strategy given to the engine during initialization.
302
- *
303
- * If there are differences and/or incompatibilities between source and destination schemas, then throw a validation error.
304
- */
305
- #assertSchemasMatching(sourceSchemas, destinationSchemas) {
306
- const strategy = this.options.schemaStrategy || exports.DEFAULT_SCHEMA_STRATEGY;
307
- if (strategy === 'ignore') {
308
- return;
309
- }
310
- const keys = (0, fp_1.uniq)(Object.keys(sourceSchemas).concat(Object.keys(destinationSchemas)));
311
- const diffs = {};
312
- keys.forEach((key) => {
313
- const sourceSchema = sourceSchemas[key];
314
- const destinationSchema = destinationSchemas[key];
315
- const schemaDiffs = (0, validation_1.compareSchemas)(sourceSchema, destinationSchema, strategy);
316
- if (schemaDiffs.length) {
317
- diffs[key] = schemaDiffs;
318
- }
319
- });
320
- if (!(0, fp_1.isEmpty)(diffs)) {
321
- const formattedDiffs = Object.entries(diffs)
322
- .map(([uid, ctDiffs]) => {
323
- let msg = `- ${uid}:${os_1.EOL}`;
324
- msg += ctDiffs
325
- .sort((a, b) => (a.kind > b.kind ? -1 : 1))
326
- .map((diff) => {
327
- const path = diff.path.join('.');
328
- if (diff.kind === 'added') {
329
- return `${path} exists in destination schema but not in source schema and the data will not be transferred.`;
330
- }
331
- if (diff.kind === 'deleted') {
332
- return `${path} exists in source schema but not in destination schema and the data will not be transferred.`;
333
- }
334
- if (diff.kind === 'modified') {
335
- if (diff.types[0] === diff.types[1]) {
336
- return `Schema value changed at "${path}": "${diff.values[0]}" (${diff.types[0]}) => "${diff.values[1]}" (${diff.types[1]})`;
337
- }
338
- return `Schema has differing data types at "${path}": "${diff.values[0]}" (${diff.types[0]}) => "${diff.values[1]}" (${diff.types[1]})`;
339
- }
340
- throw new errors_1.TransferEngineValidationError(`Invalid diff found for "${uid}"`, {
341
- check: `schema on ${uid}`,
342
- });
343
- })
344
- .map((line) => ` - ${line}`)
345
- .join(os_1.EOL);
346
- return msg;
347
- })
348
- .join(os_1.EOL);
349
- 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}`, {
350
- check: 'schema.changes',
351
- strategy,
352
- diffs,
353
- });
354
- }
355
- }
356
- shouldSkipStage(stage) {
357
- const { exclude, only } = this.options;
358
- // schemas must always be included
359
- if (stage === 'schemas') {
360
- return false;
361
- }
362
- // everything is included by default unless 'only' has been set
363
- let included = (0, fp_1.isEmpty)(only);
364
- if (only && only.length > 0) {
365
- included = only.some((transferGroup) => {
366
- return exports.TransferGroupPresets[transferGroup][stage];
367
- });
368
- }
369
- if (exclude && exclude.length > 0) {
370
- if (included) {
371
- included = !exclude.some((transferGroup) => {
372
- return exports.TransferGroupPresets[transferGroup][stage];
373
- });
374
- }
375
- }
376
- return !included;
377
- }
378
- async #transferStage(options) {
379
- const { stage, source, destination, transform, tracker } = options;
380
- const updateEndTime = () => {
381
- const stageData = this.progress.data[stage];
382
- if (stageData) {
383
- stageData.endTime = Date.now();
384
- }
385
- };
386
- if (!source || !destination || this.shouldSkipStage(stage)) {
387
- // Wait until source and destination are closed
388
- const results = await Promise.allSettled([source, destination].map((stream) => {
389
- // if stream is undefined or already closed, resolve immediately
390
- if (!stream || stream.destroyed) {
391
- return Promise.resolve();
392
- }
393
- // Wait until the close event is produced and then destroy the stream and resolve
394
- return new Promise((resolve, reject) => {
395
- stream.on('close', resolve).on('error', reject).destroy();
396
- });
397
- }));
398
- results.forEach((state) => {
399
- if (state.status === 'rejected') {
400
- this.reportWarning(state.reason, `transfer(${stage})`);
401
- }
402
- });
403
- this.#emitStageUpdate('skip', stage);
404
- return;
405
- }
406
- this.#emitStageUpdate('start', stage);
407
- await new Promise((resolve, reject) => {
408
- let stream = source;
409
- if (transform) {
410
- stream = stream.pipe(transform);
411
- }
412
- if (tracker) {
413
- stream = stream.pipe(tracker);
414
- }
415
- this.#currentStream = stream
416
- .pipe(destination)
417
- .on('error', (e) => {
418
- updateEndTime();
419
- this.#emitStageUpdate('error', stage);
420
- this.reportError(e, 'error');
421
- destination.destroy(e);
422
- reject(e);
423
- })
424
- .on('close', () => {
425
- this.#currentStream = undefined;
426
- updateEndTime();
427
- resolve();
428
- });
429
- });
430
- this.#emitStageUpdate('finish', stage);
431
- }
432
- // Cause an ongoing transfer to abort gracefully
433
- async abortTransfer() {
434
- const err = new errors_1.TransferEngineError('fatal', 'Transfer aborted.');
435
- if (!this.#currentStream) {
436
- throw err;
437
- }
438
- this.#currentStream.destroy(err);
439
- }
440
- async init() {
441
- // Resolve providers' resource and store
442
- // them in the engine's internal state
443
- await this.#resolveProviderResource();
444
- // Update the destination provider's source metadata
445
- const { source: sourceMetadata } = this.#metadata;
446
- if (sourceMetadata) {
447
- this.destinationProvider.setMetadata?.('source', sourceMetadata);
448
- }
449
- }
450
- /**
451
- * Run the bootstrap method in both source and destination providers
452
- */
453
- async bootstrap() {
454
- const results = await Promise.allSettled([
455
- this.sourceProvider.bootstrap?.(),
456
- this.destinationProvider.bootstrap?.(),
457
- ]);
458
- results.forEach((result) => {
459
- if (result.status === 'rejected') {
460
- this.panic(result.reason);
461
- }
462
- });
463
- }
464
- /**
465
- * Run the close method in both source and destination providers
466
- */
467
- async close() {
468
- const results = await Promise.allSettled([
469
- this.sourceProvider.close?.(),
470
- this.destinationProvider.close?.(),
471
- ]);
472
- results.forEach((result) => {
473
- if (result.status === 'rejected') {
474
- this.panic(result.reason);
475
- }
476
- });
477
- }
478
- async #resolveProviderResource() {
479
- const sourceMetadata = await this.sourceProvider.getMetadata();
480
- const destinationMetadata = await this.destinationProvider.getMetadata();
481
- if (sourceMetadata) {
482
- this.#metadata.source = sourceMetadata;
483
- }
484
- if (destinationMetadata) {
485
- this.#metadata.destination = destinationMetadata;
486
- }
487
- }
488
- async #getSchemas() {
489
- if (!this.#schema.source) {
490
- this.#schema.source = (await this.sourceProvider.getSchemas?.());
491
- }
492
- if (!this.#schema.destination) {
493
- this.#schema.destination = (await this.destinationProvider.getSchemas?.());
494
- }
495
- return {
496
- sourceSchemas: this.#schema.source,
497
- destinationSchemas: this.#schema.destination,
498
- };
499
- }
500
- async integrityCheck() {
501
- const sourceMetadata = await this.sourceProvider.getMetadata();
502
- const destinationMetadata = await this.destinationProvider.getMetadata();
503
- if (sourceMetadata && destinationMetadata) {
504
- this.#assertStrapiVersionIntegrity(sourceMetadata?.strapi?.version, destinationMetadata?.strapi?.version);
505
- }
506
- const { sourceSchemas, destinationSchemas } = await this.#getSchemas();
507
- try {
508
- if (sourceSchemas && destinationSchemas) {
509
- this.#assertSchemasMatching(sourceSchemas, destinationSchemas);
510
- }
511
- }
512
- catch (error) {
513
- // if this is a schema matching error, allow handlers to resolve it
514
- if (error instanceof errors_1.TransferEngineValidationError && error.details?.details?.diffs) {
515
- const schemaDiffs = error.details?.details?.diffs;
516
- const context = {
517
- ignoredDiffs: {},
518
- diffs: schemaDiffs,
519
- source: this.sourceProvider,
520
- destination: this.destinationProvider,
521
- };
522
- // if we don't have any handlers, throw the original error
523
- if ((0, fp_1.isEmpty)(this.#handlers.schemaDiff)) {
524
- throw error;
525
- }
526
- await utils.middleware.runMiddleware(context, this.#handlers.schemaDiff);
527
- // if there are any remaining diffs that weren't ignored
528
- const unresolvedDiffs = utils.json.diff(context.diffs, context.ignoredDiffs);
529
- if (unresolvedDiffs.length) {
530
- this.panic(new errors_1.TransferEngineValidationError('Unresolved differences in schema', {
531
- check: 'schema.changes',
532
- unresolvedDiffs,
533
- }));
534
- }
535
- return;
536
- }
537
- throw error;
538
- }
539
- }
540
- async transfer() {
541
- // reset data between transfers
542
- this.progress.data = {};
543
- try {
544
- this.#emitTransferUpdate('init');
545
- await this.bootstrap();
546
- await this.init();
547
- await this.integrityCheck();
548
- this.#emitTransferUpdate('start');
549
- await this.beforeTransfer();
550
- // Run the transfer stages
551
- await this.transferSchemas();
552
- await this.transferEntities();
553
- await this.transferAssets();
554
- await this.transferLinks();
555
- await this.transferConfiguration();
556
- // Gracefully close the providers
557
- await this.close();
558
- this.#emitTransferUpdate('finish');
559
- }
560
- catch (e) {
561
- this.#emitTransferUpdate('error', { error: e });
562
- const lastDiagnostic = (0, fp_1.last)(this.diagnostics.stack.items);
563
- // Do not report an error diagnostic if the last one reported the same error
564
- if (e instanceof Error &&
565
- (!lastDiagnostic || lastDiagnostic.kind !== 'error' || lastDiagnostic.details.error !== e)) {
566
- this.reportError(e, e.severity || 'fatal');
567
- }
568
- // Rollback the destination provider if an exception is thrown during the transfer
569
- // Note: This will be configurable in the future
570
- await this.destinationProvider.rollback?.(e);
571
- throw e;
572
- }
573
- return {
574
- source: this.sourceProvider.results,
575
- destination: this.destinationProvider.results,
576
- engine: this.progress.data,
577
- };
578
- }
579
- async beforeTransfer() {
580
- const runWithDiagnostic = async (provider) => {
581
- try {
582
- await provider.beforeTransfer?.();
583
- }
584
- catch (error) {
585
- if (error instanceof Error) {
586
- const resolved = await this.attemptResolveError(error);
587
- if (resolved) {
588
- return;
589
- }
590
- this.panic(error);
591
- }
592
- else {
593
- this.panic(new Error(`Unknwon error when executing "beforeTransfer" on the ${origin} provider`));
594
- }
595
- }
596
- };
597
- await runWithDiagnostic(this.sourceProvider);
598
- await runWithDiagnostic(this.destinationProvider);
599
- }
600
- async transferSchemas() {
601
- const stage = 'schemas';
602
- if (this.shouldSkipStage(stage)) {
603
- return;
604
- }
605
- const source = await this.sourceProvider.createSchemasReadStream?.();
606
- const destination = await this.destinationProvider.createSchemasWriteStream?.();
607
- const transform = this.#createStageTransformStream(stage);
608
- const tracker = this.#progressTracker(stage, {
609
- key: (value) => value.modelType,
610
- });
611
- await this.#transferStage({ stage, source, destination, transform, tracker });
612
- }
613
- async transferEntities() {
614
- const stage = 'entities';
615
- if (this.shouldSkipStage(stage)) {
616
- return;
617
- }
618
- const source = await this.sourceProvider.createEntitiesReadStream?.();
619
- const destination = await this.destinationProvider.createEntitiesWriteStream?.();
620
- const transform = (0, stream_chain_1.chain)([
621
- this.#createStageTransformStream(stage),
622
- new stream_1.Transform({
623
- objectMode: true,
624
- transform: async (entity, _encoding, callback) => {
625
- const { destinationSchemas: schemas } = await this.#getSchemas();
626
- if (!schemas) {
627
- return callback(null, entity);
628
- }
629
- // TODO: this would be safer if we only ignored things in ignoredDiffs, otherwise continue and let an error be thrown
630
- const availableContentTypes = Object.entries(schemas)
631
- .filter(([, schema]) => schema.modelType === 'contentType')
632
- .map(([uid]) => uid);
633
- // If the type of the transferred entity doesn't exist in the destination, then discard it
634
- if (!availableContentTypes.includes(entity.type)) {
635
- return callback(null, undefined);
636
- }
637
- const { type, data } = entity;
638
- const attributes = schemas[type].attributes;
639
- const attributesToRemove = (0, fp_1.difference)(Object.keys(data), Object.keys(attributes));
640
- const updatedEntity = (0, fp_1.set)('data', (0, fp_1.omit)(attributesToRemove, data), entity);
641
- callback(null, updatedEntity);
642
- },
643
- }),
644
- ]);
645
- const tracker = this.#progressTracker(stage, { key: (value) => value.type });
646
- await this.#transferStage({ stage, source, destination, transform, tracker });
647
- }
648
- async transferLinks() {
649
- const stage = 'links';
650
- if (this.shouldSkipStage(stage)) {
651
- return;
652
- }
653
- const source = await this.sourceProvider.createLinksReadStream?.();
654
- const destination = await this.destinationProvider.createLinksWriteStream?.();
655
- const transform = (0, stream_chain_1.chain)([
656
- this.#createStageTransformStream(stage),
657
- new stream_1.Transform({
658
- objectMode: true,
659
- transform: async (link, _encoding, callback) => {
660
- const { destinationSchemas: schemas } = await this.#getSchemas();
661
- if (!schemas) {
662
- return callback(null, link);
663
- }
664
- // TODO: this would be safer if we only ignored things in ignoredDiffs, otherwise continue and let an error be thrown
665
- const availableContentTypes = Object.keys(schemas);
666
- const isValidType = (uid) => availableContentTypes.includes(uid);
667
- if (!isValidType(link.left.type) || !isValidType(link.right.type)) {
668
- return callback(null, undefined); // ignore the link
669
- }
670
- callback(null, link);
671
- },
672
- }),
673
- ]);
674
- const tracker = this.#progressTracker(stage);
675
- await this.#transferStage({ stage, source, destination, transform, tracker });
676
- }
677
- async transferAssets() {
678
- const stage = 'assets';
679
- if (this.shouldSkipStage(stage)) {
680
- return;
681
- }
682
- const source = await this.sourceProvider.createAssetsReadStream?.();
683
- const destination = await this.destinationProvider.createAssetsWriteStream?.();
684
- const transform = this.#createStageTransformStream(stage);
685
- const tracker = this.#progressTracker(stage, {
686
- size: (value) => value.stats.size,
687
- key: (value) => (0, path_1.extname)(value.filename) || 'No extension',
688
- });
689
- await this.#transferStage({ stage, source, destination, transform, tracker });
690
- }
691
- async transferConfiguration() {
692
- const stage = 'configuration';
693
- if (this.shouldSkipStage(stage)) {
694
- return;
695
- }
696
- const source = await this.sourceProvider.createConfigurationReadStream?.();
697
- const destination = await this.destinationProvider.createConfigurationWriteStream?.();
698
- const transform = this.#createStageTransformStream(stage);
699
- const tracker = this.#progressTracker(stage);
700
- await this.#transferStage({ stage, source, destination, transform, tracker });
701
- }
702
- }
703
- const createTransferEngine = (sourceProvider, destinationProvider, options) => {
704
- return new TransferEngine(sourceProvider, destinationProvider, options);
705
- };
706
- exports.createTransferEngine = createTransferEngine;
707
- exports.errors = __importStar(require("./errors"));
708
- //# sourceMappingURL=index.js.map