@strapi/data-transfer 0.0.0-experimental.62ce06180fe9a772eaeb3d43d238b26644f39f7c → 0.0.0-experimental.6340da17068c3bed7fb006e7bcc554c71129e282

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 (395) hide show
  1. package/LICENSE +19 -4
  2. package/dist/directory/index.d.ts +2 -0
  3. package/dist/directory/index.d.ts.map +1 -0
  4. package/dist/directory/index.js +8 -0
  5. package/dist/directory/index.js.map +1 -0
  6. package/dist/directory/index.mjs +3 -0
  7. package/dist/directory/index.mjs.map +1 -0
  8. package/dist/directory/providers/destination/index.d.ts +38 -0
  9. package/dist/directory/providers/destination/index.d.ts.map +1 -0
  10. package/dist/directory/providers/destination/index.js +184 -0
  11. package/dist/directory/providers/destination/index.js.map +1 -0
  12. package/dist/directory/providers/destination/index.mjs +177 -0
  13. package/dist/directory/providers/destination/index.mjs.map +1 -0
  14. package/dist/directory/providers/destination/utils.d.ts +8 -0
  15. package/dist/directory/providers/destination/utils.d.ts.map +1 -0
  16. package/dist/directory/providers/destination/utils.js +62 -0
  17. package/dist/directory/providers/destination/utils.js.map +1 -0
  18. package/dist/directory/providers/destination/utils.mjs +56 -0
  19. package/dist/directory/providers/destination/utils.mjs.map +1 -0
  20. package/dist/directory/providers/index.d.ts +3 -0
  21. package/dist/directory/providers/index.d.ts.map +1 -0
  22. package/dist/directory/providers/index.js +10 -0
  23. package/dist/directory/providers/index.js.map +1 -0
  24. package/dist/directory/providers/index.mjs +3 -0
  25. package/dist/directory/providers/index.mjs.map +1 -0
  26. package/dist/directory/providers/source/index.d.ts +27 -0
  27. package/dist/directory/providers/source/index.d.ts.map +1 -0
  28. package/dist/directory/providers/source/index.js +266 -0
  29. package/dist/directory/providers/source/index.js.map +1 -0
  30. package/dist/directory/providers/source/index.mjs +259 -0
  31. package/dist/directory/providers/source/index.mjs.map +1 -0
  32. package/dist/engine/errors.js +39 -0
  33. package/dist/engine/errors.js.map +1 -0
  34. package/dist/engine/errors.mjs +34 -0
  35. package/dist/engine/errors.mjs.map +1 -0
  36. package/dist/engine/index.d.ts +2 -3
  37. package/dist/engine/index.d.ts.map +1 -1
  38. package/dist/engine/index.js +922 -0
  39. package/dist/engine/index.js.map +1 -0
  40. package/dist/engine/index.mjs +917 -0
  41. package/dist/engine/index.mjs.map +1 -0
  42. package/dist/engine/validation/provider.d.ts +2 -2
  43. package/dist/engine/validation/provider.d.ts.map +1 -1
  44. package/dist/engine/validation/provider.js +19 -0
  45. package/dist/engine/validation/provider.js.map +1 -0
  46. package/dist/engine/validation/provider.mjs +17 -0
  47. package/dist/engine/validation/provider.mjs.map +1 -0
  48. package/dist/engine/validation/schemas/index.d.ts.map +1 -1
  49. package/dist/engine/validation/schemas/index.js +59 -0
  50. package/dist/engine/validation/schemas/index.js.map +1 -0
  51. package/dist/engine/validation/schemas/index.mjs +57 -0
  52. package/dist/engine/validation/schemas/index.mjs.map +1 -0
  53. package/dist/errors/base.js +13 -0
  54. package/dist/errors/base.js.map +1 -0
  55. package/dist/errors/base.mjs +11 -0
  56. package/dist/errors/base.mjs.map +1 -0
  57. package/dist/errors/constants.d.ts +1 -1
  58. package/dist/errors/constants.d.ts.map +1 -1
  59. package/dist/errors/constants.js +9 -0
  60. package/dist/errors/constants.js.map +1 -0
  61. package/dist/errors/constants.mjs +7 -0
  62. package/dist/errors/constants.mjs.map +1 -0
  63. package/dist/errors/providers.d.ts +1 -1
  64. package/dist/errors/providers.d.ts.map +1 -1
  65. package/dist/errors/providers.js +41 -0
  66. package/dist/errors/providers.js.map +1 -0
  67. package/dist/errors/providers.mjs +36 -0
  68. package/dist/errors/providers.mjs.map +1 -0
  69. package/dist/file/index.js +8 -0
  70. package/dist/file/index.js.map +1 -0
  71. package/dist/file/index.mjs +3 -0
  72. package/dist/file/index.mjs.map +1 -0
  73. package/dist/file/providers/destination/index.d.ts +3 -5
  74. package/dist/file/providers/destination/index.d.ts.map +1 -1
  75. package/dist/file/providers/destination/index.js +254 -0
  76. package/dist/file/providers/destination/index.js.map +1 -0
  77. package/dist/file/providers/destination/index.mjs +246 -0
  78. package/dist/file/providers/destination/index.mjs.map +1 -0
  79. package/dist/file/providers/destination/utils.d.ts +0 -1
  80. package/dist/file/providers/destination/utils.d.ts.map +1 -1
  81. package/dist/file/providers/destination/utils.js +63 -0
  82. package/dist/file/providers/destination/utils.js.map +1 -0
  83. package/dist/file/providers/destination/utils.mjs +60 -0
  84. package/dist/file/providers/destination/utils.mjs.map +1 -0
  85. package/dist/file/providers/index.js +10 -0
  86. package/dist/file/providers/index.js.map +1 -0
  87. package/dist/file/providers/index.mjs +3 -0
  88. package/dist/file/providers/index.mjs.map +1 -0
  89. package/dist/file/providers/source/index.d.ts +3 -3
  90. package/dist/file/providers/source/index.d.ts.map +1 -1
  91. package/dist/file/providers/source/index.js +336 -0
  92. package/dist/file/providers/source/index.js.map +1 -0
  93. package/dist/file/providers/source/index.mjs +328 -0
  94. package/dist/file/providers/source/index.mjs.map +1 -0
  95. package/dist/file/providers/source/utils.d.ts.map +1 -1
  96. package/dist/file/providers/source/utils.js +60 -0
  97. package/dist/file/providers/source/utils.js.map +1 -0
  98. package/dist/file/providers/source/utils.mjs +52 -0
  99. package/dist/file/providers/source/utils.mjs.map +1 -0
  100. package/dist/index.d.ts +1 -0
  101. package/dist/index.d.ts.map +1 -1
  102. package/dist/index.js +15 -4408
  103. package/dist/index.js.map +1 -1
  104. package/dist/index.mjs +10 -4382
  105. package/dist/index.mjs.map +1 -1
  106. package/dist/strapi/index.js +12 -0
  107. package/dist/strapi/index.js.map +1 -0
  108. package/dist/strapi/index.mjs +7 -0
  109. package/dist/strapi/index.mjs.map +1 -0
  110. package/dist/strapi/providers/index.js +18 -0
  111. package/dist/strapi/providers/index.js.map +1 -0
  112. package/dist/strapi/providers/index.mjs +8 -0
  113. package/dist/strapi/providers/index.mjs.map +1 -0
  114. package/dist/strapi/providers/local-destination/assets-destination-writable.d.ts +26 -0
  115. package/dist/strapi/providers/local-destination/assets-destination-writable.d.ts.map +1 -0
  116. package/dist/strapi/providers/local-destination/assets-destination-writable.js +125 -0
  117. package/dist/strapi/providers/local-destination/assets-destination-writable.js.map +1 -0
  118. package/dist/strapi/providers/local-destination/assets-destination-writable.mjs +123 -0
  119. package/dist/strapi/providers/local-destination/assets-destination-writable.mjs.map +1 -0
  120. package/dist/strapi/providers/local-destination/index.d.ts +5 -3
  121. package/dist/strapi/providers/local-destination/index.d.ts.map +1 -1
  122. package/dist/strapi/providers/local-destination/index.js +362 -0
  123. package/dist/strapi/providers/local-destination/index.js.map +1 -0
  124. package/dist/strapi/providers/local-destination/index.mjs +335 -0
  125. package/dist/strapi/providers/local-destination/index.mjs.map +1 -0
  126. package/dist/strapi/providers/local-destination/strategies/restore/configuration.d.ts +1 -2
  127. package/dist/strapi/providers/local-destination/strategies/restore/configuration.d.ts.map +1 -1
  128. package/dist/strapi/providers/local-destination/strategies/restore/configuration.js +58 -0
  129. package/dist/strapi/providers/local-destination/strategies/restore/configuration.js.map +1 -0
  130. package/dist/strapi/providers/local-destination/strategies/restore/configuration.mjs +51 -0
  131. package/dist/strapi/providers/local-destination/strategies/restore/configuration.mjs.map +1 -0
  132. package/dist/strapi/providers/local-destination/strategies/restore/entities.d.ts +1 -2
  133. package/dist/strapi/providers/local-destination/strategies/restore/entities.d.ts.map +1 -1
  134. package/dist/strapi/providers/local-destination/strategies/restore/entities.js +54 -0
  135. package/dist/strapi/providers/local-destination/strategies/restore/entities.js.map +1 -0
  136. package/dist/strapi/providers/local-destination/strategies/restore/entities.mjs +52 -0
  137. package/dist/strapi/providers/local-destination/strategies/restore/entities.mjs.map +1 -0
  138. package/dist/strapi/providers/local-destination/strategies/restore/index.d.ts.map +1 -1
  139. package/dist/strapi/providers/local-destination/strategies/restore/index.js +124 -0
  140. package/dist/strapi/providers/local-destination/strategies/restore/index.js.map +1 -0
  141. package/dist/strapi/providers/local-destination/strategies/restore/index.mjs +120 -0
  142. package/dist/strapi/providers/local-destination/strategies/restore/index.mjs.map +1 -0
  143. package/dist/strapi/providers/local-destination/strategies/restore/links.d.ts +1 -2
  144. package/dist/strapi/providers/local-destination/strategies/restore/links.d.ts.map +1 -1
  145. package/dist/strapi/providers/local-destination/strategies/restore/links.js +79 -0
  146. package/dist/strapi/providers/local-destination/strategies/restore/links.js.map +1 -0
  147. package/dist/strapi/providers/local-destination/strategies/restore/links.mjs +77 -0
  148. package/dist/strapi/providers/local-destination/strategies/restore/links.mjs.map +1 -0
  149. package/dist/strapi/providers/local-source/assets.d.ts +8 -2
  150. package/dist/strapi/providers/local-source/assets.d.ts.map +1 -1
  151. package/dist/strapi/providers/local-source/assets.js +151 -0
  152. package/dist/strapi/providers/local-source/assets.js.map +1 -0
  153. package/dist/strapi/providers/local-source/assets.mjs +147 -0
  154. package/dist/strapi/providers/local-source/assets.mjs.map +1 -0
  155. package/dist/strapi/providers/local-source/configuration.d.ts +0 -1
  156. package/dist/strapi/providers/local-source/configuration.d.ts.map +1 -1
  157. package/dist/strapi/providers/local-source/configuration.js +47 -0
  158. package/dist/strapi/providers/local-source/configuration.js.map +1 -0
  159. package/dist/strapi/providers/local-source/configuration.mjs +45 -0
  160. package/dist/strapi/providers/local-source/configuration.mjs.map +1 -0
  161. package/dist/strapi/providers/local-source/entities.d.ts +3 -2
  162. package/dist/strapi/providers/local-source/entities.d.ts.map +1 -1
  163. package/dist/strapi/providers/local-source/entities.js +66 -0
  164. package/dist/strapi/providers/local-source/entities.js.map +1 -0
  165. package/dist/strapi/providers/local-source/entities.mjs +63 -0
  166. package/dist/strapi/providers/local-source/entities.mjs.map +1 -0
  167. package/dist/strapi/providers/local-source/estimate-asset-totals.d.ts +11 -0
  168. package/dist/strapi/providers/local-source/estimate-asset-totals.d.ts.map +1 -0
  169. package/dist/strapi/providers/local-source/estimate-asset-totals.js +130 -0
  170. package/dist/strapi/providers/local-source/estimate-asset-totals.js.map +1 -0
  171. package/dist/strapi/providers/local-source/estimate-asset-totals.mjs +128 -0
  172. package/dist/strapi/providers/local-source/estimate-asset-totals.mjs.map +1 -0
  173. package/dist/strapi/providers/local-source/index.d.ts +6 -4
  174. package/dist/strapi/providers/local-source/index.d.ts.map +1 -1
  175. package/dist/strapi/providers/local-source/index.js +186 -0
  176. package/dist/strapi/providers/local-source/index.js.map +1 -0
  177. package/dist/strapi/providers/local-source/index.mjs +183 -0
  178. package/dist/strapi/providers/local-source/index.mjs.map +1 -0
  179. package/dist/strapi/providers/local-source/links.d.ts +0 -1
  180. package/dist/strapi/providers/local-source/links.d.ts.map +1 -1
  181. package/dist/strapi/providers/local-source/links.js +26 -0
  182. package/dist/strapi/providers/local-source/links.js.map +1 -0
  183. package/dist/strapi/providers/local-source/links.mjs +24 -0
  184. package/dist/strapi/providers/local-source/links.mjs.map +1 -0
  185. package/dist/strapi/providers/remote-destination/index.d.ts +13 -5
  186. package/dist/strapi/providers/remote-destination/index.d.ts.map +1 -1
  187. package/dist/strapi/providers/remote-destination/index.js +482 -0
  188. package/dist/strapi/providers/remote-destination/index.js.map +1 -0
  189. package/dist/strapi/providers/remote-destination/index.mjs +480 -0
  190. package/dist/strapi/providers/remote-destination/index.mjs.map +1 -0
  191. package/dist/strapi/providers/remote-source/index.d.ts +11 -6
  192. package/dist/strapi/providers/remote-source/index.d.ts.map +1 -1
  193. package/dist/strapi/providers/remote-source/index.js +538 -0
  194. package/dist/strapi/providers/remote-source/index.js.map +1 -0
  195. package/dist/strapi/providers/remote-source/index.mjs +536 -0
  196. package/dist/strapi/providers/remote-source/index.mjs.map +1 -0
  197. package/dist/strapi/providers/utils.d.ts +22 -16
  198. package/dist/strapi/providers/utils.d.ts.map +1 -1
  199. package/dist/strapi/providers/utils.js +178 -0
  200. package/dist/strapi/providers/utils.js.map +1 -0
  201. package/dist/strapi/providers/utils.mjs +174 -0
  202. package/dist/strapi/providers/utils.mjs.map +1 -0
  203. package/dist/strapi/queries/entity.d.ts.map +1 -1
  204. package/dist/strapi/queries/entity.js +125 -0
  205. package/dist/strapi/queries/entity.js.map +1 -0
  206. package/dist/strapi/queries/entity.mjs +123 -0
  207. package/dist/strapi/queries/entity.mjs.map +1 -0
  208. package/dist/strapi/queries/index.js +10 -0
  209. package/dist/strapi/queries/index.js.map +1 -0
  210. package/dist/strapi/queries/index.mjs +5 -0
  211. package/dist/strapi/queries/index.mjs.map +1 -0
  212. package/dist/strapi/queries/link.d.ts +1 -1
  213. package/dist/strapi/queries/link.d.ts.map +1 -1
  214. package/dist/strapi/queries/link.js +298 -0
  215. package/dist/strapi/queries/link.js.map +1 -0
  216. package/dist/strapi/queries/link.mjs +295 -0
  217. package/dist/strapi/queries/link.mjs.map +1 -0
  218. package/dist/strapi/remote/constants.d.ts.map +1 -1
  219. package/dist/strapi/remote/constants.js +11 -0
  220. package/dist/strapi/remote/constants.js.map +1 -0
  221. package/dist/strapi/remote/constants.mjs +8 -0
  222. package/dist/strapi/remote/constants.mjs.map +1 -0
  223. package/dist/strapi/remote/flows/default.d.ts.map +1 -1
  224. package/dist/strapi/remote/flows/default.js +43 -0
  225. package/dist/strapi/remote/flows/default.js.map +1 -0
  226. package/dist/strapi/remote/flows/default.mjs +41 -0
  227. package/dist/strapi/remote/flows/default.mjs.map +1 -0
  228. package/dist/strapi/remote/flows/index.d.ts +1 -1
  229. package/dist/strapi/remote/flows/index.d.ts.map +1 -1
  230. package/dist/strapi/remote/flows/index.js +54 -0
  231. package/dist/strapi/remote/flows/index.js.map +1 -0
  232. package/dist/strapi/remote/flows/index.mjs +52 -0
  233. package/dist/strapi/remote/flows/index.mjs.map +1 -0
  234. package/dist/strapi/remote/handlers/abstract.d.ts +4 -1
  235. package/dist/strapi/remote/handlers/abstract.d.ts.map +1 -1
  236. package/dist/strapi/remote/handlers/constants.js +10 -0
  237. package/dist/strapi/remote/handlers/constants.js.map +1 -0
  238. package/dist/strapi/remote/handlers/constants.mjs +8 -0
  239. package/dist/strapi/remote/handlers/constants.mjs.map +1 -0
  240. package/dist/strapi/remote/handlers/index.js +12 -0
  241. package/dist/strapi/remote/handlers/index.js.map +1 -0
  242. package/dist/strapi/remote/handlers/index.mjs +4 -0
  243. package/dist/strapi/remote/handlers/index.mjs.map +1 -0
  244. package/dist/strapi/remote/handlers/pull.d.ts +2 -3
  245. package/dist/strapi/remote/handlers/pull.d.ts.map +1 -1
  246. package/dist/strapi/remote/handlers/pull.js +369 -0
  247. package/dist/strapi/remote/handlers/pull.js.map +1 -0
  248. package/dist/strapi/remote/handlers/pull.mjs +367 -0
  249. package/dist/strapi/remote/handlers/pull.mjs.map +1 -0
  250. package/dist/strapi/remote/handlers/push.d.ts +16 -5
  251. package/dist/strapi/remote/handlers/push.d.ts.map +1 -1
  252. package/dist/strapi/remote/handlers/push.js +454 -0
  253. package/dist/strapi/remote/handlers/push.js.map +1 -0
  254. package/dist/strapi/remote/handlers/push.mjs +452 -0
  255. package/dist/strapi/remote/handlers/push.mjs.map +1 -0
  256. package/dist/strapi/remote/handlers/utils.d.ts +1 -2
  257. package/dist/strapi/remote/handlers/utils.d.ts.map +1 -1
  258. package/dist/strapi/remote/handlers/utils.js +318 -0
  259. package/dist/strapi/remote/handlers/utils.js.map +1 -0
  260. package/dist/strapi/remote/handlers/utils.mjs +312 -0
  261. package/dist/strapi/remote/handlers/utils.mjs.map +1 -0
  262. package/dist/strapi/remote/index.js +10 -0
  263. package/dist/strapi/remote/index.js.map +1 -0
  264. package/dist/strapi/remote/index.mjs +5 -0
  265. package/dist/strapi/remote/index.mjs.map +1 -0
  266. package/dist/strapi/utils/project-settings-logos.d.ts +29 -0
  267. package/dist/strapi/utils/project-settings-logos.d.ts.map +1 -0
  268. package/dist/strapi/utils/project-settings-logos.js +174 -0
  269. package/dist/strapi/utils/project-settings-logos.js.map +1 -0
  270. package/dist/strapi/utils/project-settings-logos.mjs +169 -0
  271. package/dist/strapi/utils/project-settings-logos.mjs.map +1 -0
  272. package/dist/types/common-entities.d.ts +149 -0
  273. package/dist/types/common-entities.d.ts.map +1 -0
  274. package/dist/types/encryption.d.ts +13 -0
  275. package/dist/types/encryption.d.ts.map +1 -0
  276. package/dist/types/index.d.ts +7 -0
  277. package/dist/types/index.d.ts.map +1 -0
  278. package/dist/types/providers.d.ts +49 -0
  279. package/dist/types/providers.d.ts.map +1 -0
  280. package/dist/types/remote/index.d.ts +2 -0
  281. package/dist/types/remote/index.d.ts.map +1 -0
  282. package/dist/types/remote/protocol/auth.d.ts +5 -0
  283. package/dist/types/remote/protocol/auth.d.ts.map +1 -0
  284. package/dist/types/remote/protocol/client/commands.d.ts +37 -0
  285. package/dist/types/remote/protocol/client/commands.d.ts.map +1 -0
  286. package/dist/types/remote/protocol/client/index.d.ts +9 -0
  287. package/dist/types/remote/protocol/client/index.d.ts.map +1 -0
  288. package/dist/types/remote/protocol/client/transfer/action.d.ts +5 -0
  289. package/dist/types/remote/protocol/client/transfer/action.d.ts.map +1 -0
  290. package/dist/types/remote/protocol/client/transfer/index.d.ts +12 -0
  291. package/dist/types/remote/protocol/client/transfer/index.d.ts.map +1 -0
  292. package/dist/types/remote/protocol/client/transfer/pull.d.ts +25 -0
  293. package/dist/types/remote/protocol/client/transfer/pull.d.ts.map +1 -0
  294. package/dist/types/remote/protocol/client/transfer/push.d.ts +29 -0
  295. package/dist/types/remote/protocol/client/transfer/push.d.ts.map +1 -0
  296. package/dist/types/remote/protocol/client/transfer/utils.d.ts +47 -0
  297. package/dist/types/remote/protocol/client/transfer/utils.d.ts.map +1 -0
  298. package/dist/types/remote/protocol/index.d.ts +4 -0
  299. package/dist/types/remote/protocol/index.d.ts.map +1 -0
  300. package/dist/types/remote/protocol/server/error.d.ts +18 -0
  301. package/dist/types/remote/protocol/server/error.d.ts.map +1 -0
  302. package/dist/types/remote/protocol/server/index.d.ts +3 -0
  303. package/dist/types/remote/protocol/server/index.d.ts.map +1 -0
  304. package/dist/types/remote/protocol/server/messaging.d.ts +37 -0
  305. package/dist/types/remote/protocol/server/messaging.d.ts.map +1 -0
  306. package/dist/types/transfer-engine.d.ts +148 -0
  307. package/dist/types/transfer-engine.d.ts.map +1 -0
  308. package/dist/types/utils.d.ts +82 -0
  309. package/dist/types/utils.d.ts.map +1 -0
  310. package/dist/utils/components.d.ts +23 -3
  311. package/dist/utils/components.d.ts.map +1 -1
  312. package/dist/utils/components.js +230 -0
  313. package/dist/utils/components.js.map +1 -0
  314. package/dist/utils/components.mjs +219 -0
  315. package/dist/utils/components.mjs.map +1 -0
  316. package/dist/{engine → utils}/diagnostic.d.ts +1 -0
  317. package/dist/utils/diagnostic.d.ts.map +1 -0
  318. package/dist/utils/diagnostic.js +51 -0
  319. package/dist/utils/diagnostic.js.map +1 -0
  320. package/dist/utils/diagnostic.mjs +49 -0
  321. package/dist/utils/diagnostic.mjs.map +1 -0
  322. package/dist/utils/encryption/decrypt.d.ts +6 -5
  323. package/dist/utils/encryption/decrypt.d.ts.map +1 -1
  324. package/dist/utils/encryption/decrypt.js +47 -0
  325. package/dist/utils/encryption/decrypt.js.map +1 -0
  326. package/dist/utils/encryption/decrypt.mjs +45 -0
  327. package/dist/utils/encryption/decrypt.mjs.map +1 -0
  328. package/dist/utils/encryption/encrypt.d.ts +6 -5
  329. package/dist/utils/encryption/encrypt.d.ts.map +1 -1
  330. package/dist/utils/encryption/encrypt.js +47 -0
  331. package/dist/utils/encryption/encrypt.js.map +1 -0
  332. package/dist/utils/encryption/encrypt.mjs +45 -0
  333. package/dist/utils/encryption/encrypt.mjs.map +1 -0
  334. package/dist/utils/encryption/index.js +10 -0
  335. package/dist/utils/encryption/index.js.map +1 -0
  336. package/dist/utils/encryption/index.mjs +3 -0
  337. package/dist/utils/encryption/index.mjs.map +1 -0
  338. package/dist/utils/index.d.ts +3 -0
  339. package/dist/utils/index.d.ts.map +1 -1
  340. package/dist/utils/index.js +28 -0
  341. package/dist/utils/index.js.map +1 -0
  342. package/dist/utils/index.mjs +17 -0
  343. package/dist/utils/index.mjs.map +1 -0
  344. package/dist/utils/json.d.ts.map +1 -1
  345. package/dist/utils/json.js +96 -0
  346. package/dist/utils/json.js.map +1 -0
  347. package/dist/utils/json.mjs +94 -0
  348. package/dist/utils/json.mjs.map +1 -0
  349. package/dist/utils/middleware.d.ts +1 -1
  350. package/dist/utils/middleware.d.ts.map +1 -1
  351. package/dist/utils/middleware.js +14 -0
  352. package/dist/utils/middleware.js.map +1 -0
  353. package/dist/utils/middleware.mjs +12 -0
  354. package/dist/utils/middleware.mjs.map +1 -0
  355. package/dist/utils/providers.js +12 -0
  356. package/dist/utils/providers.js.map +1 -0
  357. package/dist/utils/providers.mjs +10 -0
  358. package/dist/utils/providers.mjs.map +1 -0
  359. package/dist/utils/schema.d.ts.map +1 -1
  360. package/dist/utils/schema.js +32 -0
  361. package/dist/utils/schema.js.map +1 -0
  362. package/dist/utils/schema.mjs +29 -0
  363. package/dist/utils/schema.mjs.map +1 -0
  364. package/dist/utils/stream.d.ts +0 -1
  365. package/dist/utils/stream.d.ts.map +1 -1
  366. package/dist/utils/stream.js +96 -0
  367. package/dist/utils/stream.js.map +1 -0
  368. package/dist/utils/stream.mjs +92 -0
  369. package/dist/utils/stream.mjs.map +1 -0
  370. package/dist/utils/transaction.d.ts +1 -1
  371. package/dist/utils/transaction.d.ts.map +1 -1
  372. package/dist/utils/transaction.js +93 -0
  373. package/dist/utils/transaction.js.map +1 -0
  374. package/dist/utils/transaction.mjs +91 -0
  375. package/dist/utils/transaction.mjs.map +1 -0
  376. package/dist/utils/transfer-asset-chunk.d.ts +61 -0
  377. package/dist/utils/transfer-asset-chunk.d.ts.map +1 -0
  378. package/dist/utils/transfer-asset-chunk.js +118 -0
  379. package/dist/utils/transfer-asset-chunk.js.map +1 -0
  380. package/dist/utils/transfer-asset-chunk.mjs +112 -0
  381. package/dist/utils/transfer-asset-chunk.mjs.map +1 -0
  382. package/dist/utils/transfer-websocket-json.d.ts +24 -0
  383. package/dist/utils/transfer-websocket-json.d.ts.map +1 -0
  384. package/dist/utils/transfer-websocket-json.js +67 -0
  385. package/dist/utils/transfer-websocket-json.js.map +1 -0
  386. package/dist/utils/transfer-websocket-json.mjs +63 -0
  387. package/dist/utils/transfer-websocket-json.mjs.map +1 -0
  388. package/dist/utils/writable-async-write.d.ts +16 -0
  389. package/dist/utils/writable-async-write.d.ts.map +1 -0
  390. package/dist/utils/writable-async-write.js +61 -0
  391. package/dist/utils/writable-async-write.js.map +1 -0
  392. package/dist/utils/writable-async-write.mjs +59 -0
  393. package/dist/utils/writable-async-write.mjs.map +1 -0
  394. package/package.json +40 -26
  395. package/dist/engine/diagnostic.d.ts.map +0 -1
@@ -0,0 +1,335 @@
1
+ import path from 'path';
2
+ import * as fs from 'fs-extra';
3
+ import { createAssetsDestinationWritable } from './assets-destination-writable.mjs';
4
+ import { deleteRecords } from './strategies/restore/index.mjs';
5
+ import 'crypto';
6
+ import 'node:events';
7
+ import 'node:stream/promises';
8
+ import 'stream';
9
+ import 'lodash/fp';
10
+ import { schemasToValidJSON, mapSchemasValues } from '../../../utils/schema.mjs';
11
+ import { createTransaction } from '../../../utils/transaction.mjs';
12
+ import 'events';
13
+ import { ProviderInitializationError, ProviderValidationError, ProviderTransferError } from '../../../errors/providers.mjs';
14
+ import { assertValidStrapi } from '../../../utils/providers.mjs';
15
+ import { createEntitiesWriteStream } from './strategies/restore/entities.mjs';
16
+ import { createConfigurationWriteStream } from './strategies/restore/configuration.mjs';
17
+ import { createLinksWriteStream } from './strategies/restore/links.mjs';
18
+
19
+ function _class_private_field_loose_base(receiver, privateKey) {
20
+ if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) {
21
+ throw new TypeError("attempted to use private field on non-instance");
22
+ }
23
+ return receiver;
24
+ }
25
+ var id = 0;
26
+ function _class_private_field_loose_key(name) {
27
+ return "__private_" + id++ + "_" + name;
28
+ }
29
+ const VALID_CONFLICT_STRATEGIES = [
30
+ 'restore'
31
+ ];
32
+ const DEFAULT_CONFLICT_STRATEGY = 'restore';
33
+ var _diagnostics = /*#__PURE__*/ _class_private_field_loose_key("_diagnostics"), /**
34
+ * The entities mapper is used to map old entities to their new IDs
35
+ */ _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
36
+ _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");
37
+ class LocalStrapiDestinationProvider {
38
+ async bootstrap(diagnostics) {
39
+ _class_private_field_loose_base(this, _diagnostics)[_diagnostics] = diagnostics;
40
+ _class_private_field_loose_base(this, _validateOptions)[_validateOptions]();
41
+ this.strapi = await this.options.getStrapi();
42
+ if (!this.strapi) {
43
+ throw new ProviderInitializationError('Could not access local strapi');
44
+ }
45
+ this.strapi.db.lifecycles.disable();
46
+ this.transaction = createTransaction(this.strapi);
47
+ }
48
+ async close() {
49
+ const { autoDestroy } = this.options;
50
+ assertValidStrapi(this.strapi);
51
+ this.transaction?.end();
52
+ this.strapi.db.lifecycles.enable();
53
+ // Basically `!== false` but more deterministic
54
+ if (autoDestroy === undefined || autoDestroy === true) {
55
+ await this.strapi?.destroy();
56
+ }
57
+ }
58
+ async rollback() {
59
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('Rolling back transaction');
60
+ await this.transaction?.rollback();
61
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('Rolled back transaction');
62
+ }
63
+ async beforeTransfer() {
64
+ if (!this.strapi) {
65
+ throw new Error('Strapi instance not found');
66
+ }
67
+ this.options.onTransferPhase?.('Local: preparing destination for restore…');
68
+ await this.transaction?.attach(async (trx)=>{
69
+ try {
70
+ if (this.options.strategy === 'restore') {
71
+ if (_class_private_field_loose_base(this, _areAssetsIncluded)[_areAssetsIncluded]()) {
72
+ this.options.onTransferPhase?.('Local: backing up existing upload folder…');
73
+ }
74
+ await _class_private_field_loose_base(this, _handleAssetsBackup)[_handleAssetsBackup]();
75
+ if (_class_private_field_loose_base(this, _areAssetsIncluded)[_areAssetsIncluded]()) {
76
+ this.options.onTransferPhase?.('Local: deleting existing media files from disk…');
77
+ }
78
+ await _class_private_field_loose_base(this, _deleteAllAssets)[_deleteAllAssets](trx);
79
+ this.options.onTransferPhase?.('Local: clearing database content for restore…');
80
+ await _class_private_field_loose_base(this, _deleteFromRestoreOptions)[_deleteFromRestoreOptions]();
81
+ }
82
+ } catch (error) {
83
+ throw new Error(`restore failed ${error}`);
84
+ }
85
+ });
86
+ }
87
+ getMetadata() {
88
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('getting metadata');
89
+ assertValidStrapi(this.strapi, 'Not able to get Schemas');
90
+ const strapiVersion = this.strapi.config.get('info.strapi');
91
+ const createdAt = new Date().toISOString();
92
+ return {
93
+ createdAt,
94
+ strapi: {
95
+ version: strapiVersion
96
+ }
97
+ };
98
+ }
99
+ getSchemas() {
100
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('getting schema');
101
+ assertValidStrapi(this.strapi, 'Not able to get Schemas');
102
+ const schemas = schemasToValidJSON({
103
+ ...this.strapi.contentTypes,
104
+ ...this.strapi.components
105
+ });
106
+ return mapSchemasValues(schemas);
107
+ }
108
+ createEntitiesWriteStream() {
109
+ assertValidStrapi(this.strapi, 'Not able to import entities');
110
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('creating entities stream');
111
+ const { strategy } = this.options;
112
+ const updateMappingTable = (type, oldID, newID)=>{
113
+ if (!_class_private_field_loose_base(this, _entitiesMapper)[_entitiesMapper][type]) {
114
+ _class_private_field_loose_base(this, _entitiesMapper)[_entitiesMapper][type] = {};
115
+ }
116
+ Object.assign(_class_private_field_loose_base(this, _entitiesMapper)[_entitiesMapper][type], {
117
+ [oldID]: newID
118
+ });
119
+ };
120
+ if (strategy === 'restore') {
121
+ return createEntitiesWriteStream({
122
+ strapi: this.strapi,
123
+ updateMappingTable,
124
+ transaction: this.transaction
125
+ });
126
+ }
127
+ throw new ProviderValidationError(`Invalid strategy ${this.options.strategy}`, {
128
+ check: 'strategy',
129
+ strategy: this.options.strategy,
130
+ validStrategies: VALID_CONFLICT_STRATEGIES
131
+ });
132
+ }
133
+ // TODO: Move this logic to the restore strategy
134
+ async createAssetsWriteStream() {
135
+ assertValidStrapi(this.strapi, 'Not able to stream Assets');
136
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('creating assets write stream');
137
+ if (!_class_private_field_loose_base(this, _areAssetsIncluded)[_areAssetsIncluded]()) {
138
+ throw new ProviderTransferError('Attempting to transfer assets when `assets` is not set in restore options');
139
+ }
140
+ const fileEntitiesMapper = _class_private_field_loose_base(this, _entitiesMapper)[_entitiesMapper]['plugin::upload.file'];
141
+ return createAssetsDestinationWritable({
142
+ strapi: this.strapi,
143
+ transaction: this.transaction,
144
+ resolveUploadFileId: (metadata)=>fileEntitiesMapper?.[metadata.id],
145
+ restoreMediaEntitiesContent: _class_private_field_loose_base(this, _isContentTypeIncluded)[_isContentTypeIncluded]('plugin::upload.file'),
146
+ removeAssetsBackup: _class_private_field_loose_base(this, _removeAssetsBackup)[_removeAssetsBackup].bind(this)
147
+ });
148
+ }
149
+ async createConfigurationWriteStream() {
150
+ assertValidStrapi(this.strapi, 'Not able to stream Configurations');
151
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('creating configuration write stream');
152
+ const { strategy } = this.options;
153
+ if (strategy === 'restore') {
154
+ return createConfigurationWriteStream(this.strapi, this.transaction);
155
+ }
156
+ throw new ProviderValidationError(`Invalid strategy ${strategy}`, {
157
+ check: 'strategy',
158
+ strategy,
159
+ validStrategies: VALID_CONFLICT_STRATEGIES
160
+ });
161
+ }
162
+ async createLinksWriteStream() {
163
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('creating links write stream');
164
+ if (!this.strapi) {
165
+ throw new Error('Not able to stream links. Strapi instance not found');
166
+ }
167
+ const { strategy } = this.options;
168
+ const mapID = (uid, id)=>_class_private_field_loose_base(this, _entitiesMapper)[_entitiesMapper][uid]?.[id];
169
+ if (strategy === 'restore') {
170
+ return createLinksWriteStream(mapID, this.strapi, this.transaction, this.onWarning);
171
+ }
172
+ throw new ProviderValidationError(`Invalid strategy ${strategy}`, {
173
+ check: 'strategy',
174
+ strategy,
175
+ validStrategies: VALID_CONFLICT_STRATEGIES
176
+ });
177
+ }
178
+ constructor(options){
179
+ Object.defineProperty(this, _reportInfo, {
180
+ value: reportInfo
181
+ });
182
+ Object.defineProperty(this, _validateOptions, {
183
+ value: validateOptions
184
+ });
185
+ Object.defineProperty(this, _deleteFromRestoreOptions, {
186
+ value: deleteFromRestoreOptions
187
+ });
188
+ Object.defineProperty(this, _deleteAllAssets, {
189
+ value: deleteAllAssets
190
+ });
191
+ Object.defineProperty(this, _handleAssetsBackup, {
192
+ value: handleAssetsBackup
193
+ });
194
+ Object.defineProperty(this, _removeAssetsBackup, {
195
+ value: removeAssetsBackup
196
+ });
197
+ Object.defineProperty(this, _diagnostics, {
198
+ writable: true,
199
+ value: void 0
200
+ });
201
+ Object.defineProperty(this, _entitiesMapper, {
202
+ writable: true,
203
+ value: void 0
204
+ });
205
+ Object.defineProperty(this, _areAssetsIncluded, {
206
+ writable: true,
207
+ value: void 0
208
+ });
209
+ Object.defineProperty(this, _isContentTypeIncluded, {
210
+ writable: true,
211
+ value: void 0
212
+ });
213
+ this.name = 'destination::local-strapi';
214
+ this.type = 'destination';
215
+ _class_private_field_loose_base(this, _areAssetsIncluded)[_areAssetsIncluded] = ()=>{
216
+ return this.options.restore?.assets;
217
+ };
218
+ _class_private_field_loose_base(this, _isContentTypeIncluded)[_isContentTypeIncluded] = (type)=>{
219
+ const notIncluded = this.options.restore?.entities?.include && !this.options.restore?.entities?.include?.includes(type);
220
+ const excluded = this.options.restore?.entities?.exclude && this.options.restore?.entities.exclude.includes(type);
221
+ return !excluded && !notIncluded;
222
+ };
223
+ this.options = options;
224
+ _class_private_field_loose_base(this, _entitiesMapper)[_entitiesMapper] = {};
225
+ this.uploadsBackupDirectoryName = `uploads_backup_${Date.now()}`;
226
+ }
227
+ }
228
+ function reportInfo(message) {
229
+ _class_private_field_loose_base(this, _diagnostics)[_diagnostics]?.report({
230
+ details: {
231
+ createdAt: new Date(),
232
+ message,
233
+ origin: 'local-destination-provider'
234
+ },
235
+ kind: 'info'
236
+ });
237
+ }
238
+ function validateOptions() {
239
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('validating options');
240
+ if (!VALID_CONFLICT_STRATEGIES.includes(this.options.strategy)) {
241
+ throw new ProviderValidationError(`Invalid strategy ${this.options.strategy}`, {
242
+ check: 'strategy',
243
+ strategy: this.options.strategy,
244
+ validStrategies: VALID_CONFLICT_STRATEGIES
245
+ });
246
+ }
247
+ // require restore options when using restore
248
+ if (this.options.strategy === 'restore' && !this.options.restore) {
249
+ throw new ProviderValidationError('Missing restore options');
250
+ }
251
+ }
252
+ async function deleteFromRestoreOptions() {
253
+ assertValidStrapi(this.strapi);
254
+ if (!this.options.restore) {
255
+ throw new ProviderValidationError('Missing restore options');
256
+ }
257
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('deleting record ');
258
+ return deleteRecords(this.strapi, this.options.restore);
259
+ }
260
+ async function deleteAllAssets(trx) {
261
+ assertValidStrapi(this.strapi);
262
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('deleting all assets');
263
+ // if we're not restoring files, don't touch the files
264
+ if (!_class_private_field_loose_base(this, _areAssetsIncluded)[_areAssetsIncluded]()) {
265
+ return;
266
+ }
267
+ const stream = this.strapi.db// Create a query builder instance (default type is 'select')
268
+ .queryBuilder('plugin::upload.file')// Fetch all columns
269
+ .select('*')// Attach the transaction
270
+ .transacting(trx)// Get a readable stream
271
+ .stream();
272
+ // TODO use bulk delete when exists in providers
273
+ for await (const file of stream){
274
+ await this.strapi.plugin('upload').provider.delete(file);
275
+ if (file.formats) {
276
+ for (const fileFormat of Object.values(file.formats)){
277
+ await this.strapi.plugin('upload').provider.delete(fileFormat);
278
+ }
279
+ }
280
+ }
281
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('deleted all assets');
282
+ }
283
+ async function handleAssetsBackup() {
284
+ assertValidStrapi(this.strapi, 'Not able to create the assets backup');
285
+ // if we're not restoring assets, don't back them up because they won't be touched
286
+ if (!_class_private_field_loose_base(this, _areAssetsIncluded)[_areAssetsIncluded]()) {
287
+ return;
288
+ }
289
+ if (this.strapi.config.get('plugin::upload').provider === 'local') {
290
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('creating assets backup directory');
291
+ const assetsDirectory = path.join(this.strapi.dirs.static.public, 'uploads');
292
+ const backupDirectory = path.join(this.strapi.dirs.static.public, this.uploadsBackupDirectoryName);
293
+ try {
294
+ // Check access before attempting to do anything
295
+ await fs.access(assetsDirectory, // eslint-disable-next-line no-bitwise
296
+ fs.constants.W_OK | fs.constants.R_OK | fs.constants.F_OK);
297
+ // eslint-disable-next-line no-bitwise
298
+ await fs.access(path.join(assetsDirectory, '..'), fs.constants.W_OK | fs.constants.R_OK);
299
+ await fs.move(assetsDirectory, backupDirectory);
300
+ await fs.mkdir(assetsDirectory);
301
+ // Create a .gitkeep file to ensure the directory is not empty
302
+ await fs.outputFile(path.join(assetsDirectory, '.gitkeep'), '');
303
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo](`created assets backup directory ${backupDirectory}`);
304
+ } catch (err) {
305
+ throw new 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', {
306
+ code: 'ASSETS_DIRECTORY_ERR'
307
+ });
308
+ }
309
+ return backupDirectory;
310
+ }
311
+ }
312
+ async function removeAssetsBackup() {
313
+ assertValidStrapi(this.strapi, 'Not able to remove Assets');
314
+ // if we're not restoring assets, don't back them up because they won't be touched
315
+ if (!_class_private_field_loose_base(this, _areAssetsIncluded)[_areAssetsIncluded]()) {
316
+ return;
317
+ }
318
+ // 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
319
+ if (this.strapi.config.get('plugin::upload').provider === 'local') {
320
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('removing assets backup');
321
+ assertValidStrapi(this.strapi);
322
+ const backupDirectory = path.join(this.strapi.dirs.static.public, this.uploadsBackupDirectoryName);
323
+ await fs.rm(backupDirectory, {
324
+ recursive: true,
325
+ force: true
326
+ });
327
+ _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('successfully removed assets backup');
328
+ }
329
+ }
330
+ const createLocalStrapiDestinationProvider = (options)=>{
331
+ return new LocalStrapiDestinationProvider(options);
332
+ };
333
+
334
+ export { DEFAULT_CONFLICT_STRATEGY, VALID_CONFLICT_STRATEGIES, createLocalStrapiDestinationProvider };
335
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","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 { IDestinationProvider, IMetadata, ProviderType, Transaction } from '../../../types';\nimport type { IDiagnosticReporter } from '../../../utils/diagnostic';\n\nimport { createAssetsDestinationWritable } from './assets-destination-writable';\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 /** CLI / UI: human-readable progress during {@link beforeTransfer} (restore prep). */\n onTransferPhase?: (message: string) => void;\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 this.options.onTransferPhase?.('Local: preparing destination for restore…');\n\n await this.transaction?.attach(async (trx) => {\n try {\n if (this.options.strategy === 'restore') {\n if (this.#areAssetsIncluded()) {\n this.options.onTransferPhase?.('Local: backing up existing upload folder…');\n }\n await this.#handleAssetsBackup();\n if (this.#areAssetsIncluded()) {\n this.options.onTransferPhase?.('Local: deleting existing media files from disk…');\n }\n await this.#deleteAllAssets(trx);\n this.options.onTransferPhase?.('Local: clearing database content for restore…');\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 fileEntitiesMapper = this.#entitiesMapper['plugin::upload.file'];\n\n return createAssetsDestinationWritable({\n strapi: this.strapi,\n transaction: this.transaction!,\n resolveUploadFileId: (metadata) => fileEntitiesMapper?.[metadata.id],\n restoreMediaEntitiesContent: this.#isContentTypeIncluded('plugin::upload.file'),\n removeAssetsBackup: this.#removeAssetsBackup.bind(this),\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","strapi","options","getStrapi","ProviderInitializationError","db","lifecycles","disable","transaction","utils","close","autoDestroy","assertValidStrapi","end","enable","undefined","destroy","rollback","beforeTransfer","Error","onTransferPhase","attach","trx","strategy","error","getMetadata","strapiVersion","config","get","createdAt","Date","toISOString","version","getSchemas","schemas","contentTypes","components","createEntitiesWriteStream","updateMappingTable","type","oldID","newID","Object","assign","restore","ProviderValidationError","check","validStrategies","createAssetsWriteStream","ProviderTransferError","fileEntitiesMapper","createAssetsDestinationWritable","resolveUploadFileId","metadata","id","restoreMediaEntitiesContent","removeAssetsBackup","bind","createConfigurationWriteStream","createLinksWriteStream","mapID","uid","onWarning","name","assets","notIncluded","entities","include","includes","excluded","exclude","uploadsBackupDirectoryName","now","message","report","details","origin","kind","stream","queryBuilder","select","transacting","file","plugin","provider","delete","formats","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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;MAkBaA,yBAAAA,GAA4B;AAAC,IAAA;;AACnC,MAAMC,4BAA4B;IA2BvC,YAAA,iBAAA,8BAAA,CAAA,cAAA,CAAA;;AAIC,MACD;AAoBA,kBAAA,iBAAA,8BAAA,CAAA,oBAAA,CAAA,EAIA,sBAAA,iBAAA,8BAAA,CAAA,wBAAA,CAAA,EAWA,WAAA,iBAAA,8BAAA,CAAA,aAAA,CAAA,EAsBA,gBAAA,iBAAA,8BAAA,CAAA,kBAAA,CAAA,EAgBM,yBAAA,iBAAA,8BAAA,CAAA,2BAAA,CAAA,EASA,qFAsHA,mBAAA,iBAAA,8BAAA,CAAA,qBAAA,CAAA,EA2CA,mBAAA,iBAAA,8BAAA,CAAA,qBAAA,CAAA;AAvQR,MAAMC,8BAAAA,CAAAA;IA4BJ,MAAMC,SAAAA,CAAUC,WAAiC,EAAiB;QAChE,+BAAA,CAAA,IAAI,EAAC,YAAA,CAAA,CAAA,YAAA,CAAA,GAAeA,WAAAA;QACpB,+BAAA,CAAA,IAAI,EAAC,gBAAA,CAAA,CAAA,gBAAA,CAAA,EAAA;QACL,IAAI,CAACC,MAAM,GAAG,MAAM,IA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,EAAC,WAAA,CAAA,CAAA,WAAA,CAAA,CAAY,wBAAA,CAAA;QACjBxE,iBAAAA,CAAkB,IAAI,CAACX,MAAM,CAAA;AAC7B,QAAA,MAAM8F,kBAAkBL,IAAAA,CAAKC,IAAI,CAC/B,IAAI,CAAC1F,MAAM,CAAC2F,IAAI,CAACC,MAAM,CAACC,MAAM,EAC9B,IAAI,CAACvB,0BAA0B,CAAA;QAEjC,MAAMyB,EAAAA,CAAIW,EAAE,CAACZ,eAAAA,EAAiB;YAAEa,SAAAA,EAAW,IAAA;YAAMC,KAAAA,EAAO;AAAK,SAAA,CAAA;QAC7D,+BAAA,CAAA,IAAI,EAAC,WAAA,CAAA,CAAA,WAAA,CAAA,CAAY,oCAAA,CAAA;AACnB,IAAA;AACF;AA4DK,MAAMC,uCAAuC,CAClD5G,OAAAA,GAAAA;AAEA,IAAA,OAAO,IAAIJ,8BAAAA,CAA+BI,OAAAA,CAAAA;AAC5C;;;;"}
@@ -1,7 +1,6 @@
1
- /// <reference types="node" />
2
1
  import { Writable } from 'stream';
3
2
  import type { Core } from '@strapi/types';
4
- import { IConfiguration, Transaction } from '../../../../../../types';
3
+ import { IConfiguration, Transaction } from '../../../../../types';
5
4
  export declare const restoreConfigs: (strapi: Core.Strapi, config: IConfiguration) => Promise<any>;
6
5
  export declare const createConfigurationWriteStream: (strapi: Core.Strapi, transaction?: Transaction) => Promise<Writable>;
7
6
  //# sourceMappingURL=configuration.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"configuration.d.ts","sourceRoot":"","sources":["../../../../../../src/strapi/providers/local-destination/strategies/restore/configuration.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAGlC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAE1C,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAmBtE,eAAO,MAAM,cAAc,WAAkB,KAAK,MAAM,UAAU,cAAc,iBAQ/E,CAAC;AAEF,eAAO,MAAM,8BAA8B,WACjC,KAAK,MAAM,gBACL,WAAW,sBAyB1B,CAAC"}
1
+ {"version":3,"file":"configuration.d.ts","sourceRoot":"","sources":["../../../../../../src/strapi/providers/local-destination/strategies/restore/configuration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAGlC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAE1C,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAyBnE,eAAO,MAAM,cAAc,GAAU,QAAQ,IAAI,CAAC,MAAM,EAAE,QAAQ,cAAc,iBAQ/E,CAAC;AAEF,eAAO,MAAM,8BAA8B,GACzC,QAAQ,IAAI,CAAC,MAAM,EACnB,cAAc,WAAW,sBAyB1B,CAAC"}
@@ -0,0 +1,58 @@
1
+ 'use strict';
2
+
3
+ var stream = require('stream');
4
+ var fp = require('lodash/fp');
5
+ var chalk = require('chalk');
6
+ var providers = require('../../../../../errors/providers.js');
7
+ var projectSettingsLogos = require('../../../../utils/project-settings-logos.js');
8
+
9
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
10
+
11
+ var chalk__default = /*#__PURE__*/_interopDefault(chalk);
12
+
13
+ const omitInvalidCreationAttributes = fp.omit([
14
+ 'id'
15
+ ]);
16
+ const restoreCoreStore = async (strapi, values)=>{
17
+ const data = omitInvalidCreationAttributes(values);
18
+ const row = await projectSettingsLogos.restoreProjectSettingsRow(strapi, data);
19
+ return strapi.db.query('strapi::core-store').create({
20
+ data: {
21
+ ...row,
22
+ value: JSON.stringify(row.value)
23
+ }
24
+ });
25
+ };
26
+ const restoreWebhooks = async (strapi, values)=>{
27
+ const data = omitInvalidCreationAttributes(values);
28
+ return strapi.db.query('strapi::webhook').create({
29
+ data
30
+ });
31
+ };
32
+ const restoreConfigs = async (strapi, config)=>{
33
+ if (config.type === 'core-store') {
34
+ return restoreCoreStore(strapi, config.value);
35
+ }
36
+ if (config.type === 'webhook') {
37
+ return restoreWebhooks(strapi, config.value);
38
+ }
39
+ };
40
+ const createConfigurationWriteStream = async (strapi, transaction)=>{
41
+ return new stream.Writable({
42
+ objectMode: true,
43
+ async write (config, _encoding, callback) {
44
+ await transaction?.attach(async ()=>{
45
+ try {
46
+ await restoreConfigs(strapi, config);
47
+ } catch (error) {
48
+ return callback(new providers.ProviderTransferError(`Failed to import ${chalk__default.default.yellowBright(config.type)} (${chalk__default.default.greenBright(config.value.id)}`));
49
+ }
50
+ callback();
51
+ });
52
+ }
53
+ });
54
+ };
55
+
56
+ exports.createConfigurationWriteStream = createConfigurationWriteStream;
57
+ exports.restoreConfigs = restoreConfigs;
58
+ //# sourceMappingURL=configuration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configuration.js","sources":["../../../../../../src/strapi/providers/local-destination/strategies/restore/configuration.ts"],"sourcesContent":["import { Writable } from 'stream';\nimport { omit } from 'lodash/fp';\nimport chalk from 'chalk';\nimport type { Core } from '@strapi/types';\nimport { ProviderTransferError } from '../../../../../errors/providers';\nimport { IConfiguration, Transaction } from '../../../../../types';\nimport { restoreProjectSettingsRow } from '../../../../utils/project-settings-logos';\n\nconst omitInvalidCreationAttributes = omit(['id']);\n\nconst restoreCoreStore = async <T extends { value: unknown }>(strapi: Core.Strapi, values: T) => {\n const data = omitInvalidCreationAttributes(values);\n const row = await restoreProjectSettingsRow(\n strapi,\n data as unknown as { key: string; value: unknown }\n );\n\n return strapi.db.query('strapi::core-store').create({\n data: {\n ...row,\n value: JSON.stringify(row.value),\n },\n });\n};\n\nconst restoreWebhooks = async <T extends { value: unknown }>(strapi: Core.Strapi, values: T) => {\n const data = omitInvalidCreationAttributes(values);\n return strapi.db.query('strapi::webhook').create({ data });\n};\n\nexport const restoreConfigs = async (strapi: Core.Strapi, config: IConfiguration) => {\n if (config.type === 'core-store') {\n return restoreCoreStore(strapi, config.value as { value: unknown });\n }\n\n if (config.type === 'webhook') {\n return restoreWebhooks(strapi, config.value as { value: unknown });\n }\n};\n\nexport const createConfigurationWriteStream = async (\n strapi: Core.Strapi,\n transaction?: Transaction\n) => {\n return new Writable({\n objectMode: true,\n async write<T extends { id: number }>(\n config: IConfiguration<T>,\n _encoding: BufferEncoding,\n callback: (error?: Error | null) => void\n ) {\n await transaction?.attach(async () => {\n try {\n await restoreConfigs(strapi, config);\n } catch (error) {\n return callback(\n new ProviderTransferError(\n `Failed to import ${chalk.yellowBright(config.type)} (${chalk.greenBright(\n config.value.id\n )}`\n )\n );\n }\n callback();\n });\n },\n });\n};\n"],"names":["omitInvalidCreationAttributes","omit","restoreCoreStore","strapi","values","data","row","restoreProjectSettingsRow","db","query","create","value","JSON","stringify","restoreWebhooks","restoreConfigs","config","type","createConfigurationWriteStream","transaction","Writable","objectMode","write","_encoding","callback","attach","error","ProviderTransferError","chalk","yellowBright","greenBright","id"],"mappings":";;;;;;;;;;;;AAQA,MAAMA,gCAAgCC,OAAAA,CAAK;AAAC,IAAA;AAAK,CAAA,CAAA;AAEjD,MAAMC,gBAAAA,GAAmB,OAAqCC,MAAAA,EAAqBC,MAAAA,GAAAA;AACjF,IAAA,MAAMC,OAAOL,6BAAAA,CAA8BI,MAAAA,CAAAA;IAC3C,MAAME,GAAAA,GAAM,MAAMC,8CAAAA,CAChBJ,MAAAA,EACAE,IAAAA,CAAAA;AAGF,IAAA,OAAOF,OAAOK,EAAE,CAACC,KAAK,CAAC,oBAAA,CAAA,CAAsBC,MAAM,CAAC;QAClDL,IAAAA,EAAM;AACJ,YAAA,GAAGC,GAAG;AACNK,YAAAA,KAAAA,EAAOC,IAAAA,CAAKC,SAAS,CAACP,GAAAA,CAAIK,KAAK;AACjC;AACF,KAAA,CAAA;AACF,CAAA;AAEA,MAAMG,eAAAA,GAAkB,OAAqCX,MAAAA,EAAqBC,MAAAA,GAAAA;AAChF,IAAA,MAAMC,OAAOL,6BAAAA,CAA8BI,MAAAA,CAAAA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import { omit } from 'lodash/fp';
3
+ import chalk from 'chalk';
4
+ import { ProviderTransferError } from '../../../../../errors/providers.mjs';
5
+ import { restoreProjectSettingsRow } from '../../../../utils/project-settings-logos.mjs';
6
+
7
+ const omitInvalidCreationAttributes = omit([
8
+ 'id'
9
+ ]);
10
+ const restoreCoreStore = async (strapi, values)=>{
11
+ const data = omitInvalidCreationAttributes(values);
12
+ const row = await restoreProjectSettingsRow(strapi, data);
13
+ return strapi.db.query('strapi::core-store').create({
14
+ data: {
15
+ ...row,
16
+ value: JSON.stringify(row.value)
17
+ }
18
+ });
19
+ };
20
+ const restoreWebhooks = async (strapi, values)=>{
21
+ const data = omitInvalidCreationAttributes(values);
22
+ return strapi.db.query('strapi::webhook').create({
23
+ data
24
+ });
25
+ };
26
+ const restoreConfigs = async (strapi, config)=>{
27
+ if (config.type === 'core-store') {
28
+ return restoreCoreStore(strapi, config.value);
29
+ }
30
+ if (config.type === 'webhook') {
31
+ return restoreWebhooks(strapi, config.value);
32
+ }
33
+ };
34
+ const createConfigurationWriteStream = async (strapi, transaction)=>{
35
+ return new Writable({
36
+ objectMode: true,
37
+ async write (config, _encoding, callback) {
38
+ await transaction?.attach(async ()=>{
39
+ try {
40
+ await restoreConfigs(strapi, config);
41
+ } catch (error) {
42
+ return callback(new ProviderTransferError(`Failed to import ${chalk.yellowBright(config.type)} (${chalk.greenBright(config.value.id)}`));
43
+ }
44
+ callback();
45
+ });
46
+ }
47
+ });
48
+ };
49
+
50
+ export { createConfigurationWriteStream, restoreConfigs };
51
+ //# sourceMappingURL=configuration.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configuration.mjs","sources":["../../../../../../src/strapi/providers/local-destination/strategies/restore/configuration.ts"],"sourcesContent":["import { Writable } from 'stream';\nimport { omit } from 'lodash/fp';\nimport chalk from 'chalk';\nimport type { Core } from '@strapi/types';\nimport { ProviderTransferError } from '../../../../../errors/providers';\nimport { IConfiguration, Transaction } from '../../../../../types';\nimport { restoreProjectSettingsRow } from '../../../../utils/project-settings-logos';\n\nconst omitInvalidCreationAttributes = omit(['id']);\n\nconst restoreCoreStore = async <T extends { value: unknown }>(strapi: Core.Strapi, values: T) => {\n const data = omitInvalidCreationAttributes(values);\n const row = await restoreProjectSettingsRow(\n strapi,\n data as unknown as { key: string; value: unknown }\n );\n\n return strapi.db.query('strapi::core-store').create({\n data: {\n ...row,\n value: JSON.stringify(row.value),\n },\n });\n};\n\nconst restoreWebhooks = async <T extends { value: unknown }>(strapi: Core.Strapi, values: T) => {\n const data = omitInvalidCreationAttributes(values);\n return strapi.db.query('strapi::webhook').create({ data });\n};\n\nexport const restoreConfigs = async (strapi: Core.Strapi, config: IConfiguration) => {\n if (config.type === 'core-store') {\n return restoreCoreStore(strapi, config.value as { value: unknown });\n }\n\n if (config.type === 'webhook') {\n return restoreWebhooks(strapi, config.value as { value: unknown });\n }\n};\n\nexport const createConfigurationWriteStream = async (\n strapi: Core.Strapi,\n transaction?: Transaction\n) => {\n return new Writable({\n objectMode: true,\n async write<T extends { id: number }>(\n config: IConfiguration<T>,\n _encoding: BufferEncoding,\n callback: (error?: Error | null) => void\n ) {\n await transaction?.attach(async () => {\n try {\n await restoreConfigs(strapi, config);\n } catch (error) {\n return callback(\n new ProviderTransferError(\n `Failed to import ${chalk.yellowBright(config.type)} (${chalk.greenBright(\n config.value.id\n )}`\n )\n );\n }\n callback();\n });\n },\n });\n};\n"],"names":["omitInvalidCreationAttributes","omit","restoreCoreStore","strapi","values","data","row","restoreProjectSettingsRow","db","query","create","value","JSON","stringify","restoreWebhooks","restoreConfigs","config","type","createConfigurationWriteStream","transaction","Writable","objectMode","write","_encoding","callback","attach","error","ProviderTransferError","chalk","yellowBright","greenBright","id"],"mappings":";;;;;;AAQA,MAAMA,gCAAgCC,IAAAA,CAAK;AAAC,IAAA;AAAK,CAAA,CAAA;AAEjD,MAAMC,gBAAAA,GAAmB,OAAqCC,MAAAA,EAAqBC,MAAAA,GAAAA;AACjF,IAAA,MAAMC,OA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A,MAAMV,eAAeZ,MAAAA,EAAQa,MAAAA,CAAAA;AAC/B,gBAAA,CAAA,CAAE,OAAOU,KAAAA,EAAO;oBACd,OAAOF,QAAAA,CACL,IAAIG,qBAAAA,CACF,CAAC,iBAAiB,EAAEC,KAAAA,CAAMC,YAAY,CAACb,MAAAA,CAAOC,IAAI,CAAA,CAAE,EAAE,EAAEW,KAAAA,CAAME,WAAW,CACvEd,MAAAA,CAAOL,KAAK,CAACoB,EAAE,CAAA,CAAA,CACd,CAAA,CAAA;AAGT,gBAAA;AACAP,gBAAAA,QAAAA,EAAAA;AACF,YAAA,CAAA,CAAA;AACF,QAAA;AACF,KAAA,CAAA;AACF;;;;"}
@@ -1,7 +1,6 @@
1
- /// <reference types="node" />
2
1
  import { Writable } from 'stream';
3
2
  import type { Core, UID } from '@strapi/types';
4
- import type { Transaction } from '../../../../../../types';
3
+ import type { Transaction } from '../../../../../types';
5
4
  interface IEntitiesRestoreStreamOptions {
6
5
  strapi: Core.Strapi;
7
6
  updateMappingTable<TSchemaUID extends UID.Schema>(type: TSchemaUID, oldID: number, newID: number): void;
@@ -1 +1 @@
1
- {"version":3,"file":"entities.d.ts","sourceRoot":"","sources":["../../../../../../src/strapi/providers/local-destination/strategies/restore/entities.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAClC,OAAO,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAK/C,OAAO,KAAK,EAAW,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAKpE,UAAU,6BAA6B;IACrC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC;IACpB,kBAAkB,CAAC,UAAU,SAAS,GAAG,CAAC,MAAM,EAC9C,IAAI,EAAE,UAAU,EAChB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,GACZ,IAAI,CAAC;IACR,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B;AAED,eAAO,MAAM,yBAAyB,YAAa,6BAA6B,aAqD/E,CAAC"}
1
+ {"version":3,"file":"entities.d.ts","sourceRoot":"","sources":["../../../../../../src/strapi/providers/local-destination/strategies/restore/entities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAClC,OAAO,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAG/C,OAAO,KAAK,EAAW,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAIjE,UAAU,6BAA6B;IACrC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC;IACpB,kBAAkB,CAAC,UAAU,SAAS,GAAG,CAAC,MAAM,EAC9C,IAAI,EAAE,UAAU,EAChB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,GACZ,IAAI,CAAC;IACR,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B;AAED,eAAO,MAAM,yBAAyB,GAAI,SAAS,6BAA6B,aAgD/E,CAAC"}
@@ -0,0 +1,54 @@
1
+ 'use strict';
2
+
3
+ var stream = require('stream');
4
+ var providers = require('../../../../../errors/providers.js');
5
+ var entity = require('../../../../queries/entity.js');
6
+ require('lodash/fp');
7
+ var components = require('../../../../../utils/components.js');
8
+
9
+ const createEntitiesWriteStream = (options)=>{
10
+ const { strapi, updateMappingTable, transaction } = options;
11
+ const query = entity.createEntityQuery(strapi);
12
+ return new stream.Writable({
13
+ objectMode: true,
14
+ async write (entity, _encoding, callback) {
15
+ await transaction?.attach(async ()=>{
16
+ const { type, id, data } = entity;
17
+ const { create, getDeepPopulateComponentLikeQuery } = query(type);
18
+ const contentType = strapi.getModel(type);
19
+ try {
20
+ const created = await create({
21
+ data,
22
+ populate: getDeepPopulateComponentLikeQuery(contentType, {
23
+ select: 'id'
24
+ }),
25
+ select: 'id'
26
+ });
27
+ updateMappingTable(type, id, created.id);
28
+ // Register the ID of every component instance that was re-created
29
+ // with the entity — including the ones whose ID did not change — so
30
+ // that the links stage can resolve component-side references and
31
+ // tell transferred components apart from missing/orphaned ones
32
+ const componentMappings = components.collectComponentIdMappings({
33
+ data,
34
+ created,
35
+ schema: contentType,
36
+ strapi
37
+ });
38
+ for (const { uid, oldID, newID } of componentMappings){
39
+ updateMappingTable(uid, oldID, newID);
40
+ }
41
+ } catch (e) {
42
+ if (e instanceof Error) {
43
+ return callback(e);
44
+ }
45
+ return callback(new providers.ProviderTransferError(`Failed to create "${type}" (${id})`));
46
+ }
47
+ return callback(null);
48
+ });
49
+ }
50
+ });
51
+ };
52
+
53
+ exports.createEntitiesWriteStream = createEntitiesWriteStream;
54
+ //# sourceMappingURL=entities.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entities.js","sources":["../../../../../../src/strapi/providers/local-destination/strategies/restore/entities.ts"],"sourcesContent":["import { Writable } from 'stream';\nimport type { Core, UID } from '@strapi/types';\n\nimport { ProviderTransferError } from '../../../../../errors/providers';\nimport type { IEntity, Transaction } from '../../../../../types';\nimport * as queries from '../../../../queries';\nimport { collectComponentIdMappings } from '../../../../../utils/components';\n\ninterface IEntitiesRestoreStreamOptions {\n strapi: Core.Strapi;\n updateMappingTable<TSchemaUID extends UID.Schema>(\n type: TSchemaUID,\n oldID: number,\n newID: number\n ): void;\n transaction?: Transaction;\n}\n\nexport const createEntitiesWriteStream = (options: IEntitiesRestoreStreamOptions) => {\n const { strapi, updateMappingTable, transaction } = options;\n const query = queries.entity.createEntityQuery(strapi);\n\n return new Writable({\n objectMode: true,\n\n async write(entity: IEntity, _encoding, callback) {\n await transaction?.attach(async () => {\n const { type, id, data } = entity;\n const { create, getDeepPopulateComponentLikeQuery } = query(type);\n const contentType = strapi.getModel(type);\n\n try {\n const created = await create({\n data,\n populate: getDeepPopulateComponentLikeQuery(contentType, { select: 'id' }),\n select: 'id',\n });\n\n updateMappingTable(type, id, created.id);\n\n // Register the ID of every component instance that was re-created\n // with the entity — including the ones whose ID did not change — so\n // that the links stage can resolve component-side references and\n // tell transferred components apart from missing/orphaned ones\n const componentMappings = collectComponentIdMappings({\n data,\n created,\n schema: contentType,\n strapi,\n });\n\n for (const { uid, oldID, newID } of componentMappings) {\n updateMappingTable(uid, oldID, newID);\n }\n } catch (e) {\n if (e instanceof Error) {\n return callback(e);\n }\n\n return callback(new ProviderTransferError(`Failed to create \"${type}\" (${id})`));\n }\n\n return callback(null);\n });\n },\n });\n};\n"],"names":["createEntitiesWriteStream","options","strapi","updateMappingTable","transaction","query","queries","Writable","objectMode","write","entity","_encoding","callback","attach","type","id","data","create","getDeepPopulateComponentLikeQuery","contentType","getModel","created","populate","select","componentMappings","collectComponentIdMappings","schema","uid","oldID","newID","e","Error","ProviderTransferError"],"mappings":";;;;;;;;AAkBO,MAAMA,4BAA4B,CAACC,OAAAA,GAAAA;AACxC,IAAA,MAAM,EAAEC,MAAM,EAAEC,kBAAkB,EAAEC,WAAW,EAAE,GAAGH,OAAAA;AACpD,IAAA,MAAMI,KAAAA,GAAQC,wBAAgC,CAACJ,MAAAA,CAAAA;AAE/C,IAAA,OAAO,IAAIK,eAAAA,CAAS;QAClBC,UAAAA,EAAY,IAAA;AAEZ,QAAA,MAAMC,KAAAA,CAAAA,CAAMC,MAAe,EAAEC,SAAS,EAAEC,QAAQ,EAAA;AAC9C,YAAA,MAAMR,aAAaS,MAAAA,CAAO,UAAA;AACxB,gBAAA,MAAM,EAAEC,IAAI,EAAEC,EAAE,EAAEC,IAAI,EAAE,GAAGN,MAAAA;AAC3B,gBAAA,MAAM,EAAEO,MAAM,EAAEC,iCAAiC,EAAE,GAAGb,KAAAA,CAAMS,IAAAA,CAAAA;gBAC5D,MAAMK,WAAAA,GAAcjB,MAAAA,CAAOkB,QAAQ,CAACN,IAAAA,CAAAA;gBAEpC,IAAI;oBACF,MAAMO,OAAAA,GAAU,MAAMJ,MAAAA,CAAO;AAC3BD,wBAAAA,IAAAA;AACAM,wBAAAA,QAAAA,EAAUJ,kCAAkCC,WAAAA,EAAa;4BAAEI,MAAAA,EAAQ;AAAK,yB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