@strapi/data-transfer 5.12.1 → 5.12.3

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 (213) hide show
  1. package/dist/engine/errors.js +39 -0
  2. package/dist/engine/errors.js.map +1 -0
  3. package/dist/engine/errors.mjs +34 -0
  4. package/dist/engine/errors.mjs.map +1 -0
  5. package/dist/engine/index.js +797 -0
  6. package/dist/engine/index.js.map +1 -0
  7. package/dist/engine/index.mjs +792 -0
  8. package/dist/engine/index.mjs.map +1 -0
  9. package/dist/engine/validation/provider.js +19 -0
  10. package/dist/engine/validation/provider.js.map +1 -0
  11. package/dist/engine/validation/provider.mjs +17 -0
  12. package/dist/engine/validation/provider.mjs.map +1 -0
  13. package/dist/engine/validation/schemas/index.js +57 -0
  14. package/dist/engine/validation/schemas/index.js.map +1 -0
  15. package/dist/engine/validation/schemas/index.mjs +55 -0
  16. package/dist/engine/validation/schemas/index.mjs.map +1 -0
  17. package/dist/errors/base.js +13 -0
  18. package/dist/errors/base.js.map +1 -0
  19. package/dist/errors/base.mjs +11 -0
  20. package/dist/errors/base.mjs.map +1 -0
  21. package/dist/errors/constants.js +10 -0
  22. package/dist/errors/constants.js.map +1 -0
  23. package/dist/errors/constants.mjs +8 -0
  24. package/dist/errors/constants.mjs.map +1 -0
  25. package/dist/errors/providers.js +41 -0
  26. package/dist/errors/providers.js.map +1 -0
  27. package/dist/errors/providers.mjs +36 -0
  28. package/dist/errors/providers.mjs.map +1 -0
  29. package/dist/file/index.js +8 -0
  30. package/dist/file/index.js.map +1 -0
  31. package/dist/file/index.mjs +3 -0
  32. package/dist/file/index.mjs.map +1 -0
  33. package/dist/file/providers/destination/index.js +248 -0
  34. package/dist/file/providers/destination/index.js.map +1 -0
  35. package/dist/file/providers/destination/index.mjs +246 -0
  36. package/dist/file/providers/destination/index.mjs.map +1 -0
  37. package/dist/file/providers/destination/utils.js +63 -0
  38. package/dist/file/providers/destination/utils.js.map +1 -0
  39. package/dist/file/providers/destination/utils.mjs +60 -0
  40. package/dist/file/providers/destination/utils.mjs.map +1 -0
  41. package/dist/file/providers/index.js +10 -0
  42. package/dist/file/providers/index.js.map +1 -0
  43. package/dist/file/providers/index.mjs +3 -0
  44. package/dist/file/providers/index.mjs.map +1 -0
  45. package/dist/file/providers/source/index.js +288 -0
  46. package/dist/file/providers/source/index.js.map +1 -0
  47. package/dist/file/providers/source/index.mjs +286 -0
  48. package/dist/file/providers/source/index.mjs.map +1 -0
  49. package/dist/file/providers/source/utils.js +56 -0
  50. package/dist/file/providers/source/utils.js.map +1 -0
  51. package/dist/file/providers/source/utils.mjs +52 -0
  52. package/dist/file/providers/source/utils.mjs.map +1 -0
  53. package/dist/index.js +8 -5692
  54. package/dist/index.js.map +1 -1
  55. package/dist/index.mjs +8 -5674
  56. package/dist/index.mjs.map +1 -1
  57. package/dist/strapi/index.js +12 -0
  58. package/dist/strapi/index.js.map +1 -0
  59. package/dist/strapi/index.mjs +7 -0
  60. package/dist/strapi/index.mjs.map +1 -0
  61. package/dist/strapi/providers/index.js +16 -0
  62. package/dist/strapi/providers/index.js.map +1 -0
  63. package/dist/strapi/providers/index.mjs +7 -0
  64. package/dist/strapi/providers/index.mjs.map +1 -0
  65. package/dist/strapi/providers/local-destination/index.js +419 -0
  66. package/dist/strapi/providers/local-destination/index.js.map +1 -0
  67. package/dist/strapi/providers/local-destination/index.mjs +396 -0
  68. package/dist/strapi/providers/local-destination/index.mjs.map +1 -0
  69. package/dist/strapi/providers/local-destination/strategies/restore/configuration.js +52 -0
  70. package/dist/strapi/providers/local-destination/strategies/restore/configuration.js.map +1 -0
  71. package/dist/strapi/providers/local-destination/strategies/restore/configuration.mjs +49 -0
  72. package/dist/strapi/providers/local-destination/strategies/restore/configuration.mjs.map +1 -0
  73. package/dist/strapi/providers/local-destination/strategies/restore/entities.js +64 -0
  74. package/dist/strapi/providers/local-destination/strategies/restore/entities.js.map +1 -0
  75. package/dist/strapi/providers/local-destination/strategies/restore/entities.mjs +62 -0
  76. package/dist/strapi/providers/local-destination/strategies/restore/entities.mjs.map +1 -0
  77. package/dist/strapi/providers/local-destination/strategies/restore/index.js +126 -0
  78. package/dist/strapi/providers/local-destination/strategies/restore/index.js.map +1 -0
  79. package/dist/strapi/providers/local-destination/strategies/restore/index.mjs +122 -0
  80. package/dist/strapi/providers/local-destination/strategies/restore/index.mjs.map +1 -0
  81. package/dist/strapi/providers/local-destination/strategies/restore/links.js +60 -0
  82. package/dist/strapi/providers/local-destination/strategies/restore/links.js.map +1 -0
  83. package/dist/strapi/providers/local-destination/strategies/restore/links.mjs +58 -0
  84. package/dist/strapi/providers/local-destination/strategies/restore/links.mjs.map +1 -0
  85. package/dist/strapi/providers/local-source/assets.js +123 -0
  86. package/dist/strapi/providers/local-source/assets.js.map +1 -0
  87. package/dist/strapi/providers/local-source/assets.mjs +121 -0
  88. package/dist/strapi/providers/local-source/assets.mjs.map +1 -0
  89. package/dist/strapi/providers/local-source/configuration.js +39 -0
  90. package/dist/strapi/providers/local-source/configuration.js.map +1 -0
  91. package/dist/strapi/providers/local-source/configuration.mjs +37 -0
  92. package/dist/strapi/providers/local-source/configuration.mjs.map +1 -0
  93. package/dist/strapi/providers/local-source/entities.js +62 -0
  94. package/dist/strapi/providers/local-source/entities.js.map +1 -0
  95. package/dist/strapi/providers/local-source/entities.mjs +59 -0
  96. package/dist/strapi/providers/local-source/entities.mjs.map +1 -0
  97. package/dist/strapi/providers/local-source/index.js +154 -0
  98. package/dist/strapi/providers/local-source/index.js.map +1 -0
  99. package/dist/strapi/providers/local-source/index.mjs +152 -0
  100. package/dist/strapi/providers/local-source/index.mjs.map +1 -0
  101. package/dist/strapi/providers/local-source/links.js +26 -0
  102. package/dist/strapi/providers/local-source/links.js.map +1 -0
  103. package/dist/strapi/providers/local-source/links.mjs +24 -0
  104. package/dist/strapi/providers/local-source/links.mjs.map +1 -0
  105. package/dist/strapi/providers/remote-destination/index.js +392 -0
  106. package/dist/strapi/providers/remote-destination/index.js.map +1 -0
  107. package/dist/strapi/providers/remote-destination/index.mjs +390 -0
  108. package/dist/strapi/providers/remote-destination/index.mjs.map +1 -0
  109. package/dist/strapi/providers/remote-source/index.js +405 -0
  110. package/dist/strapi/providers/remote-source/index.js.map +1 -0
  111. package/dist/strapi/providers/remote-source/index.mjs +403 -0
  112. package/dist/strapi/providers/remote-source/index.mjs.map +1 -0
  113. package/dist/strapi/providers/utils.js +173 -0
  114. package/dist/strapi/providers/utils.js.map +1 -0
  115. package/dist/strapi/providers/utils.mjs +169 -0
  116. package/dist/strapi/providers/utils.mjs.map +1 -0
  117. package/dist/strapi/queries/entity.js +125 -0
  118. package/dist/strapi/queries/entity.js.map +1 -0
  119. package/dist/strapi/queries/entity.mjs +123 -0
  120. package/dist/strapi/queries/entity.mjs.map +1 -0
  121. package/dist/strapi/queries/index.js +10 -0
  122. package/dist/strapi/queries/index.js.map +1 -0
  123. package/dist/strapi/queries/index.mjs +5 -0
  124. package/dist/strapi/queries/index.mjs.map +1 -0
  125. package/dist/strapi/queries/link.js +298 -0
  126. package/dist/strapi/queries/link.js.map +1 -0
  127. package/dist/strapi/queries/link.mjs +295 -0
  128. package/dist/strapi/queries/link.mjs.map +1 -0
  129. package/dist/strapi/remote/constants.js +11 -0
  130. package/dist/strapi/remote/constants.js.map +1 -0
  131. package/dist/strapi/remote/constants.mjs +8 -0
  132. package/dist/strapi/remote/constants.mjs.map +1 -0
  133. package/dist/strapi/remote/flows/default.js +43 -0
  134. package/dist/strapi/remote/flows/default.js.map +1 -0
  135. package/dist/strapi/remote/flows/default.mjs +41 -0
  136. package/dist/strapi/remote/flows/default.mjs.map +1 -0
  137. package/dist/strapi/remote/flows/index.js +54 -0
  138. package/dist/strapi/remote/flows/index.js.map +1 -0
  139. package/dist/strapi/remote/flows/index.mjs +52 -0
  140. package/dist/strapi/remote/flows/index.mjs.map +1 -0
  141. package/dist/strapi/remote/handlers/constants.js +10 -0
  142. package/dist/strapi/remote/handlers/constants.js.map +1 -0
  143. package/dist/strapi/remote/handlers/constants.mjs +8 -0
  144. package/dist/strapi/remote/handlers/constants.mjs.map +1 -0
  145. package/dist/strapi/remote/handlers/index.js +12 -0
  146. package/dist/strapi/remote/handlers/index.js.map +1 -0
  147. package/dist/strapi/remote/handlers/index.mjs +4 -0
  148. package/dist/strapi/remote/handlers/index.mjs.map +1 -0
  149. package/dist/strapi/remote/handlers/pull.js +348 -0
  150. package/dist/strapi/remote/handlers/pull.js.map +1 -0
  151. package/dist/strapi/remote/handlers/pull.mjs +346 -0
  152. package/dist/strapi/remote/handlers/pull.mjs.map +1 -0
  153. package/dist/strapi/remote/handlers/push.js +400 -0
  154. package/dist/strapi/remote/handlers/push.js.map +1 -0
  155. package/dist/strapi/remote/handlers/push.mjs +398 -0
  156. package/dist/strapi/remote/handlers/push.mjs.map +1 -0
  157. package/dist/strapi/remote/handlers/utils.js +316 -0
  158. package/dist/strapi/remote/handlers/utils.js.map +1 -0
  159. package/dist/strapi/remote/handlers/utils.mjs +310 -0
  160. package/dist/strapi/remote/handlers/utils.mjs.map +1 -0
  161. package/dist/strapi/remote/index.js +10 -0
  162. package/dist/strapi/remote/index.js.map +1 -0
  163. package/dist/strapi/remote/index.mjs +5 -0
  164. package/dist/strapi/remote/index.mjs.map +1 -0
  165. package/dist/utils/components.js +178 -0
  166. package/dist/utils/components.js.map +1 -0
  167. package/dist/utils/components.mjs +171 -0
  168. package/dist/utils/components.mjs.map +1 -0
  169. package/dist/utils/diagnostic.js +51 -0
  170. package/dist/utils/diagnostic.js.map +1 -0
  171. package/dist/utils/diagnostic.mjs +49 -0
  172. package/dist/utils/diagnostic.mjs.map +1 -0
  173. package/dist/utils/encryption/decrypt.js +47 -0
  174. package/dist/utils/encryption/decrypt.js.map +1 -0
  175. package/dist/utils/encryption/decrypt.mjs +45 -0
  176. package/dist/utils/encryption/decrypt.mjs.map +1 -0
  177. package/dist/utils/encryption/encrypt.js +47 -0
  178. package/dist/utils/encryption/encrypt.js.map +1 -0
  179. package/dist/utils/encryption/encrypt.mjs +45 -0
  180. package/dist/utils/encryption/encrypt.mjs.map +1 -0
  181. package/dist/utils/encryption/index.js +10 -0
  182. package/dist/utils/encryption/index.js.map +1 -0
  183. package/dist/utils/encryption/index.mjs +3 -0
  184. package/dist/utils/encryption/index.mjs.map +1 -0
  185. package/dist/utils/index.js +20 -0
  186. package/dist/utils/index.js.map +1 -0
  187. package/dist/utils/index.mjs +15 -0
  188. package/dist/utils/index.mjs.map +1 -0
  189. package/dist/utils/json.js +96 -0
  190. package/dist/utils/json.js.map +1 -0
  191. package/dist/utils/json.mjs +94 -0
  192. package/dist/utils/json.mjs.map +1 -0
  193. package/dist/utils/middleware.js +14 -0
  194. package/dist/utils/middleware.js.map +1 -0
  195. package/dist/utils/middleware.mjs +12 -0
  196. package/dist/utils/middleware.mjs.map +1 -0
  197. package/dist/utils/providers.js +12 -0
  198. package/dist/utils/providers.js.map +1 -0
  199. package/dist/utils/providers.mjs +10 -0
  200. package/dist/utils/providers.mjs.map +1 -0
  201. package/dist/utils/schema.js +32 -0
  202. package/dist/utils/schema.js.map +1 -0
  203. package/dist/utils/schema.mjs +29 -0
  204. package/dist/utils/schema.mjs.map +1 -0
  205. package/dist/utils/stream.js +59 -0
  206. package/dist/utils/stream.js.map +1 -0
  207. package/dist/utils/stream.mjs +55 -0
  208. package/dist/utils/stream.mjs.map +1 -0
  209. package/dist/utils/transaction.js +93 -0
  210. package/dist/utils/transaction.js.map +1 -0
  211. package/dist/utils/transaction.mjs +91 -0
  212. package/dist/utils/transaction.mjs.map +1 -0
  213. package/package.json +5 -5
@@ -0,0 +1,12 @@
1
+ 'use strict';
2
+
3
+ var index = require('./providers/index.js');
4
+ var index$1 = require('./queries/index.js');
5
+ var index$2 = require('./remote/index.js');
6
+
7
+
8
+
9
+ exports.providers = index;
10
+ exports.queries = index$1;
11
+ exports.remote = index$2;
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
@@ -0,0 +1,7 @@
1
+ import * as index from './providers/index.mjs';
2
+ export { index as providers };
3
+ import * as index$1 from './queries/index.mjs';
4
+ export { index$1 as queries };
5
+ import * as index$2 from './remote/index.mjs';
6
+ export { index$2 as remote };
7
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}
@@ -0,0 +1,16 @@
1
+ 'use strict';
2
+
3
+ var index = require('./local-destination/index.js');
4
+ var index$1 = require('./local-source/index.js');
5
+ var index$2 = require('./remote-destination/index.js');
6
+ var index$3 = require('./remote-source/index.js');
7
+
8
+ // Local
9
+
10
+ exports.DEFAULT_CONFLICT_STRATEGY = index.DEFAULT_CONFLICT_STRATEGY;
11
+ exports.VALID_CONFLICT_STRATEGIES = index.VALID_CONFLICT_STRATEGIES;
12
+ exports.createLocalStrapiDestinationProvider = index.createLocalStrapiDestinationProvider;
13
+ exports.createLocalStrapiSourceProvider = index$1.createLocalStrapiSourceProvider;
14
+ exports.createRemoteStrapiDestinationProvider = index$2.createRemoteStrapiDestinationProvider;
15
+ exports.createRemoteStrapiSourceProvider = index$3.createRemoteStrapiSourceProvider;
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../src/strapi/providers/index.ts"],"sourcesContent":["// Local\nexport * from './local-destination';\nexport * from './local-source';\n\n// Remote\nexport * from './remote-destination';\nexport * from './remote-source';\n"],"names":[],"mappings":";;;;;;;AAAA;;;;;;;;;"}
@@ -0,0 +1,7 @@
1
+ export { DEFAULT_CONFLICT_STRATEGY, VALID_CONFLICT_STRATEGIES, createLocalStrapiDestinationProvider } from './local-destination/index.mjs';
2
+ export { createLocalStrapiSourceProvider } from './local-source/index.mjs';
3
+ export { createRemoteStrapiDestinationProvider } from './remote-destination/index.mjs';
4
+ export { createRemoteStrapiSourceProvider } from './remote-source/index.mjs';
5
+
6
+ // Local
7
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":["../../../src/strapi/providers/index.ts"],"sourcesContent":["// Local\nexport * from './local-destination';\nexport * from './local-source';\n\n// Remote\nexport * from './remote-destination';\nexport * from './remote-source';\n"],"names":[],"mappings":";;;;;AAAA"}
@@ -0,0 +1,419 @@
1
+ 'use strict';
2
+
3
+ var stream = require('stream');
4
+ var path = require('path');
5
+ var fse = require('fs-extra');
6
+ var index = require('./strategies/restore/index.js');
7
+ require('crypto');
8
+ require('lodash/fp');
9
+ var schema = require('../../../utils/schema.js');
10
+ var transaction = require('../../../utils/transaction.js');
11
+ require('events');
12
+ var providers = require('../../../errors/providers.js');
13
+ var providers$1 = require('../../../utils/providers.js');
14
+ var entities = require('./strategies/restore/entities.js');
15
+ var configuration = require('./strategies/restore/configuration.js');
16
+ var links = require('./strategies/restore/links.js');
17
+
18
+ function _interopNamespaceDefault(e) {
19
+ var n = Object.create(null);
20
+ if (e) {
21
+ Object.keys(e).forEach(function (k) {
22
+ if (k !== 'default') {
23
+ var d = Object.getOwnPropertyDescriptor(e, k);
24
+ Object.defineProperty(n, k, d.get ? d : {
25
+ enumerable: true,
26
+ get: function () { return e[k]; }
27
+ });
28
+ }
29
+ });
30
+ }
31
+ n.default = e;
32
+ return Object.freeze(n);
33
+ }
34
+
35
+ var fse__namespace = /*#__PURE__*/_interopNamespaceDefault(fse);
36
+
37
+ function _class_private_field_loose_base(receiver, privateKey) {
38
+ if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) {
39
+ throw new TypeError("attempted to use private field on non-instance");
40
+ }
41
+ return receiver;
42
+ }
43
+ var id = 0;
44
+ function _class_private_field_loose_key(name) {
45
+ return "__private_" + id++ + "_" + name;
46
+ }
47
+ const VALID_CONFLICT_STRATEGIES = [
48
+ 'restore'
49
+ ];
50
+ const DEFAULT_CONFLICT_STRATEGY = 'restore';
51
+ var _diagnostics = /*#__PURE__*/ _class_private_field_loose_key("_diagnostics"), /**
52
+ * The entities mapper is used to map old entities to their new IDs
53
+ */ _entitiesMapper = /*#__PURE__*/ _class_private_field_loose_key("_entitiesMapper"), // TODO: either move this to restore strategy, or restore strategy should given access to these instead of repeating the logic possibly in a different way
54
+ _areAssetsIncluded = /*#__PURE__*/ _class_private_field_loose_key("_areAssetsIncluded"), _isContentTypeIncluded = /*#__PURE__*/ _class_private_field_loose_key("_isContentTypeIncluded"), _reportInfo = /*#__PURE__*/ _class_private_field_loose_key("_reportInfo"), _validateOptions = /*#__PURE__*/ _class_private_field_loose_key("_validateOptions"), _deleteFromRestoreOptions = /*#__PURE__*/ _class_private_field_loose_key("_deleteFromRestoreOptions"), _deleteAllAssets = /*#__PURE__*/ _class_private_field_loose_key("_deleteAllAssets"), _handleAssetsBackup = /*#__PURE__*/ _class_private_field_loose_key("_handleAssetsBackup"), _removeAssetsBackup = /*#__PURE__*/ _class_private_field_loose_key("_removeAssetsBackup");
55
+ class LocalStrapiDestinationProvider {
56
+ async bootstrap(diagnostics) {
57
+ _class_private_field_loose_base(this, _diagnostics)[_diagnostics] = diagnostics;
58
+ _class_private_field_loose_base(this, _validateOptions)[_validateOptions]();
59
+ this.strapi = await this.options.getStrapi();
60
+ if (!this.strapi) {
61
+ throw new providers.ProviderInitializationError('Could not access local strapi');
62
+ }
63
+ this.strapi.db.lifecycles.disable();
64
+ this.transaction = transaction.createTransaction(this.strapi);
65
+ }
66
+ async close() {
67
+ const { autoDestroy } = this.options;
68
+ providers$1.assertValidStrapi(this.strapi);
69
+ this.transaction?.end();
70
+ this.strapi.db.lifecycles.enable();
71
+ // Basically `!== false` but more deterministic
72
+ if (autoDestroy === undefined || autoDestroy === true) {
73
+ await this.strapi?.destroy();
74
+ }
75
+ }
76
+ async rollback() {
77
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('Rolling back transaction');
78
+ await this.transaction?.rollback();
79
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('Rolled back transaction');
80
+ }
81
+ async beforeTransfer() {
82
+ if (!this.strapi) {
83
+ throw new Error('Strapi instance not found');
84
+ }
85
+ await this.transaction?.attach(async (trx)=>{
86
+ try {
87
+ if (this.options.strategy === 'restore') {
88
+ await _class_private_field_loose_base(this, _handleAssetsBackup)[_handleAssetsBackup]();
89
+ await _class_private_field_loose_base(this, _deleteAllAssets)[_deleteAllAssets](trx);
90
+ await _class_private_field_loose_base(this, _deleteFromRestoreOptions)[_deleteFromRestoreOptions]();
91
+ }
92
+ } catch (error) {
93
+ throw new Error(`restore failed ${error}`);
94
+ }
95
+ });
96
+ }
97
+ getMetadata() {
98
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('getting metadata');
99
+ providers$1.assertValidStrapi(this.strapi, 'Not able to get Schemas');
100
+ const strapiVersion = this.strapi.config.get('info.strapi');
101
+ const createdAt = new Date().toISOString();
102
+ return {
103
+ createdAt,
104
+ strapi: {
105
+ version: strapiVersion
106
+ }
107
+ };
108
+ }
109
+ getSchemas() {
110
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('getting schema');
111
+ providers$1.assertValidStrapi(this.strapi, 'Not able to get Schemas');
112
+ const schemas = schema.schemasToValidJSON({
113
+ ...this.strapi.contentTypes,
114
+ ...this.strapi.components
115
+ });
116
+ return schema.mapSchemasValues(schemas);
117
+ }
118
+ createEntitiesWriteStream() {
119
+ providers$1.assertValidStrapi(this.strapi, 'Not able to import entities');
120
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('creating entities stream');
121
+ const { strategy } = this.options;
122
+ const updateMappingTable = (type, oldID, newID)=>{
123
+ if (!_class_private_field_loose_base(this, _entitiesMapper)[_entitiesMapper][type]) {
124
+ _class_private_field_loose_base(this, _entitiesMapper)[_entitiesMapper][type] = {};
125
+ }
126
+ Object.assign(_class_private_field_loose_base(this, _entitiesMapper)[_entitiesMapper][type], {
127
+ [oldID]: newID
128
+ });
129
+ };
130
+ if (strategy === 'restore') {
131
+ return entities.createEntitiesWriteStream({
132
+ strapi: this.strapi,
133
+ updateMappingTable,
134
+ transaction: this.transaction
135
+ });
136
+ }
137
+ throw new providers.ProviderValidationError(`Invalid strategy ${this.options.strategy}`, {
138
+ check: 'strategy',
139
+ strategy: this.options.strategy,
140
+ validStrategies: VALID_CONFLICT_STRATEGIES
141
+ });
142
+ }
143
+ // TODO: Move this logic to the restore strategy
144
+ async createAssetsWriteStream() {
145
+ providers$1.assertValidStrapi(this.strapi, 'Not able to stream Assets');
146
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('creating assets write stream');
147
+ if (!_class_private_field_loose_base(this, _areAssetsIncluded)[_areAssetsIncluded]()) {
148
+ throw new providers.ProviderTransferError('Attempting to transfer assets when `assets` is not set in restore options');
149
+ }
150
+ const removeAssetsBackup = _class_private_field_loose_base(this, _removeAssetsBackup)[_removeAssetsBackup].bind(this);
151
+ const strapi = this.strapi;
152
+ const transaction = this.transaction;
153
+ const fileEntitiesMapper = _class_private_field_loose_base(this, _entitiesMapper)[_entitiesMapper]['plugin::upload.file'];
154
+ const restoreMediaEntitiesContent = _class_private_field_loose_base(this, _isContentTypeIncluded)[_isContentTypeIncluded]('plugin::upload.file');
155
+ return new stream.Writable({
156
+ objectMode: true,
157
+ async final (next) {
158
+ // Delete the backup folder
159
+ await removeAssetsBackup();
160
+ next();
161
+ },
162
+ async write (chunk, _encoding, callback) {
163
+ await transaction?.attach(async ()=>{
164
+ const uploadData = {
165
+ ...chunk.metadata,
166
+ stream: stream.Readable.from(chunk.stream),
167
+ buffer: chunk?.buffer
168
+ };
169
+ const provider = strapi.config.get('plugin::upload').provider;
170
+ const fileId = fileEntitiesMapper?.[uploadData.id];
171
+ if (!fileId) {
172
+ return callback(new Error(`File ID not found for ID: ${uploadData.id}`));
173
+ }
174
+ try {
175
+ await strapi.plugin('upload').provider.uploadStream(uploadData);
176
+ // if we're not supposed to transfer the associated entities, stop here
177
+ if (!restoreMediaEntitiesContent) {
178
+ return callback();
179
+ }
180
+ // Files formats are stored within the parent file entity
181
+ if (uploadData?.type) {
182
+ const entry = await strapi.db.query('plugin::upload.file').findOne({
183
+ where: {
184
+ id: fileId
185
+ }
186
+ });
187
+ if (!entry) {
188
+ throw new Error('file not found');
189
+ }
190
+ const specificFormat = entry?.formats?.[uploadData.type];
191
+ if (specificFormat) {
192
+ specificFormat.url = uploadData.url;
193
+ }
194
+ await strapi.db.query('plugin::upload.file').update({
195
+ where: {
196
+ id: entry.id
197
+ },
198
+ data: {
199
+ formats: entry.formats,
200
+ provider
201
+ }
202
+ });
203
+ return callback();
204
+ }
205
+ const entry = await strapi.db.query('plugin::upload.file').findOne({
206
+ where: {
207
+ id: fileId
208
+ }
209
+ });
210
+ if (!entry) {
211
+ throw new Error('file not found');
212
+ }
213
+ entry.url = uploadData.url;
214
+ await strapi.db.query('plugin::upload.file').update({
215
+ where: {
216
+ id: entry.id
217
+ },
218
+ data: {
219
+ url: entry.url,
220
+ provider
221
+ }
222
+ });
223
+ return callback();
224
+ } catch (error) {
225
+ return callback(new Error(`Error while uploading asset ${chunk.filename} ${error}`));
226
+ }
227
+ });
228
+ }
229
+ });
230
+ }
231
+ async createConfigurationWriteStream() {
232
+ providers$1.assertValidStrapi(this.strapi, 'Not able to stream Configurations');
233
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('creating configuration write stream');
234
+ const { strategy } = this.options;
235
+ if (strategy === 'restore') {
236
+ return configuration.createConfigurationWriteStream(this.strapi, this.transaction);
237
+ }
238
+ throw new providers.ProviderValidationError(`Invalid strategy ${strategy}`, {
239
+ check: 'strategy',
240
+ strategy,
241
+ validStrategies: VALID_CONFLICT_STRATEGIES
242
+ });
243
+ }
244
+ async createLinksWriteStream() {
245
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('creating links write stream');
246
+ if (!this.strapi) {
247
+ throw new Error('Not able to stream links. Strapi instance not found');
248
+ }
249
+ const { strategy } = this.options;
250
+ const mapID = (uid, id)=>_class_private_field_loose_base(this, _entitiesMapper)[_entitiesMapper][uid]?.[id];
251
+ if (strategy === 'restore') {
252
+ return links.createLinksWriteStream(mapID, this.strapi, this.transaction, this.onWarning);
253
+ }
254
+ throw new providers.ProviderValidationError(`Invalid strategy ${strategy}`, {
255
+ check: 'strategy',
256
+ strategy,
257
+ validStrategies: VALID_CONFLICT_STRATEGIES
258
+ });
259
+ }
260
+ constructor(options){
261
+ Object.defineProperty(this, _reportInfo, {
262
+ value: reportInfo
263
+ });
264
+ Object.defineProperty(this, _validateOptions, {
265
+ value: validateOptions
266
+ });
267
+ Object.defineProperty(this, _deleteFromRestoreOptions, {
268
+ value: deleteFromRestoreOptions
269
+ });
270
+ Object.defineProperty(this, _deleteAllAssets, {
271
+ value: deleteAllAssets
272
+ });
273
+ Object.defineProperty(this, _handleAssetsBackup, {
274
+ value: handleAssetsBackup
275
+ });
276
+ Object.defineProperty(this, _removeAssetsBackup, {
277
+ value: removeAssetsBackup
278
+ });
279
+ Object.defineProperty(this, _diagnostics, {
280
+ writable: true,
281
+ value: void 0
282
+ });
283
+ Object.defineProperty(this, _entitiesMapper, {
284
+ writable: true,
285
+ value: void 0
286
+ });
287
+ Object.defineProperty(this, _areAssetsIncluded, {
288
+ writable: true,
289
+ value: void 0
290
+ });
291
+ Object.defineProperty(this, _isContentTypeIncluded, {
292
+ writable: true,
293
+ value: void 0
294
+ });
295
+ this.name = 'destination::local-strapi';
296
+ this.type = 'destination';
297
+ _class_private_field_loose_base(this, _areAssetsIncluded)[_areAssetsIncluded] = ()=>{
298
+ return this.options.restore?.assets;
299
+ };
300
+ _class_private_field_loose_base(this, _isContentTypeIncluded)[_isContentTypeIncluded] = (type)=>{
301
+ const notIncluded = this.options.restore?.entities?.include && !this.options.restore?.entities?.include?.includes(type);
302
+ const excluded = this.options.restore?.entities?.exclude && this.options.restore?.entities.exclude.includes(type);
303
+ return !excluded && !notIncluded;
304
+ };
305
+ this.options = options;
306
+ _class_private_field_loose_base(this, _entitiesMapper)[_entitiesMapper] = {};
307
+ this.uploadsBackupDirectoryName = `uploads_backup_${Date.now()}`;
308
+ }
309
+ }
310
+ function reportInfo(message) {
311
+ _class_private_field_loose_base(this, _diagnostics)[_diagnostics]?.report({
312
+ details: {
313
+ createdAt: new Date(),
314
+ message,
315
+ origin: 'local-destination-provider'
316
+ },
317
+ kind: 'info'
318
+ });
319
+ }
320
+ function validateOptions() {
321
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('validating options');
322
+ if (!VALID_CONFLICT_STRATEGIES.includes(this.options.strategy)) {
323
+ throw new providers.ProviderValidationError(`Invalid strategy ${this.options.strategy}`, {
324
+ check: 'strategy',
325
+ strategy: this.options.strategy,
326
+ validStrategies: VALID_CONFLICT_STRATEGIES
327
+ });
328
+ }
329
+ // require restore options when using restore
330
+ if (this.options.strategy === 'restore' && !this.options.restore) {
331
+ throw new providers.ProviderValidationError('Missing restore options');
332
+ }
333
+ }
334
+ async function deleteFromRestoreOptions() {
335
+ providers$1.assertValidStrapi(this.strapi);
336
+ if (!this.options.restore) {
337
+ throw new providers.ProviderValidationError('Missing restore options');
338
+ }
339
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('deleting record ');
340
+ return index.deleteRecords(this.strapi, this.options.restore);
341
+ }
342
+ async function deleteAllAssets(trx) {
343
+ providers$1.assertValidStrapi(this.strapi);
344
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('deleting all assets');
345
+ // if we're not restoring files, don't touch the files
346
+ if (!_class_private_field_loose_base(this, _areAssetsIncluded)[_areAssetsIncluded]()) {
347
+ return;
348
+ }
349
+ const stream = this.strapi.db// Create a query builder instance (default type is 'select')
350
+ .queryBuilder('plugin::upload.file')// Fetch all columns
351
+ .select('*')// Attach the transaction
352
+ .transacting(trx)// Get a readable stream
353
+ .stream();
354
+ // TODO use bulk delete when exists in providers
355
+ for await (const file of stream){
356
+ await this.strapi.plugin('upload').provider.delete(file);
357
+ if (file.formats) {
358
+ for (const fileFormat of Object.values(file.formats)){
359
+ await this.strapi.plugin('upload').provider.delete(fileFormat);
360
+ }
361
+ }
362
+ }
363
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('deleted all assets');
364
+ }
365
+ async function handleAssetsBackup() {
366
+ providers$1.assertValidStrapi(this.strapi, 'Not able to create the assets backup');
367
+ // if we're not restoring assets, don't back them up because they won't be touched
368
+ if (!_class_private_field_loose_base(this, _areAssetsIncluded)[_areAssetsIncluded]()) {
369
+ return;
370
+ }
371
+ if (this.strapi.config.get('plugin::upload').provider === 'local') {
372
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('creating assets backup directory');
373
+ const assetsDirectory = path.join(this.strapi.dirs.static.public, 'uploads');
374
+ const backupDirectory = path.join(this.strapi.dirs.static.public, this.uploadsBackupDirectoryName);
375
+ try {
376
+ // Check access before attempting to do anything
377
+ await fse__namespace.access(assetsDirectory, // eslint-disable-next-line no-bitwise
378
+ fse__namespace.constants.W_OK | fse__namespace.constants.R_OK | fse__namespace.constants.F_OK);
379
+ // eslint-disable-next-line no-bitwise
380
+ await fse__namespace.access(path.join(assetsDirectory, '..'), fse__namespace.constants.W_OK | fse__namespace.constants.R_OK);
381
+ await fse__namespace.move(assetsDirectory, backupDirectory);
382
+ await fse__namespace.mkdir(assetsDirectory);
383
+ // Create a .gitkeep file to ensure the directory is not empty
384
+ await fse__namespace.outputFile(path.join(assetsDirectory, '.gitkeep'), '');
385
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo](`created assets backup directory ${backupDirectory}`);
386
+ } catch (err) {
387
+ throw new providers.ProviderTransferError('The backup folder for the assets could not be created inside the public folder. Please ensure Strapi has write permissions on the public directory', {
388
+ code: 'ASSETS_DIRECTORY_ERR'
389
+ });
390
+ }
391
+ return backupDirectory;
392
+ }
393
+ }
394
+ async function removeAssetsBackup() {
395
+ providers$1.assertValidStrapi(this.strapi, 'Not able to remove Assets');
396
+ // if we're not restoring assets, don't back them up because they won't be touched
397
+ if (!_class_private_field_loose_base(this, _areAssetsIncluded)[_areAssetsIncluded]()) {
398
+ return;
399
+ }
400
+ // TODO: this should catch all thrown errors and bubble it up to engine so it can be reported as a non-fatal diagnostic message telling the user they may need to manually delete assets
401
+ if (this.strapi.config.get('plugin::upload').provider === 'local') {
402
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('removing assets backup');
403
+ providers$1.assertValidStrapi(this.strapi);
404
+ const backupDirectory = path.join(this.strapi.dirs.static.public, this.uploadsBackupDirectoryName);
405
+ await fse__namespace.rm(backupDirectory, {
406
+ recursive: true,
407
+ force: true
408
+ });
409
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('successfully removed assets backup');
410
+ }
411
+ }
412
+ const createLocalStrapiDestinationProvider = (options)=>{
413
+ return new LocalStrapiDestinationProvider(options);
414
+ };
415
+
416
+ exports.DEFAULT_CONFLICT_STRATEGY = DEFAULT_CONFLICT_STRATEGY;
417
+ exports.VALID_CONFLICT_STRATEGIES = VALID_CONFLICT_STRATEGIES;
418
+ exports.createLocalStrapiDestinationProvider = createLocalStrapiDestinationProvider;
419
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../../src/strapi/providers/local-destination/index.ts"],"sourcesContent":["import { Writable, Readable } from 'stream';\nimport path from 'path';\nimport * as fse from 'fs-extra';\nimport type { Knex } from 'knex';\nimport type { Core, Struct } from '@strapi/types';\nimport type {\n IAsset,\n IDestinationProvider,\n IFile,\n IMetadata,\n ProviderType,\n Transaction,\n} from '../../../../types';\nimport type { IDiagnosticReporter } from '../../../utils/diagnostic';\n\nimport { restore } from './strategies';\nimport * as utils from '../../../utils';\nimport {\n ProviderInitializationError,\n ProviderTransferError,\n ProviderValidationError,\n} from '../../../errors/providers';\nimport { assertValidStrapi } from '../../../utils/providers';\n\nexport const VALID_CONFLICT_STRATEGIES = ['restore'];\nexport const DEFAULT_CONFLICT_STRATEGY = 'restore';\n\nexport interface ILocalStrapiDestinationProviderOptions {\n getStrapi(): Core.Strapi | Promise<Core.Strapi>; // return an initialized instance of Strapi\n\n autoDestroy?: boolean; // shut down the instance returned by getStrapi() at the end of the transfer\n restore?: restore.IRestoreOptions; // erase data in strapi database before transfer; required if strategy is 'restore'\n strategy: 'restore'; // conflict management strategy; only the restore strategy is available at this time\n}\n\nclass LocalStrapiDestinationProvider implements IDestinationProvider {\n name = 'destination::local-strapi';\n\n type: ProviderType = 'destination';\n\n options: ILocalStrapiDestinationProviderOptions;\n\n strapi?: Core.Strapi;\n\n transaction?: Transaction;\n\n uploadsBackupDirectoryName: string;\n\n onWarning?: ((message: string) => void) | undefined;\n\n #diagnostics?: IDiagnosticReporter;\n\n /**\n * The entities mapper is used to map old entities to their new IDs\n */\n #entitiesMapper: { [type: string]: { [id: number]: number } };\n\n constructor(options: ILocalStrapiDestinationProviderOptions) {\n this.options = options;\n this.#entitiesMapper = {};\n this.uploadsBackupDirectoryName = `uploads_backup_${Date.now()}`;\n }\n\n async bootstrap(diagnostics?: IDiagnosticReporter): Promise<void> {\n this.#diagnostics = diagnostics;\n this.#validateOptions();\n this.strapi = await this.options.getStrapi();\n if (!this.strapi) {\n throw new ProviderInitializationError('Could not access local strapi');\n }\n this.strapi.db.lifecycles.disable();\n this.transaction = utils.transaction.createTransaction(this.strapi);\n }\n\n // TODO: either move this to restore strategy, or restore strategy should given access to these instead of repeating the logic possibly in a different way\n #areAssetsIncluded = () => {\n return this.options.restore?.assets;\n };\n\n #isContentTypeIncluded = (type: string) => {\n const notIncluded =\n this.options.restore?.entities?.include &&\n !this.options.restore?.entities?.include?.includes(type);\n const excluded =\n this.options.restore?.entities?.exclude &&\n this.options.restore?.entities.exclude.includes(type);\n\n return !excluded && !notIncluded;\n };\n\n #reportInfo(message: string) {\n this.#diagnostics?.report({\n details: {\n createdAt: new Date(),\n message,\n origin: 'local-destination-provider',\n },\n kind: 'info',\n });\n }\n\n async close(): Promise<void> {\n const { autoDestroy } = this.options;\n assertValidStrapi(this.strapi);\n this.transaction?.end();\n this.strapi.db.lifecycles.enable();\n // Basically `!== false` but more deterministic\n if (autoDestroy === undefined || autoDestroy === true) {\n await this.strapi?.destroy();\n }\n }\n\n #validateOptions() {\n this.#reportInfo('validating options');\n if (!VALID_CONFLICT_STRATEGIES.includes(this.options.strategy)) {\n throw new ProviderValidationError(`Invalid strategy ${this.options.strategy}`, {\n check: 'strategy',\n strategy: this.options.strategy,\n validStrategies: VALID_CONFLICT_STRATEGIES,\n });\n }\n\n // require restore options when using restore\n if (this.options.strategy === 'restore' && !this.options.restore) {\n throw new ProviderValidationError('Missing restore options');\n }\n }\n\n async #deleteFromRestoreOptions() {\n assertValidStrapi(this.strapi);\n if (!this.options.restore) {\n throw new ProviderValidationError('Missing restore options');\n }\n this.#reportInfo('deleting record ');\n return restore.deleteRecords(this.strapi, this.options.restore);\n }\n\n async #deleteAllAssets(trx?: Knex.Transaction) {\n assertValidStrapi(this.strapi);\n this.#reportInfo('deleting all assets');\n // if we're not restoring files, don't touch the files\n if (!this.#areAssetsIncluded()) {\n return;\n }\n\n const stream: Readable = this.strapi.db\n // Create a query builder instance (default type is 'select')\n .queryBuilder('plugin::upload.file')\n // Fetch all columns\n .select('*')\n // Attach the transaction\n .transacting(trx)\n // Get a readable stream\n .stream();\n\n // TODO use bulk delete when exists in providers\n for await (const file of stream) {\n await this.strapi.plugin('upload').provider.delete(file);\n if (file.formats) {\n for (const fileFormat of Object.values(file.formats)) {\n await this.strapi.plugin('upload').provider.delete(fileFormat);\n }\n }\n }\n\n this.#reportInfo('deleted all assets');\n }\n\n async rollback() {\n this.#reportInfo('Rolling back transaction');\n await this.transaction?.rollback();\n this.#reportInfo('Rolled back transaction');\n }\n\n async beforeTransfer() {\n if (!this.strapi) {\n throw new Error('Strapi instance not found');\n }\n\n await this.transaction?.attach(async (trx) => {\n try {\n if (this.options.strategy === 'restore') {\n await this.#handleAssetsBackup();\n await this.#deleteAllAssets(trx);\n await this.#deleteFromRestoreOptions();\n }\n } catch (error) {\n throw new Error(`restore failed ${error}`);\n }\n });\n }\n\n getMetadata(): IMetadata {\n this.#reportInfo('getting metadata');\n assertValidStrapi(this.strapi, 'Not able to get Schemas');\n const strapiVersion = this.strapi.config.get<string>('info.strapi');\n const createdAt = new Date().toISOString();\n\n return {\n createdAt,\n strapi: {\n version: strapiVersion,\n },\n };\n }\n\n getSchemas(): Record<string, Struct.Schema> {\n this.#reportInfo('getting schema');\n assertValidStrapi(this.strapi, 'Not able to get Schemas');\n\n const schemas = utils.schema.schemasToValidJSON({\n ...this.strapi.contentTypes,\n ...this.strapi.components,\n });\n\n return utils.schema.mapSchemasValues(schemas);\n }\n\n createEntitiesWriteStream(): Writable {\n assertValidStrapi(this.strapi, 'Not able to import entities');\n this.#reportInfo('creating entities stream');\n const { strategy } = this.options;\n\n const updateMappingTable = (type: string, oldID: number, newID: number) => {\n if (!this.#entitiesMapper[type]) {\n this.#entitiesMapper[type] = {};\n }\n\n Object.assign(this.#entitiesMapper[type], { [oldID]: newID });\n };\n\n if (strategy === 'restore') {\n return restore.createEntitiesWriteStream({\n strapi: this.strapi,\n updateMappingTable,\n transaction: this.transaction,\n });\n }\n\n throw new ProviderValidationError(`Invalid strategy ${this.options.strategy}`, {\n check: 'strategy',\n strategy: this.options.strategy,\n validStrategies: VALID_CONFLICT_STRATEGIES,\n });\n }\n\n async #handleAssetsBackup() {\n assertValidStrapi(this.strapi, 'Not able to create the assets backup');\n\n // if we're not restoring assets, don't back them up because they won't be touched\n if (!this.#areAssetsIncluded()) {\n return;\n }\n\n if (this.strapi.config.get<{ provider: string }>('plugin::upload').provider === 'local') {\n this.#reportInfo('creating assets backup directory');\n const assetsDirectory = path.join(this.strapi.dirs.static.public, 'uploads');\n const backupDirectory = path.join(\n this.strapi.dirs.static.public,\n this.uploadsBackupDirectoryName\n );\n\n try {\n // Check access before attempting to do anything\n await fse.access(\n assetsDirectory,\n // eslint-disable-next-line no-bitwise\n fse.constants.W_OK | fse.constants.R_OK | fse.constants.F_OK\n );\n // eslint-disable-next-line no-bitwise\n await fse.access(path.join(assetsDirectory, '..'), fse.constants.W_OK | fse.constants.R_OK);\n\n await fse.move(assetsDirectory, backupDirectory);\n await fse.mkdir(assetsDirectory);\n // Create a .gitkeep file to ensure the directory is not empty\n await fse.outputFile(path.join(assetsDirectory, '.gitkeep'), '');\n this.#reportInfo(`created assets backup directory ${backupDirectory}`);\n } catch (err) {\n throw new ProviderTransferError(\n 'The backup folder for the assets could not be created inside the public folder. Please ensure Strapi has write permissions on the public directory',\n {\n code: 'ASSETS_DIRECTORY_ERR',\n }\n );\n }\n return backupDirectory;\n }\n }\n\n async #removeAssetsBackup() {\n assertValidStrapi(this.strapi, 'Not able to remove Assets');\n // if we're not restoring assets, don't back them up because they won't be touched\n if (!this.#areAssetsIncluded()) {\n return;\n }\n // TODO: this should catch all thrown errors and bubble it up to engine so it can be reported as a non-fatal diagnostic message telling the user they may need to manually delete assets\n if (this.strapi.config.get<{ provider: string }>('plugin::upload').provider === 'local') {\n this.#reportInfo('removing assets backup');\n assertValidStrapi(this.strapi);\n const backupDirectory = path.join(\n this.strapi.dirs.static.public,\n this.uploadsBackupDirectoryName\n );\n await fse.rm(backupDirectory, { recursive: true, force: true });\n this.#reportInfo('successfully removed assets backup');\n }\n }\n\n // TODO: Move this logic to the restore strategy\n async createAssetsWriteStream(): Promise<Writable> {\n assertValidStrapi(this.strapi, 'Not able to stream Assets');\n this.#reportInfo('creating assets write stream');\n if (!this.#areAssetsIncluded()) {\n throw new ProviderTransferError(\n 'Attempting to transfer assets when `assets` is not set in restore options'\n );\n }\n\n const removeAssetsBackup = this.#removeAssetsBackup.bind(this);\n const strapi = this.strapi;\n const transaction = this.transaction;\n const fileEntitiesMapper = this.#entitiesMapper['plugin::upload.file'];\n\n const restoreMediaEntitiesContent = this.#isContentTypeIncluded('plugin::upload.file');\n\n return new Writable({\n objectMode: true,\n async final(next) {\n // Delete the backup folder\n await removeAssetsBackup();\n next();\n },\n async write(chunk: IAsset, _encoding, callback) {\n await transaction?.attach(async () => {\n const uploadData = {\n ...chunk.metadata,\n stream: Readable.from(chunk.stream),\n buffer: chunk?.buffer,\n };\n\n const provider = strapi.config.get<{ provider: string }>('plugin::upload').provider;\n\n const fileId = fileEntitiesMapper?.[uploadData.id];\n if (!fileId) {\n return callback(new Error(`File ID not found for ID: ${uploadData.id}`));\n }\n\n try {\n await strapi.plugin('upload').provider.uploadStream(uploadData);\n\n // if we're not supposed to transfer the associated entities, stop here\n if (!restoreMediaEntitiesContent) {\n return callback();\n }\n\n // Files formats are stored within the parent file entity\n if (uploadData?.type) {\n const entry: IFile = await strapi.db.query('plugin::upload.file').findOne({\n where: { id: fileId },\n });\n if (!entry) {\n throw new Error('file not found');\n }\n const specificFormat = entry?.formats?.[uploadData.type];\n if (specificFormat) {\n specificFormat.url = uploadData.url;\n }\n await strapi.db.query('plugin::upload.file').update({\n where: { id: entry.id },\n data: {\n formats: entry.formats,\n provider,\n },\n });\n return callback();\n }\n\n const entry: IFile = await strapi.db.query('plugin::upload.file').findOne({\n where: { id: fileId },\n });\n if (!entry) {\n throw new Error('file not found');\n }\n entry.url = uploadData.url;\n await strapi.db.query('plugin::upload.file').update({\n where: { id: entry.id },\n data: {\n url: entry.url,\n provider,\n },\n });\n return callback();\n } catch (error) {\n return callback(new Error(`Error while uploading asset ${chunk.filename} ${error}`));\n }\n });\n },\n });\n }\n\n async createConfigurationWriteStream(): Promise<Writable> {\n assertValidStrapi(this.strapi, 'Not able to stream Configurations');\n this.#reportInfo('creating configuration write stream');\n const { strategy } = this.options;\n\n if (strategy === 'restore') {\n return restore.createConfigurationWriteStream(this.strapi, this.transaction);\n }\n\n throw new ProviderValidationError(`Invalid strategy ${strategy}`, {\n check: 'strategy',\n strategy,\n validStrategies: VALID_CONFLICT_STRATEGIES,\n });\n }\n\n async createLinksWriteStream(): Promise<Writable> {\n this.#reportInfo('creating links write stream');\n if (!this.strapi) {\n throw new Error('Not able to stream links. Strapi instance not found');\n }\n\n const { strategy } = this.options;\n const mapID = (uid: string, id: number): number | undefined => this.#entitiesMapper[uid]?.[id];\n\n if (strategy === 'restore') {\n return restore.createLinksWriteStream(mapID, this.strapi, this.transaction, this.onWarning);\n }\n\n throw new ProviderValidationError(`Invalid strategy ${strategy}`, {\n check: 'strategy',\n strategy,\n validStrategies: VALID_CONFLICT_STRATEGIES,\n });\n }\n}\n\nexport const createLocalStrapiDestinationProvider = (\n options: ILocalStrapiDestinationProviderOptions\n) => {\n return new LocalStrapiDestinationProvider(options);\n};\n"],"names":["VALID_CONFLICT_STRATEGIES","DEFAULT_CONFLICT_STRATEGY","LocalStrapiDestinationProvider","bootstrap","diagnostics","validateOptions","strapi","options","getStrapi","ProviderInitializationError","db","lifecycles","disable","transaction","utils","close","autoDestroy","assertValidStrapi","end","enable","undefined","destroy","rollback","reportInfo","beforeTransfer","Error","attach","trx","strategy","handleAssetsBackup","deleteAllAssets","deleteFromRestoreOptions","error","getMetadata","strapiVersion","config","get","createdAt","Date","toISOString","version","getSchemas","schemas","contentTypes","components","createEntitiesWriteStream","updateMappingTable","type","oldID","newID","entitiesMapper","Object","assign","restore","ProviderValidationError","check","validStrategies","createAssetsWriteStream","areAssetsIncluded","ProviderTransferError","removeAssetsBackup","bind","fileEntitiesMapper","restoreMediaEntitiesContent","isContentTypeIncluded","Writable","objectMode","final","next","write","chunk","_encoding","callback","uploadData","metadata","stream","Readable","from","buffer","provider","fileId","id","plugin","uploadStream","entry","query","findOne","where","specificFormat","formats","url","update","data","filename","createConfigurationWriteStream","createLinksWriteStream","mapID","uid","onWarning","constructor","name","assets","notIncluded","entities","include","includes","excluded","exclude","uploadsBackupDirectoryName","now","message","report","details","origin","kind","queryBuilder","select","transacting","file","delete","fileFormat","values","assetsDirectory","path","join","dirs","static","public","backupDirectory","fse","access","constants","W_OK","R_OK","F_OK","move","mkdir","outputFile","err","code","rm","recursive","force","createLocalStrapiDestinationProvider"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAwBaA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