@solidxai/core 0.1.22-beta.2 → 0.1.22-beta.4

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 (472) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/dist/constants/error-messages.d.ts +1 -1
  3. package/dist/constants/error-messages.d.ts.map +1 -1
  4. package/dist/constants/error-messages.js +1 -1
  5. package/dist/constants/error-messages.js.map +1 -1
  6. package/dist/controllers/agent-registry.controller.d.ts +8 -0
  7. package/dist/controllers/agent-registry.controller.d.ts.map +1 -1
  8. package/dist/controllers/agent-registry.controller.js +14 -0
  9. package/dist/controllers/agent-registry.controller.js.map +1 -1
  10. package/dist/controllers/agent-session.controller.d.ts +8 -1
  11. package/dist/controllers/agent-session.controller.d.ts.map +1 -1
  12. package/dist/controllers/agent-session.controller.js +66 -2
  13. package/dist/controllers/agent-session.controller.js.map +1 -1
  14. package/dist/controllers/media-migration-item.controller.d.ts +8 -0
  15. package/dist/controllers/media-migration-item.controller.d.ts.map +1 -0
  16. package/dist/controllers/media-migration-item.controller.js +66 -0
  17. package/dist/controllers/media-migration-item.controller.js.map +1 -0
  18. package/dist/controllers/media-migration-job.controller.d.ts +8 -0
  19. package/dist/controllers/media-migration-job.controller.d.ts.map +1 -0
  20. package/dist/controllers/media-migration-job.controller.js +66 -0
  21. package/dist/controllers/media-migration-job.controller.js.map +1 -0
  22. package/dist/controllers/media-migration.controller.d.ts +321 -0
  23. package/dist/controllers/media-migration.controller.d.ts.map +1 -0
  24. package/dist/controllers/media-migration.controller.js +197 -0
  25. package/dist/controllers/media-migration.controller.js.map +1 -0
  26. package/dist/controllers/media-migration.controller.spec.d.ts +2 -0
  27. package/dist/controllers/media-migration.controller.spec.d.ts.map +1 -0
  28. package/dist/controllers/media-migration.controller.spec.js +72 -0
  29. package/dist/controllers/media-migration.controller.spec.js.map +1 -0
  30. package/dist/controllers/test-data.controller.d.ts +12 -0
  31. package/dist/controllers/test-data.controller.d.ts.map +1 -0
  32. package/dist/controllers/test-data.controller.js +66 -0
  33. package/dist/controllers/test-data.controller.js.map +1 -0
  34. package/dist/controllers/test-data.controller.spec.d.ts +2 -0
  35. package/dist/controllers/test-data.controller.spec.d.ts.map +1 -0
  36. package/dist/controllers/test-data.controller.spec.js +78 -0
  37. package/dist/controllers/test-data.controller.spec.js.map +1 -0
  38. package/dist/dtos/create-agent-job.dto.d.ts +1 -0
  39. package/dist/dtos/create-agent-job.dto.d.ts.map +1 -1
  40. package/dist/dtos/create-agent-job.dto.js +8 -1
  41. package/dist/dtos/create-agent-job.dto.js.map +1 -1
  42. package/dist/dtos/create-agent-process.dto.d.ts +5 -0
  43. package/dist/dtos/create-agent-process.dto.d.ts.map +1 -1
  44. package/dist/dtos/create-agent-process.dto.js +37 -1
  45. package/dist/dtos/create-agent-process.dto.js.map +1 -1
  46. package/dist/dtos/create-agent-registry.dto.d.ts +5 -0
  47. package/dist/dtos/create-agent-registry.dto.d.ts.map +1 -1
  48. package/dist/dtos/create-agent-registry.dto.js +39 -1
  49. package/dist/dtos/create-agent-registry.dto.js.map +1 -1
  50. package/dist/dtos/create-agent-session.dto.js +1 -1
  51. package/dist/dtos/create-agent-session.dto.js.map +1 -1
  52. package/dist/dtos/create-media-migration.dto.d.ts +21 -0
  53. package/dist/dtos/create-media-migration.dto.d.ts.map +1 -0
  54. package/dist/dtos/create-media-migration.dto.js +126 -0
  55. package/dist/dtos/create-media-migration.dto.js.map +1 -0
  56. package/dist/dtos/create-media-storage-provider-metadata.dto.d.ts.map +1 -1
  57. package/dist/dtos/create-media-storage-provider-metadata.dto.js +11 -0
  58. package/dist/dtos/create-media-storage-provider-metadata.dto.js.map +1 -1
  59. package/dist/dtos/create-media-storage-provider-metadata.dto.spec.d.ts +2 -0
  60. package/dist/dtos/create-media-storage-provider-metadata.dto.spec.d.ts.map +1 -0
  61. package/dist/dtos/create-media-storage-provider-metadata.dto.spec.js +29 -0
  62. package/dist/dtos/create-media-storage-provider-metadata.dto.spec.js.map +1 -0
  63. package/dist/dtos/test-run-request.dto.d.ts +1 -0
  64. package/dist/dtos/test-run-request.dto.d.ts.map +1 -1
  65. package/dist/dtos/test-run-request.dto.js +7 -1
  66. package/dist/dtos/test-run-request.dto.js.map +1 -1
  67. package/dist/dtos/update-agent-deployment.dto.d.ts +8 -0
  68. package/dist/dtos/update-agent-deployment.dto.d.ts.map +1 -0
  69. package/dist/dtos/update-agent-deployment.dto.js +60 -0
  70. package/dist/dtos/update-agent-deployment.dto.js.map +1 -0
  71. package/dist/dtos/update-agent-job.dto.d.ts +1 -0
  72. package/dist/dtos/update-agent-job.dto.d.ts.map +1 -1
  73. package/dist/dtos/update-agent-job.dto.js +8 -1
  74. package/dist/dtos/update-agent-job.dto.js.map +1 -1
  75. package/dist/dtos/update-agent-process.dto.d.ts +5 -0
  76. package/dist/dtos/update-agent-process.dto.d.ts.map +1 -1
  77. package/dist/dtos/update-agent-process.dto.js +37 -1
  78. package/dist/dtos/update-agent-process.dto.js.map +1 -1
  79. package/dist/dtos/update-agent-registry.dto.d.ts +5 -0
  80. package/dist/dtos/update-agent-registry.dto.d.ts.map +1 -1
  81. package/dist/dtos/update-agent-registry.dto.js +39 -1
  82. package/dist/dtos/update-agent-registry.dto.js.map +1 -1
  83. package/dist/dtos/update-agent-session.dto.js +1 -1
  84. package/dist/dtos/update-agent-session.dto.js.map +1 -1
  85. package/dist/entities/agent-job.entity.d.ts +1 -0
  86. package/dist/entities/agent-job.entity.d.ts.map +1 -1
  87. package/dist/entities/agent-job.entity.js +7 -2
  88. package/dist/entities/agent-job.entity.js.map +1 -1
  89. package/dist/entities/agent-process.entity.d.ts +8 -0
  90. package/dist/entities/agent-process.entity.d.ts.map +1 -1
  91. package/dist/entities/agent-process.entity.js +38 -1
  92. package/dist/entities/agent-process.entity.js.map +1 -1
  93. package/dist/entities/agent-registry.entity.d.ts +5 -0
  94. package/dist/entities/agent-registry.entity.d.ts.map +1 -1
  95. package/dist/entities/agent-registry.entity.js +22 -1
  96. package/dist/entities/agent-registry.entity.js.map +1 -1
  97. package/dist/entities/agent-session.entity.d.ts.map +1 -1
  98. package/dist/entities/agent-session.entity.js +3 -1
  99. package/dist/entities/agent-session.entity.js.map +1 -1
  100. package/dist/entities/media-migration-item.entity.d.ts +19 -0
  101. package/dist/entities/media-migration-item.entity.d.ts.map +1 -0
  102. package/dist/entities/media-migration-item.entity.js +85 -0
  103. package/dist/entities/media-migration-item.entity.js.map +1 -0
  104. package/dist/entities/media-migration-job.entity.d.ts +30 -0
  105. package/dist/entities/media-migration-job.entity.d.ts.map +1 -0
  106. package/dist/entities/media-migration-job.entity.js +131 -0
  107. package/dist/entities/media-migration-job.entity.js.map +1 -0
  108. package/dist/helpers/agent-config-version-name.d.ts +2 -0
  109. package/dist/helpers/agent-config-version-name.d.ts.map +1 -0
  110. package/dist/helpers/agent-config-version-name.js +17 -0
  111. package/dist/helpers/agent-config-version-name.js.map +1 -0
  112. package/dist/helpers/agent-config-version-name.spec.d.ts +2 -0
  113. package/dist/helpers/agent-config-version-name.spec.d.ts.map +1 -0
  114. package/dist/helpers/agent-config-version-name.spec.js +31 -0
  115. package/dist/helpers/agent-config-version-name.spec.js.map +1 -0
  116. package/dist/helpers/typeorm-db-helper.d.ts.map +1 -1
  117. package/dist/helpers/typeorm-db-helper.js +9 -0
  118. package/dist/helpers/typeorm-db-helper.js.map +1 -1
  119. package/dist/index.d.ts +6 -0
  120. package/dist/index.d.ts.map +1 -1
  121. package/dist/index.js +5 -0
  122. package/dist/index.js.map +1 -1
  123. package/dist/jobs/database/media-migration-publisher-database.service.d.ts +13 -0
  124. package/dist/jobs/database/media-migration-publisher-database.service.d.ts.map +1 -0
  125. package/dist/jobs/database/media-migration-publisher-database.service.js +39 -0
  126. package/dist/jobs/database/media-migration-publisher-database.service.js.map +1 -0
  127. package/dist/jobs/database/media-migration-queue-options-database.d.ts +8 -0
  128. package/dist/jobs/database/media-migration-queue-options-database.d.ts.map +1 -0
  129. package/dist/jobs/database/media-migration-queue-options-database.js +10 -0
  130. package/dist/jobs/database/media-migration-queue-options-database.js.map +1 -0
  131. package/dist/jobs/database/media-migration-subscriber-database.service.d.ts +21 -0
  132. package/dist/jobs/database/media-migration-subscriber-database.service.d.ts.map +1 -0
  133. package/dist/jobs/database/media-migration-subscriber-database.service.js +48 -0
  134. package/dist/jobs/database/media-migration-subscriber-database.service.js.map +1 -0
  135. package/dist/jobs/database/test-run-queue-subscriber-database.service.d.ts.map +1 -1
  136. package/dist/jobs/database/test-run-queue-subscriber-database.service.js +8 -4
  137. package/dist/jobs/database/test-run-queue-subscriber-database.service.js.map +1 -1
  138. package/dist/jobs/media-migration-queues.spec.d.ts +2 -0
  139. package/dist/jobs/media-migration-queues.spec.d.ts.map +1 -0
  140. package/dist/jobs/media-migration-queues.spec.js +49 -0
  141. package/dist/jobs/media-migration-queues.spec.js.map +1 -0
  142. package/dist/jobs/rabbitmq/media-migration-publisher.service.d.ts +13 -0
  143. package/dist/jobs/rabbitmq/media-migration-publisher.service.d.ts.map +1 -0
  144. package/dist/jobs/rabbitmq/media-migration-publisher.service.js +39 -0
  145. package/dist/jobs/rabbitmq/media-migration-publisher.service.js.map +1 -0
  146. package/dist/jobs/rabbitmq/media-migration-queue-options.d.ts +8 -0
  147. package/dist/jobs/rabbitmq/media-migration-queue-options.d.ts.map +1 -0
  148. package/dist/jobs/rabbitmq/media-migration-queue-options.js +10 -0
  149. package/dist/jobs/rabbitmq/media-migration-queue-options.js.map +1 -0
  150. package/dist/jobs/rabbitmq/media-migration-subscriber.service.d.ts +19 -0
  151. package/dist/jobs/rabbitmq/media-migration-subscriber.service.d.ts.map +1 -0
  152. package/dist/jobs/rabbitmq/media-migration-subscriber.service.js +45 -0
  153. package/dist/jobs/rabbitmq/media-migration-subscriber.service.js.map +1 -0
  154. package/dist/jobs/redis/media-migration-publisher-redis.service.d.ts +13 -0
  155. package/dist/jobs/redis/media-migration-publisher-redis.service.d.ts.map +1 -0
  156. package/dist/jobs/redis/media-migration-publisher-redis.service.js +39 -0
  157. package/dist/jobs/redis/media-migration-publisher-redis.service.js.map +1 -0
  158. package/dist/jobs/redis/media-migration-queue-options-redis.d.ts +8 -0
  159. package/dist/jobs/redis/media-migration-queue-options-redis.d.ts.map +1 -0
  160. package/dist/jobs/redis/media-migration-queue-options-redis.js +10 -0
  161. package/dist/jobs/redis/media-migration-queue-options-redis.js.map +1 -0
  162. package/dist/jobs/redis/media-migration-subscriber-redis.service.d.ts +19 -0
  163. package/dist/jobs/redis/media-migration-subscriber-redis.service.d.ts.map +1 -0
  164. package/dist/jobs/redis/media-migration-subscriber-redis.service.js +45 -0
  165. package/dist/jobs/redis/media-migration-subscriber-redis.service.js.map +1 -0
  166. package/dist/repository/media-migration-item.repository.d.ts +12 -0
  167. package/dist/repository/media-migration-item.repository.d.ts.map +1 -0
  168. package/dist/repository/media-migration-item.repository.js +34 -0
  169. package/dist/repository/media-migration-item.repository.js.map +1 -0
  170. package/dist/repository/media-migration-job.repository.d.ts +12 -0
  171. package/dist/repository/media-migration-job.repository.d.ts.map +1 -0
  172. package/dist/repository/media-migration-job.repository.js +34 -0
  173. package/dist/repository/media-migration-job.repository.js.map +1 -0
  174. package/dist/resources/agent-embed/solid-agent-embed.js +244 -4
  175. package/dist/seeders/media-migration-metadata.spec.d.ts +2 -0
  176. package/dist/seeders/media-migration-metadata.spec.d.ts.map +1 -0
  177. package/dist/seeders/media-migration-metadata.spec.js +119 -0
  178. package/dist/seeders/media-migration-metadata.spec.js.map +1 -0
  179. package/dist/seeders/module-test-data.service.d.ts +19 -0
  180. package/dist/seeders/module-test-data.service.d.ts.map +1 -1
  181. package/dist/seeders/module-test-data.service.js +95 -15
  182. package/dist/seeders/module-test-data.service.js.map +1 -1
  183. package/dist/seeders/module-test-data.service.spec.d.ts +2 -0
  184. package/dist/seeders/module-test-data.service.spec.d.ts.map +1 -0
  185. package/dist/seeders/module-test-data.service.spec.js +158 -0
  186. package/dist/seeders/module-test-data.service.spec.js.map +1 -0
  187. package/dist/seeders/seed-data/solid-core-metadata.json +2565 -1162
  188. package/dist/services/agent-hub-process-manager.service.d.ts +4 -0
  189. package/dist/services/agent-hub-process-manager.service.d.ts.map +1 -1
  190. package/dist/services/agent-hub-process-manager.service.js +19 -3
  191. package/dist/services/agent-hub-process-manager.service.js.map +1 -1
  192. package/dist/services/agent-registry.service.d.ts +8 -0
  193. package/dist/services/agent-registry.service.d.ts.map +1 -1
  194. package/dist/services/agent-registry.service.js +32 -1
  195. package/dist/services/agent-registry.service.js.map +1 -1
  196. package/dist/services/crud.service.d.ts +1 -0
  197. package/dist/services/crud.service.d.ts.map +1 -1
  198. package/dist/services/crud.service.js +26 -2
  199. package/dist/services/crud.service.js.map +1 -1
  200. package/dist/services/file/disk-file.service.d.ts +3 -0
  201. package/dist/services/file/disk-file.service.d.ts.map +1 -1
  202. package/dist/services/file/disk-file.service.js +12 -0
  203. package/dist/services/file/disk-file.service.js.map +1 -1
  204. package/dist/services/file/file-service.interface.d.ts +1 -0
  205. package/dist/services/file/file-service.interface.d.ts.map +1 -1
  206. package/dist/services/file/file-service.interface.js.map +1 -1
  207. package/dist/services/file/multipart-part-size.d.ts +3 -0
  208. package/dist/services/file/multipart-part-size.d.ts.map +1 -0
  209. package/dist/services/file/multipart-part-size.js +16 -0
  210. package/dist/services/file/multipart-part-size.js.map +1 -0
  211. package/dist/services/file/multipart-part-size.spec.d.ts +2 -0
  212. package/dist/services/file/multipart-part-size.spec.d.ts.map +1 -0
  213. package/dist/services/file/multipart-part-size.spec.js +25 -0
  214. package/dist/services/file/multipart-part-size.spec.js.map +1 -0
  215. package/dist/services/file/s3-file.service.d.ts +5 -0
  216. package/dist/services/file/s3-file.service.d.ts.map +1 -1
  217. package/dist/services/file/s3-file.service.js +42 -12
  218. package/dist/services/file/s3-file.service.js.map +1 -1
  219. package/dist/services/file/s3-file.service.spec.d.ts +2 -0
  220. package/dist/services/file/s3-file.service.spec.d.ts.map +1 -0
  221. package/dist/services/file/s3-file.service.spec.js +54 -0
  222. package/dist/services/file/s3-file.service.spec.js.map +1 -0
  223. package/dist/services/media-download-url.service.d.ts +5 -2
  224. package/dist/services/media-download-url.service.d.ts.map +1 -1
  225. package/dist/services/media-download-url.service.js +22 -1
  226. package/dist/services/media-download-url.service.js.map +1 -1
  227. package/dist/services/media-download-url.service.spec.d.ts +2 -0
  228. package/dist/services/media-download-url.service.spec.d.ts.map +1 -0
  229. package/dist/services/media-download-url.service.spec.js +55 -0
  230. package/dist/services/media-download-url.service.spec.js.map +1 -0
  231. package/dist/services/media-file-storage.service.d.ts +17 -0
  232. package/dist/services/media-file-storage.service.d.ts.map +1 -0
  233. package/dist/services/media-file-storage.service.js +73 -0
  234. package/dist/services/media-file-storage.service.js.map +1 -0
  235. package/dist/services/media-file-storage.service.spec.d.ts +2 -0
  236. package/dist/services/media-file-storage.service.spec.d.ts.map +1 -0
  237. package/dist/services/media-file-storage.service.spec.js +46 -0
  238. package/dist/services/media-file-storage.service.spec.js.map +1 -0
  239. package/dist/services/media-migration/media-location.d.ts +20 -0
  240. package/dist/services/media-migration/media-location.d.ts.map +1 -0
  241. package/dist/services/media-migration/media-location.js +140 -0
  242. package/dist/services/media-migration/media-location.js.map +1 -0
  243. package/dist/services/media-migration/media-location.spec.d.ts +2 -0
  244. package/dist/services/media-migration/media-location.spec.d.ts.map +1 -0
  245. package/dist/services/media-migration/media-location.spec.js +148 -0
  246. package/dist/services/media-migration/media-location.spec.js.map +1 -0
  247. package/dist/services/media-migration/media-migration-runner.service.d.ts +44 -0
  248. package/dist/services/media-migration/media-migration-runner.service.d.ts.map +1 -0
  249. package/dist/services/media-migration/media-migration-runner.service.js +434 -0
  250. package/dist/services/media-migration/media-migration-runner.service.js.map +1 -0
  251. package/dist/services/media-migration/media-migration-scope.d.ts +21 -0
  252. package/dist/services/media-migration/media-migration-scope.d.ts.map +1 -0
  253. package/dist/services/media-migration/media-migration-scope.js +128 -0
  254. package/dist/services/media-migration/media-migration-scope.js.map +1 -0
  255. package/dist/services/media-migration/media-migration.integration.spec.d.ts +2 -0
  256. package/dist/services/media-migration/media-migration.integration.spec.d.ts.map +1 -0
  257. package/dist/services/media-migration/media-migration.integration.spec.js +688 -0
  258. package/dist/services/media-migration/media-migration.integration.spec.js.map +1 -0
  259. package/dist/services/media-migration/media-migration.service.d.ts +86 -0
  260. package/dist/services/media-migration/media-migration.service.d.ts.map +1 -0
  261. package/dist/services/media-migration/media-migration.service.js +468 -0
  262. package/dist/services/media-migration/media-migration.service.js.map +1 -0
  263. package/dist/services/media-migration/media-transfer.service.d.ts +26 -0
  264. package/dist/services/media-migration/media-transfer.service.d.ts.map +1 -0
  265. package/dist/services/media-migration/media-transfer.service.js +274 -0
  266. package/dist/services/media-migration/media-transfer.service.js.map +1 -0
  267. package/dist/services/media-migration/media-transfer.service.spec.d.ts +2 -0
  268. package/dist/services/media-migration/media-transfer.service.spec.d.ts.map +1 -0
  269. package/dist/services/media-migration/media-transfer.service.spec.js +266 -0
  270. package/dist/services/media-migration/media-transfer.service.spec.js.map +1 -0
  271. package/dist/services/media-migration/migration-error.d.ts +10 -0
  272. package/dist/services/media-migration/migration-error.d.ts.map +1 -0
  273. package/dist/services/media-migration/migration-error.js +40 -0
  274. package/dist/services/media-migration/migration-error.js.map +1 -0
  275. package/dist/services/media-migration/migration-error.spec.d.ts +2 -0
  276. package/dist/services/media-migration/migration-error.spec.d.ts.map +1 -0
  277. package/dist/services/media-migration/migration-error.spec.js +37 -0
  278. package/dist/services/media-migration/migration-error.spec.js.map +1 -0
  279. package/dist/services/media-migration-item.service.d.ts +12 -0
  280. package/dist/services/media-migration-item.service.d.ts.map +1 -0
  281. package/dist/services/media-migration-item.service.js +38 -0
  282. package/dist/services/media-migration-item.service.js.map +1 -0
  283. package/dist/services/media-migration-job.service.d.ts +12 -0
  284. package/dist/services/media-migration-job.service.d.ts.map +1 -0
  285. package/dist/services/media-migration-job.service.js +38 -0
  286. package/dist/services/media-migration-job.service.js.map +1 -0
  287. package/dist/services/media-storage-provider-changes.d.ts +15 -0
  288. package/dist/services/media-storage-provider-changes.d.ts.map +1 -0
  289. package/dist/services/media-storage-provider-changes.js +39 -0
  290. package/dist/services/media-storage-provider-changes.js.map +1 -0
  291. package/dist/services/media-storage-provider-changes.spec.d.ts +2 -0
  292. package/dist/services/media-storage-provider-changes.spec.d.ts.map +1 -0
  293. package/dist/services/media-storage-provider-changes.spec.js +47 -0
  294. package/dist/services/media-storage-provider-changes.spec.js.map +1 -0
  295. package/dist/services/media-storage-provider-metadata.service.d.ts +6 -1
  296. package/dist/services/media-storage-provider-metadata.service.d.ts.map +1 -1
  297. package/dist/services/media-storage-provider-metadata.service.js +59 -5
  298. package/dist/services/media-storage-provider-metadata.service.js.map +1 -1
  299. package/dist/services/media-storage-provider-metadata.service.spec.d.ts +2 -0
  300. package/dist/services/media-storage-provider-metadata.service.spec.d.ts.map +1 -0
  301. package/dist/services/media-storage-provider-metadata.service.spec.js +88 -0
  302. package/dist/services/media-storage-provider-metadata.service.spec.js.map +1 -0
  303. package/dist/services/media.service.d.ts +3 -1
  304. package/dist/services/media.service.d.ts.map +1 -1
  305. package/dist/services/media.service.js +12 -35
  306. package/dist/services/media.service.js.map +1 -1
  307. package/dist/services/mediaStorageProviders/file-s3-storage-provider.d.ts +4 -1
  308. package/dist/services/mediaStorageProviders/file-s3-storage-provider.d.ts.map +1 -1
  309. package/dist/services/mediaStorageProviders/file-s3-storage-provider.js +33 -23
  310. package/dist/services/mediaStorageProviders/file-s3-storage-provider.js.map +1 -1
  311. package/dist/services/mediaStorageProviders/file-s3-storage-provider.spec.d.ts +2 -0
  312. package/dist/services/mediaStorageProviders/file-s3-storage-provider.spec.d.ts.map +1 -0
  313. package/dist/services/mediaStorageProviders/file-s3-storage-provider.spec.js +63 -0
  314. package/dist/services/mediaStorageProviders/file-s3-storage-provider.spec.js.map +1 -0
  315. package/dist/services/mediaStorageProviders/file-storage-provider.d.ts +3 -1
  316. package/dist/services/mediaStorageProviders/file-storage-provider.d.ts.map +1 -1
  317. package/dist/services/mediaStorageProviders/file-storage-provider.js +8 -9
  318. package/dist/services/mediaStorageProviders/file-storage-provider.js.map +1 -1
  319. package/dist/services/settings/default-settings-provider.service.d.ts +12 -2
  320. package/dist/services/settings/default-settings-provider.service.d.ts.map +1 -1
  321. package/dist/services/settings/default-settings-provider.service.js +7 -1
  322. package/dist/services/settings/default-settings-provider.service.js.map +1 -1
  323. package/dist/solid-core.module.d.ts.map +1 -1
  324. package/dist/solid-core.module.js +41 -0
  325. package/dist/solid-core.module.js.map +1 -1
  326. package/dist/testing/adapters/ui/browser-provisioner.d.ts +11 -0
  327. package/dist/testing/adapters/ui/browser-provisioner.d.ts.map +1 -1
  328. package/dist/testing/adapters/ui/browser-provisioner.js +51 -1
  329. package/dist/testing/adapters/ui/browser-provisioner.js.map +1 -1
  330. package/dist/testing/adapters/ui/browser-provisioner.spec.d.ts +2 -0
  331. package/dist/testing/adapters/ui/browser-provisioner.spec.d.ts.map +1 -0
  332. package/dist/testing/adapters/ui/browser-provisioner.spec.js +137 -0
  333. package/dist/testing/adapters/ui/browser-provisioner.spec.js.map +1 -0
  334. package/dist/testing/adapters/ui/playwright-adapter.d.ts +7 -0
  335. package/dist/testing/adapters/ui/playwright-adapter.d.ts.map +1 -1
  336. package/dist/testing/adapters/ui/playwright-adapter.js +37 -8
  337. package/dist/testing/adapters/ui/playwright-adapter.js.map +1 -1
  338. package/dist/testing/adapters/ui/run-video.d.ts +40 -0
  339. package/dist/testing/adapters/ui/run-video.d.ts.map +1 -0
  340. package/dist/testing/adapters/ui/run-video.js +113 -0
  341. package/dist/testing/adapters/ui/run-video.js.map +1 -0
  342. package/dist/testing/adapters/ui/run-video.spec.d.ts +2 -0
  343. package/dist/testing/adapters/ui/run-video.spec.d.ts.map +1 -0
  344. package/dist/testing/adapters/ui/run-video.spec.js +62 -0
  345. package/dist/testing/adapters/ui/run-video.spec.js.map +1 -0
  346. package/dist/testing/contracts/testing-metadata.types.d.ts +1 -0
  347. package/dist/testing/contracts/testing-metadata.types.d.ts.map +1 -1
  348. package/dist/testing/contracts/testing-metadata.types.js.map +1 -1
  349. package/dist/testing/core/testing-engine.d.ts +1 -1
  350. package/dist/testing/core/testing-engine.d.ts.map +1 -1
  351. package/dist/testing/core/testing-engine.js +22 -4
  352. package/dist/testing/core/testing-engine.js.map +1 -1
  353. package/dist/testing/reporter/lifecycle-events.types.d.ts +1 -1
  354. package/dist/testing/reporter/lifecycle-events.types.d.ts.map +1 -1
  355. package/dist/testing/reporter/lifecycle-events.types.js.map +1 -1
  356. package/dist/testing/reporter/lifecycle-webhook-reporter.d.ts.map +1 -1
  357. package/dist/testing/reporter/lifecycle-webhook-reporter.js +2 -0
  358. package/dist/testing/reporter/lifecycle-webhook-reporter.js.map +1 -1
  359. package/dist/testing/runner/read-scenarios-file.d.ts +1 -0
  360. package/dist/testing/runner/read-scenarios-file.d.ts.map +1 -1
  361. package/dist/testing/runner/read-scenarios-file.js +20 -0
  362. package/dist/testing/runner/read-scenarios-file.js.map +1 -1
  363. package/dist/testing/runner/run-from-metadata.d.ts.map +1 -1
  364. package/dist/testing/runner/run-from-metadata.js +9 -1
  365. package/dist/testing/runner/run-from-metadata.js.map +1 -1
  366. package/dist/testing/runner/run-from-metadata.spec.js +12 -1
  367. package/dist/testing/runner/run-from-metadata.spec.js.map +1 -1
  368. package/dist/transformers/typeorm/bigint-to-number-transformer.d.ts +3 -0
  369. package/dist/transformers/typeorm/bigint-to-number-transformer.d.ts.map +1 -0
  370. package/dist/transformers/typeorm/bigint-to-number-transformer.js +8 -0
  371. package/dist/transformers/typeorm/bigint-to-number-transformer.js.map +1 -0
  372. package/package.json +2 -1
  373. package/postman/media-migration.postman_collection.json +519 -0
  374. package/postman/media-migration.test.postman_collection.json +1013 -0
  375. package/resources/agent-embed/solid-agent-embed.js +244 -4
  376. package/src/constants/error-messages.ts +2 -1
  377. package/src/controllers/agent-registry.controller.ts +8 -1
  378. package/src/controllers/agent-session.controller.ts +37 -2
  379. package/src/controllers/media-migration-item.controller.ts +32 -0
  380. package/src/controllers/media-migration-job.controller.ts +32 -0
  381. package/src/controllers/media-migration.controller.spec.ts +85 -0
  382. package/src/controllers/media-migration.controller.ts +123 -0
  383. package/src/controllers/test-data.controller.spec.ts +94 -0
  384. package/src/controllers/test-data.controller.ts +58 -0
  385. package/src/dtos/create-agent-job.dto.ts +6 -0
  386. package/src/dtos/create-agent-process.dto.ts +32 -1
  387. package/src/dtos/create-agent-registry.dto.ts +34 -1
  388. package/src/dtos/create-agent-session.dto.ts +1 -1
  389. package/src/dtos/create-media-migration.dto.ts +95 -0
  390. package/src/dtos/create-media-storage-provider-metadata.dto.spec.ts +35 -0
  391. package/src/dtos/create-media-storage-provider-metadata.dto.ts +9 -0
  392. package/src/dtos/test-run-request.dto.ts +6 -0
  393. package/src/dtos/update-agent-deployment.dto.ts +37 -0
  394. package/src/dtos/update-agent-job.dto.ts +6 -0
  395. package/src/dtos/update-agent-process.dto.ts +32 -1
  396. package/src/dtos/update-agent-registry.dto.ts +34 -1
  397. package/src/dtos/update-agent-session.dto.ts +1 -1
  398. package/src/entities/agent-job.entity.ts +5 -1
  399. package/src/entities/agent-process.entity.ts +28 -0
  400. package/src/entities/agent-registry.entity.ts +15 -0
  401. package/src/entities/agent-session.entity.ts +3 -0
  402. package/src/entities/media-migration-item.entity.ts +67 -0
  403. package/src/entities/media-migration-job.entity.ts +103 -0
  404. package/src/helpers/agent-config-version-name.spec.ts +35 -0
  405. package/src/helpers/agent-config-version-name.ts +16 -0
  406. package/src/helpers/typeorm-db-helper.ts +12 -0
  407. package/src/index.ts +8 -0
  408. package/src/jobs/database/media-migration-publisher-database.service.ts +24 -0
  409. package/src/jobs/database/media-migration-queue-options-database.ts +9 -0
  410. package/src/jobs/database/media-migration-subscriber-database.service.ts +37 -0
  411. package/src/jobs/database/test-run-queue-subscriber-database.service.ts +10 -6
  412. package/src/jobs/media-migration-queues.spec.ts +53 -0
  413. package/src/jobs/rabbitmq/media-migration-publisher.service.ts +24 -0
  414. package/src/jobs/rabbitmq/media-migration-queue-options.ts +9 -0
  415. package/src/jobs/rabbitmq/media-migration-subscriber.service.ts +31 -0
  416. package/src/jobs/redis/media-migration-publisher-redis.service.ts +24 -0
  417. package/src/jobs/redis/media-migration-queue-options-redis.ts +9 -0
  418. package/src/jobs/redis/media-migration-subscriber-redis.service.ts +31 -0
  419. package/src/repository/media-migration-item.repository.ts +17 -0
  420. package/src/repository/media-migration-job.repository.ts +17 -0
  421. package/src/seeders/media-migration-metadata.spec.ts +97 -0
  422. package/src/seeders/module-test-data.service.spec.ts +184 -0
  423. package/src/seeders/module-test-data.service.ts +136 -20
  424. package/src/seeders/seed-data/solid-core-metadata.json +2565 -1162
  425. package/src/services/agent-hub-process-manager.service.ts +25 -4
  426. package/src/services/agent-registry.service.ts +35 -2
  427. package/src/services/crud.service.ts +30 -2
  428. package/src/services/file/disk-file.service.ts +16 -0
  429. package/src/services/file/file-service.interface.ts +2 -0
  430. package/src/services/file/multipart-part-size.spec.ts +26 -0
  431. package/src/services/file/multipart-part-size.ts +18 -0
  432. package/src/services/file/s3-file.service.spec.ts +65 -0
  433. package/src/services/file/s3-file.service.ts +56 -15
  434. package/src/services/media-download-url.service.spec.ts +62 -0
  435. package/src/services/media-download-url.service.ts +33 -2
  436. package/src/services/media-file-storage.service.spec.ts +51 -0
  437. package/src/services/media-file-storage.service.ts +75 -0
  438. package/src/services/media-migration/media-location.spec.ts +130 -0
  439. package/src/services/media-migration/media-location.ts +149 -0
  440. package/src/services/media-migration/media-migration-runner.service.ts +563 -0
  441. package/src/services/media-migration/media-migration-scope.ts +136 -0
  442. package/src/services/media-migration/media-migration.integration.spec.ts +802 -0
  443. package/src/services/media-migration/media-migration.service.ts +576 -0
  444. package/src/services/media-migration/media-transfer.service.spec.ts +288 -0
  445. package/src/services/media-migration/media-transfer.service.ts +285 -0
  446. package/src/services/media-migration/migration-error.spec.ts +41 -0
  447. package/src/services/media-migration/migration-error.ts +70 -0
  448. package/src/services/media-migration-item.service.ts +20 -0
  449. package/src/services/media-migration-job.service.ts +20 -0
  450. package/src/services/media-storage-provider-changes.spec.ts +55 -0
  451. package/src/services/media-storage-provider-changes.ts +70 -0
  452. package/src/services/media-storage-provider-metadata.service.spec.ts +99 -0
  453. package/src/services/media-storage-provider-metadata.service.ts +71 -4
  454. package/src/services/media.service.ts +10 -50
  455. package/src/services/mediaStorageProviders/file-s3-storage-provider.spec.ts +69 -0
  456. package/src/services/mediaStorageProviders/file-s3-storage-provider.ts +40 -30
  457. package/src/services/mediaStorageProviders/file-storage-provider.ts +8 -9
  458. package/src/services/settings/default-settings-provider.service.ts +11 -1
  459. package/src/solid-core.module.ts +41 -0
  460. package/src/testing/adapters/ui/browser-provisioner.spec.ts +131 -0
  461. package/src/testing/adapters/ui/browser-provisioner.ts +85 -2
  462. package/src/testing/adapters/ui/playwright-adapter.ts +48 -10
  463. package/src/testing/adapters/ui/run-video.spec.ts +72 -0
  464. package/src/testing/adapters/ui/run-video.ts +122 -0
  465. package/src/testing/contracts/testing-metadata.types.ts +5 -0
  466. package/src/testing/core/testing-engine.ts +28 -5
  467. package/src/testing/reporter/lifecycle-events.types.ts +2 -1
  468. package/src/testing/reporter/lifecycle-webhook-reporter.ts +1 -0
  469. package/src/testing/runner/read-scenarios-file.ts +24 -0
  470. package/src/testing/runner/run-from-metadata.spec.ts +15 -1
  471. package/src/testing/runner/run-from-metadata.ts +13 -5
  472. package/src/transformers/typeorm/bigint-to-number-transformer.ts +7 -0
@@ -0,0 +1,468 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ var MediaMigrationService_1;
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.MediaMigrationService = exports.CLEANUP_TARGET_CONFIRMATION = exports.CLEANUP_SOURCE_CONFIRMATION = void 0;
17
+ const common_1 = require("@nestjs/common");
18
+ const config_1 = require("@nestjs/config");
19
+ const typeorm_1 = require("@nestjs/typeorm");
20
+ const typeorm_2 = require("typeorm");
21
+ const create_media_storage_provider_metadata_dto_1 = require("../../dtos/create-media-storage-provider-metadata.dto");
22
+ const field_metadata_entity_1 = require("../../entities/field-metadata.entity");
23
+ const media_entity_1 = require("../../entities/media.entity");
24
+ const media_migration_item_entity_1 = require("../../entities/media-migration-item.entity");
25
+ const media_migration_job_entity_1 = require("../../entities/media-migration-job.entity");
26
+ const media_storage_provider_metadata_entity_1 = require("../../entities/media-storage-provider-metadata.entity");
27
+ const model_metadata_entity_1 = require("../../entities/model-metadata.entity");
28
+ const publisher_factory_service_1 = require("../queues/publisher-factory.service");
29
+ const media_location_1 = require("./media-location");
30
+ const migration_error_1 = require("./migration-error");
31
+ const media_transfer_service_1 = require("./media-transfer.service");
32
+ const media_migration_scope_1 = require("./media-migration-scope");
33
+ exports.CLEANUP_SOURCE_CONFIRMATION = 'DELETE_SOURCE_FILES';
34
+ exports.CLEANUP_TARGET_CONFIRMATION = 'DELETE_TARGET_FILES';
35
+ const ACTIVE_STATUSES = ['pending', 'running', 'cancelling'];
36
+ const DEFAULT_BATCH_SIZE = 200;
37
+ const DEFAULT_CONCURRENCY = 4;
38
+ function unique(values) {
39
+ return [...new Set(values)];
40
+ }
41
+ let MediaMigrationService = MediaMigrationService_1 = class MediaMigrationService {
42
+ constructor(dataSource, transfer, configService, publisherFactory) {
43
+ this.dataSource = dataSource;
44
+ this.transfer = transfer;
45
+ this.configService = configService;
46
+ this.publisherFactory = publisherFactory;
47
+ this.logger = new common_1.Logger(MediaMigrationService_1.name);
48
+ }
49
+ async preview(request) {
50
+ const { source, target, scope } = await this.validate(request, { checkActiveJobs: false });
51
+ const sourceLocationKind = source.type;
52
+ const sameBucket = source.type === create_media_storage_provider_metadata_dto_1.MediaStorageProviderType.AwsS3 && target.type === create_media_storage_provider_metadata_dto_1.MediaStorageProviderType.AwsS3
53
+ && source.bucketName === target.bucketName;
54
+ await this.checkBuckets(source, target);
55
+ const rowsQuery = (0, media_migration_scope_1.scopedMediaQuery)(this.dataSource, scope);
56
+ const totalMediaRows = await rowsQuery.getCount();
57
+ const fileRows = await (0, media_migration_scope_1.scopedMediaQuery)(this.dataSource, scope)
58
+ .select('media.relativeUri', 'relativeUri')
59
+ .addSelect('scopeField.id', 'fieldId')
60
+ .addSelect('MAX(media.fileSize)', 'size')
61
+ .groupBy('media.relativeUri')
62
+ .addGroupBy('scopeField.id')
63
+ .getRawMany();
64
+ const distinctFiles = new Map();
65
+ const byFieldMap = new Map();
66
+ for (const row of fileRows) {
67
+ const size = Number(row.size ?? 0);
68
+ distinctFiles.set(row.relativeUri, size);
69
+ const field = byFieldMap.get(Number(row.fieldId)) ?? { files: 0, bytes: 0 };
70
+ field.files += 1;
71
+ field.bytes += size;
72
+ byFieldMap.set(Number(row.fieldId), field);
73
+ }
74
+ const fieldIds = [...byFieldMap.keys()];
75
+ const fields = fieldIds.length
76
+ ? await this.dataSource.getRepository(field_metadata_entity_1.FieldMetadata).find({ where: { id: (0, typeorm_2.In)(fieldIds) }, relations: ['model'] })
77
+ : [];
78
+ const fieldById = new Map(fields.map(field => [field.id, field]));
79
+ const byField = fieldIds.map(fieldId => {
80
+ const field = fieldById.get(fieldId);
81
+ return {
82
+ fieldMetadataId: fieldId,
83
+ fieldName: field?.name,
84
+ modelName: field?.model?.singularName,
85
+ files: byFieldMap.get(fieldId).files,
86
+ bytes: byFieldMap.get(fieldId).bytes,
87
+ };
88
+ });
89
+ const collisions = (0, media_location_1.findTargetKeyCollisions)(distinctFiles.keys());
90
+ const sharedOutside = await (0, media_migration_scope_1.countSharedRowsOutsideScope)(this.dataSource, scope);
91
+ const nullSizeRows = await (0, media_migration_scope_1.scopedMediaQuery)(this.dataSource, scope).andWhere('media.fileSize IS NULL').getCount();
92
+ const warnings = [];
93
+ if (sameBucket) {
94
+ warnings.push('No files are copied. S3 access is controlled by the bucket policy; this only changes how URLs are generated.');
95
+ }
96
+ if (source.isPublic === false && target.isPublic !== false) {
97
+ warnings.push('Files from a private provider will become publicly reachable.');
98
+ }
99
+ if (sharedOutside > 0) {
100
+ warnings.push(`${sharedOutside} media row(s) outside this scope use the same files. They will be moved too.`);
101
+ }
102
+ if (collisions.length > 0) {
103
+ warnings.push(`${collisions.length} target file name(s) are shared by different source files. The migration will fail for those files until they are renamed.`);
104
+ }
105
+ if (nullSizeRows > 0) {
106
+ warnings.push(`${nullSizeRows} media row(s) have no recorded size, so they are not included in the byte total.`);
107
+ }
108
+ const fieldsOnSourceProvider = await (0, media_migration_scope_1.findMediaFieldsOnProvider)(this.dataSource, scope);
109
+ return {
110
+ sourceProvider: source.name,
111
+ targetProvider: target.name,
112
+ sourceType: sourceLocationKind,
113
+ sameLocation: sameBucket,
114
+ totalFiles: distinctFiles.size,
115
+ totalMediaRows,
116
+ totalBytes: [...distinctFiles.values()].reduce((sum, size) => sum + size, 0),
117
+ byField,
118
+ fieldsOnSourceProvider,
119
+ collisions,
120
+ warnings,
121
+ };
122
+ }
123
+ async create(request) {
124
+ const { source, target, scope, options } = await this.validate(request);
125
+ await this.checkBuckets(source, target);
126
+ const defaultRegion = this.defaultRegion();
127
+ await this.transfer.probeWritable((0, media_location_1.resolveLocation)(target, 'probe', defaultRegion)).catch(error => {
128
+ throw new common_1.BadRequestException(error instanceof migration_error_1.MigrationError ? error.message : String(error));
129
+ });
130
+ const preview = await this.preview(request);
131
+ const jobRepo = this.dataSource.getRepository(media_migration_job_entity_1.MediaMigrationJob);
132
+ const job = await jobRepo.save(jobRepo.create({
133
+ sourceProvider: source,
134
+ targetProvider: target,
135
+ modelMetadataIds: scope.modelMetadataIds?.length ? scope.modelMetadataIds : null,
136
+ fieldMetadataIds: scope.fieldMetadataIds?.length ? scope.fieldMetadataIds : null,
137
+ status: 'pending',
138
+ overwriteExisting: options.overwriteExisting,
139
+ batchSize: options.batchSize,
140
+ concurrency: options.concurrency,
141
+ totalCount: preview.totalFiles,
142
+ totalBytes: preview.totalBytes,
143
+ warnings: preview.warnings,
144
+ }));
145
+ try {
146
+ await this.publish(job.id);
147
+ }
148
+ catch (error) {
149
+ const reason = `The job could not be queued: ${error?.message ?? error}`;
150
+ await this.updateJob(job.id, { status: 'failed', finishedAt: new Date(), errorMessage: reason });
151
+ throw new common_1.BadRequestException(`${reason} Check the queue settings (QUEUES_DEFAULT_BROKER and QUEUES_SERVICE_ROLE) and try again.`);
152
+ }
153
+ this.logger.log(`Queued media migration job ${job.id} (${source.name} -> ${target.name})`);
154
+ return job;
155
+ }
156
+ async cancel(jobId) {
157
+ const job = await this.loadJob(jobId);
158
+ const repo = this.dataSource.getRepository(media_migration_job_entity_1.MediaMigrationJob);
159
+ const cancelled = { status: 'cancelled', finishedAt: new Date(), leaseToken: null, leaseExpiresAt: null };
160
+ if (job.status === 'pending') {
161
+ const result = await repo.update({ id: jobId, status: 'pending' }, cancelled);
162
+ if ((result.affected ?? 0) === 0) {
163
+ return this.cancel(jobId);
164
+ }
165
+ }
166
+ else if (job.status === 'running' || job.status === 'cancelling') {
167
+ if (this.hasLiveWorker(job)) {
168
+ await repo.update({ id: jobId, status: (0, typeorm_2.In)(['running', 'cancelling']) }, { status: 'cancelling' });
169
+ }
170
+ else {
171
+ await repo.update({ id: jobId, status: (0, typeorm_2.In)(['running', 'cancelling']) }, cancelled);
172
+ }
173
+ }
174
+ else {
175
+ throw new common_1.BadRequestException(`Job #${jobId} is ${job.status} and cannot be cancelled.`);
176
+ }
177
+ return this.loadJob(jobId);
178
+ }
179
+ hasLiveWorker(job) {
180
+ return !!job.leaseToken && !!job.leaseExpiresAt && job.leaseExpiresAt > new Date();
181
+ }
182
+ async resume(jobId) {
183
+ const job = await this.loadJob(jobId);
184
+ const orphaned = ['running', 'cancelling'].includes(job.status) && !this.hasLiveWorker(job);
185
+ if (!['failed', 'cancelled', 'pending'].includes(job.status) && !orphaned) {
186
+ throw new common_1.BadRequestException(`Job #${jobId} is ${job.status} and cannot be resumed.`);
187
+ }
188
+ if (job.status !== 'pending') {
189
+ await this.updateJob(jobId, { status: 'pending', errorMessage: null, leaseToken: null, leaseExpiresAt: null });
190
+ }
191
+ await this.publish(jobId);
192
+ return this.loadJob(jobId);
193
+ }
194
+ async retryFailed(jobId) {
195
+ const job = await this.loadJob(jobId);
196
+ if (!['completed_with_errors', 'failed'].includes(job.status)) {
197
+ throw new common_1.BadRequestException(`Job #${jobId} is ${job.status}. Only jobs that finished with failures can be retried.`);
198
+ }
199
+ await this.dataSource.getRepository(media_migration_item_entity_1.MediaMigrationItem).update({ job: { id: jobId }, status: 'failed' }, { status: 'pending', errorCode: null, errorMessage: null });
200
+ await this.updateJob(jobId, { status: 'pending', lastProcessedMediaId: 0, errorMessage: null, finishedAt: null });
201
+ await this.publish(jobId);
202
+ return this.loadJob(jobId);
203
+ }
204
+ async rollback(jobId) {
205
+ const job = await this.loadJob(jobId);
206
+ if (!['completed', 'completed_with_errors', 'cancelled'].includes(job.status)) {
207
+ throw new common_1.BadRequestException(`Job #${jobId} is ${job.status}. Rollback needs a finished job.`);
208
+ }
209
+ const removed = await this.dataSource.getRepository(media_migration_item_entity_1.MediaMigrationItem).count({ where: { job: { id: jobId }, status: 'source_deleted' } });
210
+ if (removed > 0) {
211
+ throw new common_1.BadRequestException(`Job #${jobId} already removed ${removed} source file(s), so it cannot be rolled back. ` +
212
+ `To move the files back, run a new migration from the target provider to the source provider.`);
213
+ }
214
+ const completed = await this.dataSource.getRepository(media_migration_item_entity_1.MediaMigrationItem).find({ where: { job: { id: jobId }, status: 'completed' } });
215
+ for (const item of completed) {
216
+ await this.dataSource.transaction(async (manager) => {
217
+ const rows = await manager.getRepository(media_entity_1.Media).createQueryBuilder('media').withDeleted()
218
+ .innerJoin('media.mediaStorageProviderMetadata', 'provider')
219
+ .where('provider.id = :targetId', { targetId: job.targetProvider.id })
220
+ .andWhere('media.id IN (:...ids)', { ids: item.mediaIds.length ? item.mediaIds : [0] })
221
+ .select(['media.id'])
222
+ .getMany();
223
+ if (rows.length > 0) {
224
+ await manager.createQueryBuilder()
225
+ .update(media_entity_1.Media)
226
+ .set({ mediaStorageProviderMetadata: { id: job.sourceProvider.id }, relativeUri: item.sourceKey })
227
+ .where('id IN (:...ids)', { ids: rows.map(row => row.id) })
228
+ .execute();
229
+ }
230
+ await manager.getRepository(media_migration_item_entity_1.MediaMigrationItem).update({ id: item.id }, { status: 'rolled_back' });
231
+ });
232
+ }
233
+ await this.updateJob(jobId, {
234
+ status: 'rolled_back',
235
+ finishedAt: new Date(),
236
+ });
237
+ const targetFilesLeft = await this.dataSource.getRepository(media_migration_item_entity_1.MediaMigrationItem).count({ where: { job: { id: jobId }, copied: true } });
238
+ return { job: await this.loadJob(jobId), targetFilesLeft };
239
+ }
240
+ async cleanup(jobId, confirm) {
241
+ const job = await this.loadJob(jobId);
242
+ if (['completed', 'completed_with_errors'].includes(job.status)) {
243
+ this.assertConfirmation(confirm, exports.CLEANUP_SOURCE_CONFIRMATION, 'source');
244
+ return { side: 'source', ...await this.cleanupSourceFiles(job) };
245
+ }
246
+ if (job.status === 'rolled_back') {
247
+ this.assertConfirmation(confirm, exports.CLEANUP_TARGET_CONFIRMATION, 'target');
248
+ return { side: 'target', ...await this.cleanupTargetFiles(job) };
249
+ }
250
+ throw new common_1.BadRequestException(`Job #${jobId} is ${job.status}. Files can only be removed after the job has finished or been rolled back.`);
251
+ }
252
+ assertConfirmation(confirm, expected, side) {
253
+ if (confirm !== expected) {
254
+ throw new common_1.BadRequestException(`Deleting ${side} files for this job needs confirm: "${expected}" in the request body.`);
255
+ }
256
+ }
257
+ async cleanupTargetFiles(job) {
258
+ const defaultRegion = this.defaultRegion();
259
+ const items = await this.dataSource.getRepository(media_migration_item_entity_1.MediaMigrationItem).find({ where: { job: { id: job.id }, status: 'rolled_back', copied: true } });
260
+ const skipped = [];
261
+ let deleted = 0;
262
+ for (const item of items) {
263
+ try {
264
+ const source = (0, media_location_1.resolveLocation)(job.sourceProvider, item.sourceKey, defaultRegion);
265
+ const target = (0, media_location_1.resolveLocation)(job.targetProvider, item.targetKey ?? item.sourceKey, defaultRegion);
266
+ if ((0, media_location_1.sameLocation)(source, target)) {
267
+ skipped.push({ itemId: item.id, reason: 'Source and target are the same stored file.' });
268
+ continue;
269
+ }
270
+ const sourceStat = await this.transfer.stat(source, 'source');
271
+ if (!sourceStat || (item.sourceSize !== null && item.sourceSize !== undefined && sourceStat.size !== item.sourceSize)) {
272
+ skipped.push({ itemId: item.id, reason: 'The source file is missing or has a different size, so the target copy may be the only good one.' });
273
+ continue;
274
+ }
275
+ const stillUsed = await (0, media_migration_scope_1.rowsUsingLocation)(this.dataSource, target, defaultRegion);
276
+ if (stillUsed.length > 0) {
277
+ skipped.push({ itemId: item.id, reason: `${stillUsed.length} media row(s) still use the target file.` });
278
+ continue;
279
+ }
280
+ await this.transfer.delete(target, 'target');
281
+ await this.dataSource.getRepository(media_migration_item_entity_1.MediaMigrationItem).update({ id: item.id }, { status: 'target_deleted' });
282
+ deleted += 1;
283
+ }
284
+ catch (error) {
285
+ skipped.push({ itemId: item.id, reason: error instanceof migration_error_1.MigrationError ? error.message : (error?.message ?? String(error)) });
286
+ }
287
+ }
288
+ return { deleted, skipped };
289
+ }
290
+ async cleanupSourceFiles(job) {
291
+ const jobId = job.id;
292
+ const defaultRegion = this.defaultRegion();
293
+ const items = await this.dataSource.getRepository(media_migration_item_entity_1.MediaMigrationItem).find({ where: { job: { id: jobId }, status: 'completed' } });
294
+ const skipped = [];
295
+ let deleted = 0;
296
+ for (const item of items) {
297
+ try {
298
+ const source = (0, media_location_1.resolveLocation)(job.sourceProvider, item.sourceKey, defaultRegion);
299
+ const target = (0, media_location_1.resolveLocation)(job.targetProvider, item.targetKey ?? item.sourceKey, defaultRegion);
300
+ if ((0, media_location_1.sameLocation)(source, target)) {
301
+ skipped.push({ itemId: item.id, reason: 'Source and target are the same stored file.' });
302
+ continue;
303
+ }
304
+ if (item.targetSize === null || item.targetSize === undefined) {
305
+ skipped.push({ itemId: item.id, reason: 'The target size was not recorded, so the copy cannot be verified.' });
306
+ continue;
307
+ }
308
+ const targetStat = await this.transfer.stat(target, 'target');
309
+ if (!targetStat || targetStat.size !== item.targetSize) {
310
+ skipped.push({ itemId: item.id, reason: 'The target copy is missing or has a different size.' });
311
+ continue;
312
+ }
313
+ const stillUsed = await (0, media_migration_scope_1.rowsUsingLocation)(this.dataSource, source, defaultRegion);
314
+ if (stillUsed.length > 0) {
315
+ skipped.push({ itemId: item.id, reason: `${stillUsed.length} media row(s) still use the source file.` });
316
+ continue;
317
+ }
318
+ await this.transfer.delete(source, 'source');
319
+ await this.dataSource.getRepository(media_migration_item_entity_1.MediaMigrationItem).update({ id: item.id }, { status: 'source_deleted' });
320
+ deleted += 1;
321
+ }
322
+ catch (error) {
323
+ skipped.push({ itemId: item.id, reason: error instanceof migration_error_1.MigrationError ? error.message : (error?.message ?? String(error)) });
324
+ }
325
+ }
326
+ return { deleted, skipped };
327
+ }
328
+ async validate(request, options = { checkActiveJobs: true }) {
329
+ if (request.entityIds !== undefined) {
330
+ throw new common_1.BadRequestException('entityIds is no longer supported. Scope a migration by modelMetadataIds or fieldMetadataIds. ' +
331
+ 'To try a migration first, move one small field and roll it back if anything looks wrong.');
332
+ }
333
+ const source = await this.findProvider(request.sourceProviderId, request.sourceProviderName, 'source');
334
+ const target = await this.findProvider(request.targetProviderId, request.targetProviderName, 'target');
335
+ if (source.id === target.id) {
336
+ throw new common_1.BadRequestException('The source and target provider are the same. Choose a different target.');
337
+ }
338
+ for (const provider of [source, target]) {
339
+ if (![create_media_storage_provider_metadata_dto_1.MediaStorageProviderType.Filesystem, create_media_storage_provider_metadata_dto_1.MediaStorageProviderType.AwsS3].includes(provider.type)) {
340
+ throw new common_1.BadRequestException(`Provider "${provider.name}" is of type "${provider.type}", which cannot be migrated. Use filesystem or aws-s3.`);
341
+ }
342
+ if (provider.type === create_media_storage_provider_metadata_dto_1.MediaStorageProviderType.AwsS3 && (!process.env.S3_AWS_ACCESS_KEY || !process.env.S3_AWS_SECRET_KEY)) {
343
+ throw new common_1.BadRequestException('S3_AWS_ACCESS_KEY and S3_AWS_SECRET_KEY must be set to migrate to or from S3.');
344
+ }
345
+ try {
346
+ (0, media_location_1.resolveLocation)(provider, 'check', this.defaultRegion());
347
+ }
348
+ catch (error) {
349
+ throw new common_1.BadRequestException(error instanceof migration_error_1.MigrationError ? error.message : String(error));
350
+ }
351
+ }
352
+ const byKey = await this.resolveUserKeys(request);
353
+ const modelIds = unique([...(request.modelMetadataIds ?? []), ...byKey.modelIds]);
354
+ const fieldIds = unique([...(request.fieldMetadataIds ?? []), ...byKey.fieldIds]);
355
+ const scope = {
356
+ sourceProviderId: source.id,
357
+ modelMetadataIds: modelIds.length ? modelIds : null,
358
+ fieldMetadataIds: fieldIds.length ? fieldIds : null,
359
+ };
360
+ await this.assertScopeExists(scope);
361
+ const active = options.checkActiveJobs
362
+ ? await this.dataSource.getRepository(media_migration_job_entity_1.MediaMigrationJob).findOne({
363
+ where: { sourceProvider: { id: source.id }, status: (0, typeorm_2.In)(ACTIVE_STATUSES) },
364
+ })
365
+ : null;
366
+ if (active) {
367
+ throw new common_1.BadRequestException(`Migration job #${active.id} is already ${active.status} for provider "${source.name}". Wait for it to finish or cancel it.`);
368
+ }
369
+ const clamp = (value, fallback, min, max) => Math.min(max, Math.max(min, Math.floor(value ?? fallback)));
370
+ return {
371
+ source,
372
+ target,
373
+ scope,
374
+ options: {
375
+ overwriteExisting: request.overwriteExisting ?? false,
376
+ batchSize: clamp(request.batchSize, DEFAULT_BATCH_SIZE, 10, 1000),
377
+ concurrency: clamp(request.concurrency, DEFAULT_CONCURRENCY, 1, 16),
378
+ },
379
+ };
380
+ }
381
+ async findProvider(id, name, role) {
382
+ const repo = this.dataSource.getRepository(media_storage_provider_metadata_entity_1.MediaStorageProviderMetadata);
383
+ const provider = id
384
+ ? await repo.findOne({ where: { id } })
385
+ : name ? await repo.findOne({ where: { name } }) : null;
386
+ if (!provider) {
387
+ throw new common_1.BadRequestException(`Choose a ${role} provider by id or name. "${id ?? name ?? ''}" was not found.`);
388
+ }
389
+ return provider;
390
+ }
391
+ async resolveUserKeys(request) {
392
+ const modelKeys = unique(request.modelUserKeys ?? []);
393
+ const modelIds = [];
394
+ if (modelKeys.length) {
395
+ const models = await this.dataSource.getRepository(model_metadata_entity_1.ModelMetadata).find({ where: { singularName: (0, typeorm_2.In)(modelKeys) } });
396
+ const found = new Set(models.map(model => model.singularName));
397
+ const missing = modelKeys.filter(key => !found.has(key));
398
+ if (missing.length) {
399
+ throw new common_1.BadRequestException(`Unknown model userKey: ${missing.map(key => `"${key}"`).join(', ')}. A model's userKey is its singularName.`);
400
+ }
401
+ modelIds.push(...models.map(model => model.id));
402
+ }
403
+ const fieldIds = [];
404
+ for (const ref of request.fieldUserKeys ?? []) {
405
+ const field = await this.dataSource.getRepository(field_metadata_entity_1.FieldMetadata).findOne({
406
+ where: { name: ref.fieldUserKey, model: { singularName: ref.modelUserKey } },
407
+ });
408
+ if (!field) {
409
+ throw new common_1.BadRequestException(`Unknown field userKey "${ref.fieldUserKey}" on model "${ref.modelUserKey}".`);
410
+ }
411
+ fieldIds.push(field.id);
412
+ }
413
+ return { modelIds, fieldIds: unique(fieldIds) };
414
+ }
415
+ async assertScopeExists(scope) {
416
+ const checks = [
417
+ ['model', scope.modelMetadataIds, model_metadata_entity_1.ModelMetadata],
418
+ ['field', scope.fieldMetadataIds, field_metadata_entity_1.FieldMetadata],
419
+ ];
420
+ for (const [label, ids, entity] of checks) {
421
+ if (!ids?.length)
422
+ continue;
423
+ const found = await this.dataSource.getRepository(entity).count({ where: { id: (0, typeorm_2.In)(ids) } });
424
+ if (found !== new Set(ids).size) {
425
+ throw new common_1.BadRequestException(`Some ${label} ids in the scope do not exist.`);
426
+ }
427
+ }
428
+ }
429
+ async checkBuckets(source, target) {
430
+ for (const [provider, role] of [[source, 'source'], [target, 'target']]) {
431
+ if (provider.type !== create_media_storage_provider_metadata_dto_1.MediaStorageProviderType.AwsS3)
432
+ continue;
433
+ await this.transfer.assertBucketReachable((0, media_location_1.resolveLocation)(provider, 'check', this.defaultRegion()), role)
434
+ .catch(error => {
435
+ throw new common_1.BadRequestException(error instanceof migration_error_1.MigrationError ? error.message : String(error));
436
+ });
437
+ }
438
+ }
439
+ defaultRegion() {
440
+ return this.configService.get('S3_AWS_REGION_NAME') || undefined;
441
+ }
442
+ async loadJob(jobId) {
443
+ const job = await this.dataSource.getRepository(media_migration_job_entity_1.MediaMigrationJob).findOne({
444
+ where: { id: jobId },
445
+ relations: ['sourceProvider', 'targetProvider'],
446
+ });
447
+ if (!job) {
448
+ throw new common_1.NotFoundException(`Media migration job #${jobId} not found`);
449
+ }
450
+ return job;
451
+ }
452
+ async publish(jobId) {
453
+ await this.publisherFactory.publish({ payload: { jobId } }, 'MediaMigrationPublisher');
454
+ }
455
+ async updateJob(jobId, fields) {
456
+ await this.dataSource.getRepository(media_migration_job_entity_1.MediaMigrationJob).update({ id: jobId }, fields);
457
+ }
458
+ };
459
+ exports.MediaMigrationService = MediaMigrationService;
460
+ exports.MediaMigrationService = MediaMigrationService = MediaMigrationService_1 = __decorate([
461
+ (0, common_1.Injectable)(),
462
+ __param(0, (0, typeorm_1.InjectDataSource)()),
463
+ __metadata("design:paramtypes", [typeorm_2.DataSource,
464
+ media_transfer_service_1.MediaTransferService,
465
+ config_1.ConfigService,
466
+ publisher_factory_service_1.PublisherFactory])
467
+ ], MediaMigrationService);
468
+ //# sourceMappingURL=media-migration.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"media-migration.service.js","sourceRoot":"","sources":["../../../src/services/media-migration/media-migration.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAA4F;AAC5F,2CAA+C;AAC/C,6CAAmD;AACnD,qCAAyC;AACzC,sHAA+F;AAC/F,gFAAmE;AACnE,8DAAkD;AAClD,4FAA8E;AAC9E,0FAAqG;AACrG,kHAAmG;AACnG,gFAAmE;AACnE,mFAAiF;AACjF,qDAA8G;AAC9G,uDAAmD;AACnD,qEAAgE;AAChE,mEAAsJ;AAIzI,QAAA,2BAA2B,GAAG,qBAAqB,CAAC;AACpD,QAAA,2BAA2B,GAAG,qBAAqB,CAAC;AAEjE,MAAM,eAAe,GAA8B,CAAC,SAAS,EAAE,SAAS,EAAE,YAAY,CAAC,CAAC;AACxF,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAC/B,MAAM,mBAAmB,GAAG,CAAC,CAAC;AA8B9B,SAAS,MAAM,CAAI,MAAW;IAC5B,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;AAC9B,CAAC;AAGM,IAAM,qBAAqB,6BAA3B,MAAM,qBAAqB;IAGhC,YAEE,UAAuC,EACtB,QAA8B,EAC9B,aAA4B,EAC5B,gBAAqD;QAHrD,eAAU,GAAV,UAAU,CAAY;QACtB,aAAQ,GAAR,QAAQ,CAAsB;QAC9B,kBAAa,GAAb,aAAa,CAAe;QAC5B,qBAAgB,GAAhB,gBAAgB,CAAqC;QAPvD,WAAM,GAAG,IAAI,eAAM,CAAC,uBAAqB,CAAC,IAAI,CAAC,CAAC;IAQ7D,CAAC;IAKL,KAAK,CAAC,OAAO,CAAC,OAA8B;QAC1C,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,I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;YACzE,KAAK,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE;YACpB,SAAS,EAAE,CAAC,gBAAgB,EAAE,gBAAgB,CAAC;SAChD,CAAC,CAAC;QACH,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,MAAM,IAAI,0BAAiB,CAAC,wBAAwB,KAAK,YAAY,CAAC,CAAC;QACzE,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;IAGO,KAAK,CAAC,OAAO,CAAC,KAAa;QACjC,MAAM,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,EAAS,EAAE,yBAAyB,CAAC,CAAC;IAChG,CAAC;IAEO,KAAK,CAAC,SAAS,CAAC,KAAa,EAAE,MAAkC;QACvE,MAAM,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,8CAAiB,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,MAAa,CAAC,CAAC;IAC9F,CAAC;CACF,CAAA;AApgBY,sDAAqB;gCAArB,qBAAqB;IADjC,IAAA,mBAAU,GAAE;IAKR,WAAA,IAAA,0BAAgB,GAAE,CAAA;qCACU,oBAAU;QACZ,6CAAoB;QACf,sBAAa;QACV,4CAAgB;GAR1C,qBAAqB,CAogBjC","sourcesContent":["import { BadRequestException, Injectable, Logger, NotFoundException } from '@nestjs/common';\nimport { ConfigService } from '@nestjs/config';\nimport { InjectDataSource } from '@nestjs/typeorm';\nimport { DataSource, In } from 'typeorm';\nimport { MediaStorageProviderType } from 'src/dtos/create-media-storage-provider-metadata.dto';\nimport { FieldMetadata } from 'src/entities/field-metadata.entity';\nimport { Media } from 'src/entities/media.entity';\nimport { MediaMigrationItem } from 'src/entities/media-migration-item.entity';\nimport { MediaMigrationJob, MediaMigrationJobStatus } from 'src/entities/media-migration-job.entity';\nimport { MediaStorageProviderMetadata } from 'src/entities/media-storage-provider-metadata.entity';\nimport { ModelMetadata } from 'src/entities/model-metadata.entity';\nimport { PublisherFactory } from 'src/services/queues/publisher-factory.service';\nimport { findTargetKeyCollisions, normalizeTargetKey, resolveLocation, sameLocation } from './media-location';\nimport { MigrationError } from './migration-error';\nimport { MediaTransferService } from './media-transfer.service';\nimport { countSharedRowsOutsideScope, findMediaFieldsOnProvider, MigrationScope, rowsUsingLocation, scopedMediaQuery } from './media-migration-scope';\n\n// Cleanup deletes the files a finished job no longer needs: the source files after a migration, the\n// target copies after a rollback. The confirmation names the side so the wrong one cannot be deleted.\nexport const CLEANUP_SOURCE_CONFIRMATION = 'DELETE_SOURCE_FILES';\nexport const CLEANUP_TARGET_CONFIRMATION = 'DELETE_TARGET_FILES';\n\nconst ACTIVE_STATUSES: MediaMigrationJobStatus[] = ['pending', 'running', 'cancelling'];\nconst DEFAULT_BATCH_SIZE = 200;\nconst DEFAULT_CONCURRENCY = 4;\n\n/** A field identified by its name and the model it belongs to, since field names repeat across models. */\nexport interface FieldUserKeyRef {\n modelUserKey: string;\n fieldUserKey: string;\n}\n\nexport interface MediaMigrationRequest {\n sourceProviderId?: number;\n sourceProviderName?: string;\n targetProviderId?: number;\n targetProviderName?: string;\n modelMetadataIds?: number[];\n fieldMetadataIds?: number[];\n // The same scope by user key: a model's userKey is its singularName; a field's is its name.\n modelUserKeys?: string[];\n fieldUserKeys?: FieldUserKeyRef[];\n overwriteExisting?: boolean;\n batchSize?: number;\n concurrency?: number;\n}\n\ninterface ValidatedRequest {\n source: MediaStorageProviderMetadata;\n target: MediaStorageProviderMetadata;\n scope: MigrationScope;\n options: { overwriteExisting: boolean; batchSize: number; concurrency: number };\n}\n\nfunction unique<T>(values: T[]): T[] {\n return [...new Set(values)];\n}\n\n@Injectable()\nexport class MediaMigrationService {\n private readonly logger = new Logger(MediaMigrationService.name);\n\n constructor(\n @InjectDataSource()\n private readonly dataSource: DataSource,\n private readonly transfer: MediaTransferService,\n private readonly configService: ConfigService,\n private readonly publisherFactory: PublisherFactory<{ jobId: number }>,\n ) { }\n\n // ---- preview ----\n\n /** Counts and checks a migration without writing anything. */\n async preview(request: MediaMigrationRequest) {\n const { source, target, scope } = await this.validate(request, { checkActiveJobs: false });\n const sourceLocationKind = source.type;\n const sameBucket = source.type === MediaStorageProviderType.AwsS3 && target.type === MediaStorageProviderType.AwsS3\n && source.bucketName === target.bucketName;\n\n // Bucket checks only read, so they are safe here.\n await this.checkBuckets(source, target);\n\n const rowsQuery = scopedMediaQuery(this.dataSource, scope);\n const totalMediaRows = await rowsQuery.getCount();\n\n const fileRows: { relativeUri: string; fieldId: number; size: string | null }[] = await scopedMediaQuery(this.dataSource, scope)\n .select('media.relativeUri', 'relativeUri')\n .addSelect('scopeField.id', 'fieldId')\n .addSelect('MAX(media.fileSize)', 'size')\n .groupBy('media.relativeUri')\n .addGroupBy('scopeField.id')\n .getRawMany();\n\n const distinctFiles = new Map<string, number>();\n const byFieldMap = new Map<number, { files: number; bytes: number }>();\n for (const row of fileRows) {\n const size = Number(row.size ?? 0);\n distinctFiles.set(row.relativeUri, size);\n const field = byFieldMap.get(Number(row.fieldId)) ?? { files: 0, bytes: 0 };\n field.files += 1;\n field.bytes += size;\n byFieldMap.set(Number(row.fieldId), field);\n }\n\n const fieldIds = [...byFieldMap.keys()];\n const fields = fieldIds.length\n ? await this.dataSource.getRepository(FieldMetadata).find({ where: { id: In(fieldIds) }, relations: ['model'] })\n : [];\n const fieldById = new Map(fields.map(field => [field.id, field]));\n const byField = fieldIds.map(fieldId => {\n const field = fieldById.get(fieldId);\n return {\n fieldMetadataId: fieldId,\n fieldName: field?.name,\n modelName: field?.model?.singularName,\n files: byFieldMap.get(fieldId)!.files,\n bytes: byFieldMap.get(fieldId)!.bytes,\n };\n });\n\n const collisions = findTargetKeyCollisions(distinctFiles.keys());\n const sharedOutside = await countSharedRowsOutsideScope(this.dataSource, scope);\n const nullSizeRows = await scopedMediaQuery(this.dataSource, scope).andWhere('media.fileSize IS NULL').getCount();\n\n const warnings: string[] = [];\n if (sameBucket) {\n warnings.push('No files are copied. S3 access is controlled by the bucket policy; this only changes how URLs are generated.');\n }\n if (source.isPublic === false && target.isPublic !== false) {\n warnings.push('Files from a private provider will become publicly reachable.');\n }\n if (sharedOutside > 0) {\n warnings.push(`${sharedOutside} media row(s) outside this scope use the same files. They will be moved too.`);\n }\n if (collisions.length > 0) {\n warnings.push(`${collisions.length} target file name(s) are shared by different source files. The migration will fail for those files until they are renamed.`);\n }\n if (nullSizeRows > 0) {\n warnings.push(`${nullSizeRows} media row(s) have no recorded size, so they are not included in the byte total.`);\n }\n\n // Media fields that still store uploads on the source provider. Linking them to the target is done in\n // the metadata, outside the job, so this list is what the admin must update.\n const fieldsOnSourceProvider = await findMediaFieldsOnProvider(this.dataSource, scope);\n\n return {\n sourceProvider: source.name,\n targetProvider: target.name,\n sourceType: sourceLocationKind,\n sameLocation: sameBucket,\n totalFiles: distinctFiles.size,\n totalMediaRows,\n totalBytes: [...distinctFiles.values()].reduce((sum, size) => sum + size, 0),\n byField,\n fieldsOnSourceProvider,\n collisions,\n warnings,\n };\n }\n\n // ---- create ----\n\n /** Creates a migration job after all checks, including a write test on the target, and queues it. */\n async create(request: MediaMigrationRequest): Promise<MediaMigrationJob> {\n const { source, target, scope, options } = await this.validate(request);\n await this.checkBuckets(source, target);\n\n const defaultRegion = this.defaultRegion();\n await this.transfer.probeWritable(resolveLocation(target, 'probe', defaultRegion)).catch(error => {\n throw new BadRequestException(error instanceof MigrationError ? error.message : String(error));\n });\n\n const preview = await this.preview(request);\n const jobRepo = this.dataSource.getRepository(MediaMigrationJob);\n const job = await jobRepo.save(jobRepo.create({\n sourceProvider: source,\n targetProvider: target,\n modelMetadataIds: scope.modelMetadataIds?.length ? scope.modelMetadataIds : null,\n fieldMetadataIds: scope.fieldMetadataIds?.length ? scope.fieldMetadataIds : null,\n status: 'pending',\n overwriteExisting: options.overwriteExisting,\n batchSize: options.batchSize,\n concurrency: options.concurrency,\n totalCount: preview.totalFiles,\n totalBytes: preview.totalBytes,\n warnings: preview.warnings,\n } as any) as unknown as MediaMigrationJob);\n\n try {\n await this.publish(job.id);\n } catch (error: any) {\n // A job that was never queued would wait forever and block this provider, so close it.\n const reason = `The job could not be queued: ${error?.message ?? error}`;\n await this.updateJob(job.id, { status: 'failed', finishedAt: new Date(), errorMessage: reason });\n throw new BadRequestException(`${reason} Check the queue settings (QUEUES_DEFAULT_BROKER and QUEUES_SERVICE_ROLE) and try again.`);\n }\n this.logger.log(`Queued media migration job ${job.id} (${source.name} -> ${target.name})`);\n return job;\n }\n\n // ---- control ----\n\n /**\n * Stops a job. A pending job, or one whose worker is gone, is cancelled at once; a running one stops\n * after its current batch. Each change only applies if the job is still in the state it was read in,\n * so a worker starting at the same moment cannot undo it.\n */\n async cancel(jobId: number): Promise<MediaMigrationJob> {\n const job = await this.loadJob(jobId);\n const repo = this.dataSource.getRepository(MediaMigrationJob);\n const cancelled = { status: 'cancelled' as const, finishedAt: new Date(), leaseToken: null, leaseExpiresAt: null };\n\n if (job.status === 'pending') {\n const result = await repo.update({ id: jobId, status: 'pending' }, cancelled);\n if ((result.affected ?? 0) === 0) {\n // A worker took the job in the meantime: ask it to stop instead.\n return this.cancel(jobId);\n }\n } else if (job.status === 'running' || job.status === 'cancelling') {\n if (this.hasLiveWorker(job)) {\n await repo.update({ id: jobId, status: In(['running', 'cancelling']) }, { status: 'cancelling' });\n } else {\n // The worker is gone, so nothing would ever see a \"cancelling\" request.\n await repo.update({ id: jobId, status: In(['running', 'cancelling']) }, cancelled);\n }\n } else {\n throw new BadRequestException(`Job #${jobId} is ${job.status} and cannot be cancelled.`);\n }\n return this.loadJob(jobId);\n }\n\n // A worker is alive while it keeps renewing the job's lease.\n private hasLiveWorker(job: MediaMigrationJob): boolean {\n return !!job.leaseToken && !!job.leaseExpiresAt && job.leaseExpiresAt > new Date();\n }\n\n /**\n * Continues a job from where it stopped: a failed or cancelled job, one whose worker is gone, or a\n * pending job whose queue message never arrived (it is queued again; only one worker can run it).\n */\n async resume(jobId: number): Promise<MediaMigrationJob> {\n const job = await this.loadJob(jobId);\n const orphaned = ['running', 'cancelling'].includes(job.status) && !this.hasLiveWorker(job);\n if (!['failed', 'cancelled', 'pending'].includes(job.status) && !orphaned) {\n throw new BadRequestException(`Job #${jobId} is ${job.status} and cannot be resumed.`);\n }\n if (job.status !== 'pending') {\n // A pending job may be starting right now, so only clear the lease of one that is truly orphaned or finished.\n await this.updateJob(jobId, { status: 'pending', errorMessage: null, leaseToken: null, leaseExpiresAt: null });\n }\n await this.publish(jobId);\n return this.loadJob(jobId);\n }\n\n /** Runs again the files that failed. Files already migrated are not copied again. */\n async retryFailed(jobId: number): Promise<MediaMigrationJob> {\n const job = await this.loadJob(jobId);\n if (!['completed_with_errors', 'failed'].includes(job.status)) {\n throw new BadRequestException(`Job #${jobId} is ${job.status}. Only jobs that finished with failures can be retried.`);\n }\n await this.dataSource.getRepository(MediaMigrationItem).update(\n { job: { id: jobId }, status: 'failed' },\n { status: 'pending', errorCode: null, errorMessage: null },\n );\n await this.updateJob(jobId, { status: 'pending', lastProcessedMediaId: 0, errorMessage: null, finishedAt: null });\n await this.publish(jobId);\n return this.loadJob(jobId);\n }\n\n /**\n * Moves migrated media rows back to the source provider. Source files were never changed, so this\n * is safe until cleanup has removed them.\n */\n async rollback(jobId: number): Promise<{ job: MediaMigrationJob; targetFilesLeft: number }> {\n const job = await this.loadJob(jobId);\n if (!['completed', 'completed_with_errors', 'cancelled'].includes(job.status)) {\n throw new BadRequestException(`Job #${jobId} is ${job.status}. Rollback needs a finished job.`);\n }\n const removed = await this.dataSource.getRepository(MediaMigrationItem).count({ where: { job: { id: jobId }, status: 'source_deleted' } });\n if (removed > 0) {\n throw new BadRequestException(\n `Job #${jobId} already removed ${removed} source file(s), so it cannot be rolled back. ` +\n `To move the files back, run a new migration from the target provider to the source provider.`,\n );\n }\n\n const completed = await this.dataSource.getRepository(MediaMigrationItem).find({ where: { job: { id: jobId }, status: 'completed' } });\n for (const item of completed) {\n await this.dataSource.transaction(async manager => {\n const rows = await manager.getRepository(Media).createQueryBuilder('media').withDeleted()\n .innerJoin('media.mediaStorageProviderMetadata', 'provider')\n .where('provider.id = :targetId', { targetId: job.targetProvider.id })\n .andWhere('media.id IN (:...ids)', { ids: item.mediaIds.length ? item.mediaIds : [0] })\n .select(['media.id'])\n .getMany();\n if (rows.length > 0) {\n await manager.createQueryBuilder()\n .update(Media)\n .set({ mediaStorageProviderMetadata: { id: job.sourceProvider.id } as any, relativeUri: item.sourceKey })\n .where('id IN (:...ids)', { ids: rows.map(row => row.id) })\n .execute();\n }\n await manager.getRepository(MediaMigrationItem).update({ id: item.id }, { status: 'rolled_back' });\n });\n }\n await this.updateJob(jobId, {\n status: 'rolled_back',\n finishedAt: new Date(),\n });\n\n const targetFilesLeft = await this.dataSource.getRepository(MediaMigrationItem).count({ where: { job: { id: jobId }, copied: true } });\n return { job: await this.loadJob(jobId), targetFilesLeft };\n }\n\n /**\n * Deletes the files a finished job no longer needs. After a migration (completed) that is the source\n * files; after a rollback (rolled_back) it is the target copies the job made. Each side needs its own\n * confirmation string. Items that fail a check are skipped and reported, never deleted.\n */\n async cleanup(jobId: number, confirm: string): Promise<{ side: 'source' | 'target'; deleted: number; skipped: { itemId: number; reason: string }[] }> {\n const job = await this.loadJob(jobId);\n if (['completed', 'completed_with_errors'].includes(job.status)) {\n this.assertConfirmation(confirm, CLEANUP_SOURCE_CONFIRMATION, 'source');\n return { side: 'source', ...await this.cleanupSourceFiles(job) };\n }\n if (job.status === 'rolled_back') {\n this.assertConfirmation(confirm, CLEANUP_TARGET_CONFIRMATION, 'target');\n return { side: 'target', ...await this.cleanupTargetFiles(job) };\n }\n throw new BadRequestException(`Job #${jobId} is ${job.status}. Files can only be removed after the job has finished or been rolled back.`);\n }\n\n private assertConfirmation(confirm: string, expected: string, side: 'source' | 'target') {\n if (confirm !== expected) {\n throw new BadRequestException(`Deleting ${side} files for this job needs confirm: \"${expected}\" in the request body.`);\n }\n }\n\n /**\n * Deletes the target copies a rolled-back job made. The rows point at the source again, so a target\n * copy is only deleted if the source file is still there, no media row uses the copy, and the job\n * wrote the copy itself (a file that was already on the target is never touched).\n */\n private async cleanupTargetFiles(job: MediaMigrationJob): Promise<{ deleted: number; skipped: { itemId: number; reason: string }[] }> {\n const defaultRegion = this.defaultRegion();\n const items = await this.dataSource.getRepository(MediaMigrationItem).find({ where: { job: { id: job.id }, status: 'rolled_back', copied: true } });\n const skipped: { itemId: number; reason: string }[] = [];\n let deleted = 0;\n\n for (const item of items) {\n try {\n const source = resolveLocation(job.sourceProvider, item.sourceKey, defaultRegion);\n const target = resolveLocation(job.targetProvider, item.targetKey ?? item.sourceKey, defaultRegion);\n if (sameLocation(source, target)) {\n skipped.push({ itemId: item.id, reason: 'Source and target are the same stored file.' });\n continue;\n }\n // The rolled-back rows read from the source, so it has to be intact before the other copy goes.\n const sourceStat = await this.transfer.stat(source, 'source');\n if (!sourceStat || (item.sourceSize !== null && item.sourceSize !== undefined && sourceStat.size !== item.sourceSize)) {\n skipped.push({ itemId: item.id, reason: 'The source file is missing or has a different size, so the target copy may be the only good one.' });\n continue;\n }\n const stillUsed = await rowsUsingLocation(this.dataSource, target, defaultRegion);\n if (stillUsed.length > 0) {\n skipped.push({ itemId: item.id, reason: `${stillUsed.length} media row(s) still use the target file.` });\n continue;\n }\n await this.transfer.delete(target, 'target');\n await this.dataSource.getRepository(MediaMigrationItem).update({ id: item.id }, { status: 'target_deleted' });\n deleted += 1;\n } catch (error: any) {\n skipped.push({ itemId: item.id, reason: error instanceof MigrationError ? error.message : (error?.message ?? String(error)) });\n }\n }\n return { deleted, skipped };\n }\n\n /**\n * Deletes the source files of completed items, after checking that the target copy is complete and\n * that no media row still uses the source file. Items that fail a check are skipped and reported.\n */\n private async cleanupSourceFiles(job: MediaMigrationJob): Promise<{ deleted: number; skipped: { itemId: number; reason: string }[] }> {\n const jobId = job.id;\n const defaultRegion = this.defaultRegion();\n const items = await this.dataSource.getRepository(MediaMigrationItem).find({ where: { job: { id: jobId }, status: 'completed' } });\n const skipped: { itemId: number; reason: string }[] = [];\n let deleted = 0;\n\n for (const item of items) {\n try {\n const source = resolveLocation(job.sourceProvider, item.sourceKey, defaultRegion);\n const target = resolveLocation(job.targetProvider, item.targetKey ?? item.sourceKey, defaultRegion);\n if (sameLocation(source, target)) {\n skipped.push({ itemId: item.id, reason: 'Source and target are the same stored file.' });\n continue;\n }\n if (item.targetSize === null || item.targetSize === undefined) {\n skipped.push({ itemId: item.id, reason: 'The target size was not recorded, so the copy cannot be verified.' });\n continue;\n }\n const targetStat = await this.transfer.stat(target, 'target');\n if (!targetStat || targetStat.size !== item.targetSize) {\n skipped.push({ itemId: item.id, reason: 'The target copy is missing or has a different size.' });\n continue;\n }\n const stillUsed = await rowsUsingLocation(this.dataSource, source, defaultRegion);\n if (stillUsed.length > 0) {\n skipped.push({ itemId: item.id, reason: `${stillUsed.length} media row(s) still use the source file.` });\n continue;\n }\n await this.transfer.delete(source, 'source');\n await this.dataSource.getRepository(MediaMigrationItem).update({ id: item.id }, { status: 'source_deleted' });\n deleted += 1;\n } catch (error: any) {\n skipped.push({ itemId: item.id, reason: error instanceof MigrationError ? error.message : (error?.message ?? String(error)) });\n }\n }\n return { deleted, skipped };\n }\n\n // ---- shared ----\n\n private async validate(request: MediaMigrationRequest, options: { checkActiveJobs: boolean } = { checkActiveJobs: true }): Promise<ValidatedRequest> {\n // The app does not reject unknown request fields, so an old client that still sends entityIds would\n // silently migrate far more than it meant to. Refuse it instead.\n if ((request as any).entityIds !== undefined) {\n throw new BadRequestException(\n 'entityIds is no longer supported. Scope a migration by modelMetadataIds or fieldMetadataIds. ' +\n 'To try a migration first, move one small field and roll it back if anything looks wrong.',\n );\n }\n\n const source = await this.findProvider(request.sourceProviderId, request.sourceProviderName, 'source');\n const target = await this.findProvider(request.targetProviderId, request.targetProviderName, 'target');\n\n if (source.id === target.id) {\n throw new BadRequestException('The source and target provider are the same. Choose a different target.');\n }\n for (const provider of [source, target]) {\n if (![MediaStorageProviderType.Filesystem, MediaStorageProviderType.AwsS3].includes(provider.type as MediaStorageProviderType)) {\n throw new BadRequestException(`Provider \"${provider.name}\" is of type \"${provider.type}\", which cannot be migrated. Use filesystem or aws-s3.`);\n }\n if (provider.type === MediaStorageProviderType.AwsS3 && (!process.env.S3_AWS_ACCESS_KEY || !process.env.S3_AWS_SECRET_KEY)) {\n throw new BadRequestException('S3_AWS_ACCESS_KEY and S3_AWS_SECRET_KEY must be set to migrate to or from S3.');\n }\n try {\n resolveLocation(provider, 'check', this.defaultRegion());\n } catch (error) {\n throw new BadRequestException(error instanceof MigrationError ? error.message : String(error));\n }\n }\n\n // Ids and user keys can be mixed; the scope is the union of both, resolved to ids once here.\n const byKey = await this.resolveUserKeys(request);\n const modelIds = unique([...(request.modelMetadataIds ?? []), ...byKey.modelIds]);\n const fieldIds = unique([...(request.fieldMetadataIds ?? []), ...byKey.fieldIds]);\n const scope: MigrationScope = {\n sourceProviderId: source.id,\n modelMetadataIds: modelIds.length ? modelIds : null,\n fieldMetadataIds: fieldIds.length ? fieldIds : null,\n };\n await this.assertScopeExists(scope);\n\n // Only one job may run per source provider at a time. Preview only reports, so it skips this check.\n const active = options.checkActiveJobs\n ? await this.dataSource.getRepository(MediaMigrationJob).findOne({\n where: { sourceProvider: { id: source.id }, status: In(ACTIVE_STATUSES) },\n })\n : null;\n if (active) {\n throw new BadRequestException(`Migration job #${active.id} is already ${active.status} for provider \"${source.name}\". Wait for it to finish or cancel it.`);\n }\n\n const clamp = (value: number | undefined, fallback: number, min: number, max: number) =>\n Math.min(max, Math.max(min, Math.floor(value ?? fallback)));\n\n return {\n source,\n target,\n scope,\n options: {\n overwriteExisting: request.overwriteExisting ?? false,\n batchSize: clamp(request.batchSize, DEFAULT_BATCH_SIZE, 10, 1000),\n concurrency: clamp(request.concurrency, DEFAULT_CONCURRENCY, 1, 16),\n },\n };\n }\n\n private async findProvider(id: number | undefined, name: string | undefined, role: string): Promise<MediaStorageProviderMetadata> {\n const repo = this.dataSource.getRepository(MediaStorageProviderMetadata);\n const provider = id\n ? await repo.findOne({ where: { id } })\n : name ? await repo.findOne({ where: { name } }) : null;\n if (!provider) {\n throw new BadRequestException(`Choose a ${role} provider by id or name. \"${id ?? name ?? ''}\" was not found.`);\n }\n return provider;\n }\n\n // Turns model and field user keys into ids. An unknown key is refused by name, so a typo cannot\n // quietly migrate less than the admin meant.\n private async resolveUserKeys(request: MediaMigrationRequest): Promise<{ modelIds: number[]; fieldIds: number[] }> {\n const modelKeys = unique(request.modelUserKeys ?? []);\n const modelIds: number[] = [];\n if (modelKeys.length) {\n const models = await this.dataSource.getRepository(ModelMetadata).find({ where: { singularName: In(modelKeys) } });\n const found = new Set(models.map(model => model.singularName));\n const missing = modelKeys.filter(key => !found.has(key));\n if (missing.length) {\n throw new BadRequestException(`Unknown model userKey: ${missing.map(key => `\"${key}\"`).join(', ')}. A model's userKey is its singularName.`);\n }\n modelIds.push(...models.map(model => model.id));\n }\n\n const fieldIds: number[] = [];\n for (const ref of request.fieldUserKeys ?? []) {\n const field = await this.dataSource.getRepository(FieldMetadata).findOne({\n where: { name: ref.fieldUserKey, model: { singularName: ref.modelUserKey } },\n });\n if (!field) {\n throw new BadRequestException(`Unknown field userKey \"${ref.fieldUserKey}\" on model \"${ref.modelUserKey}\".`);\n }\n fieldIds.push(field.id);\n }\n return { modelIds, fieldIds: unique(fieldIds) };\n }\n\n private async assertScopeExists(scope: MigrationScope): Promise<void> {\n const checks: [string, number[] | null | undefined, any][] = [\n ['model', scope.modelMetadataIds, ModelMetadata],\n ['field', scope.fieldMetadataIds, FieldMetadata],\n ];\n for (const [label, ids, entity] of checks) {\n if (!ids?.length) continue;\n const found = await this.dataSource.getRepository(entity).count({ where: { id: In(ids) } });\n if (found !== new Set(ids).size) {\n throw new BadRequestException(`Some ${label} ids in the scope do not exist.`);\n }\n }\n }\n\n private async checkBuckets(source: MediaStorageProviderMetadata, target: MediaStorageProviderMetadata): Promise<void> {\n for (const [provider, role] of [[source, 'source'], [target, 'target']] as const) {\n if (provider.type !== MediaStorageProviderType.AwsS3) continue;\n await this.transfer.assertBucketReachable(resolveLocation(provider, 'check', this.defaultRegion()), role)\n .catch(error => {\n throw new BadRequestException(error instanceof MigrationError ? error.message : String(error));\n });\n }\n }\n\n private defaultRegion(): string | undefined {\n return this.configService.get<string>('S3_AWS_REGION_NAME') || undefined;\n }\n\n private async loadJob(jobId: number): Promise<MediaMigrationJob> {\n const job = await this.dataSource.getRepository(MediaMigrationJob).findOne({\n where: { id: jobId },\n relations: ['sourceProvider', 'targetProvider'],\n });\n if (!job) {\n throw new NotFoundException(`Media migration job #${jobId} not found`);\n }\n return job;\n }\n\n // Publishes through the configured broker (database, redis or rabbitmq), by publisher name.\n private async publish(jobId: number): Promise<void> {\n await this.publisherFactory.publish({ payload: { jobId } } as any, 'MediaMigrationPublisher');\n }\n\n private async updateJob(jobId: number, fields: Partial<MediaMigrationJob>): Promise<void> {\n await this.dataSource.getRepository(MediaMigrationJob).update({ id: jobId }, fields as any);\n }\n}\n"]}
@@ -0,0 +1,26 @@
1
+ import { DiskFileService, S3FileService } from '../../services/file';
2
+ import { MediaLocation } from './media-location';
3
+ import { StorageRole } from './migration-error';
4
+ export declare class MediaTransferService {
5
+ private readonly diskFileService;
6
+ private readonly s3FileService;
7
+ constructor(diskFileService: DiskFileService, s3FileService: S3FileService);
8
+ stat(location: MediaLocation, role: StorageRole): Promise<{
9
+ size: number;
10
+ } | null>;
11
+ assertBucketReachable(location: MediaLocation, role: StorageRole): Promise<void>;
12
+ copy(source: MediaLocation, target: MediaLocation, options: {
13
+ sourceSize: number;
14
+ contentType?: string;
15
+ }): Promise<void>;
16
+ delete(location: MediaLocation, role?: StorageRole): Promise<void>;
17
+ probeWritable(target: MediaLocation): Promise<void>;
18
+ private writeAtomically;
19
+ private useStream;
20
+ sameContent(source: MediaLocation, target: MediaLocation): Promise<boolean>;
21
+ private contentHash;
22
+ private attributeCopyError;
23
+ private failedSide;
24
+ private sourceNotFound;
25
+ }
26
+ //# sourceMappingURL=media-transfer.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"media-transfer.service.d.ts","sourceRoot":"","sources":["../../../src/services/media-migration/media-transfer.service.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAkB,WAAW,EAAoB,MAAM,mBAAmB,CAAC;AA8BlF,qBACa,oBAAoB;IAE7B,OAAO,CAAC,QAAQ,CAAC,eAAe;IAChC,OAAO,CAAC,QAAQ,CAAC,aAAa;gBADb,eAAe,EAAE,eAAe,EAChC,aAAa,EAAE,aAAa;IAIzC,IAAI,CAAC,QAAQ,EAAE,aAAa,EAAE,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IAgBlF,qBAAqB,CAAC,QAAQ,EAAE,aAAa,EAAE,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAsBhF,IAAI,CAAC,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAgCxH,MAAM,CAAC,QAAQ,EAAE,aAAa,EAAE,IAAI,GAAE,WAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IAqB5E,aAAa,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;YAyC3C,eAAe;YAcf,SAAS;IAajB,WAAW,CAAC,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,OAAO,CAAC;YAKnE,WAAW;YAmBX,kBAAkB;YA4BlB,UAAU;IAoBxB,OAAO,CAAC,cAAc;CAOvB"}