@jrmc/adonis-attachment 5.2.1 → 6.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (404) hide show
  1. package/README.md +10 -81
  2. package/build/bin/test.d.ts +2 -0
  3. package/build/bin/test.d.ts.map +1 -0
  4. package/build/bin/test.js +9 -0
  5. package/build/bin/test.js.map +1 -0
  6. package/build/commands/commands.json +1 -1
  7. package/build/commands/make/attachment_v5_migration.d.ts +17 -0
  8. package/build/commands/make/attachment_v5_migration.d.ts.map +1 -0
  9. package/build/commands/make/attachment_v5_migration.js +26 -0
  10. package/build/commands/make/attachment_v5_migration.js.map +1 -0
  11. package/build/commands/make/{converter.d.ts → attachments_table.d.ts} +6 -4
  12. package/build/commands/make/attachments_table.d.ts.map +1 -0
  13. package/build/commands/make/attachments_table.js +30 -0
  14. package/build/commands/make/attachments_table.js.map +1 -0
  15. package/build/configure.d.ts.map +1 -1
  16. package/build/configure.js +2 -1
  17. package/build/configure.js.map +1 -0
  18. package/build/index.d.ts +23 -8
  19. package/build/index.d.ts.map +1 -1
  20. package/build/index.js +13 -7
  21. package/build/index.js.map +1 -0
  22. package/build/providers/attachment_provider.d.ts +0 -19
  23. package/build/providers/attachment_provider.d.ts.map +1 -1
  24. package/build/providers/attachment_provider.js +30 -26
  25. package/build/providers/attachment_provider.js.map +1 -0
  26. package/build/services/main.d.ts +3 -3
  27. package/build/services/main.d.ts.map +1 -1
  28. package/build/services/main.js +42 -5
  29. package/build/services/main.js.map +1 -0
  30. package/build/src/adapters/adonis_drive_storage.d.ts +33 -0
  31. package/build/src/adapters/adonis_drive_storage.d.ts.map +1 -0
  32. package/build/src/adapters/adonis_drive_storage.js +35 -0
  33. package/build/src/adapters/adonis_drive_storage.js.map +1 -0
  34. package/build/src/adapters/local_file_storage.d.ts +25 -0
  35. package/build/src/adapters/local_file_storage.d.ts.map +1 -0
  36. package/build/src/adapters/local_file_storage.js +54 -0
  37. package/build/src/adapters/local_file_storage.js.map +1 -0
  38. package/build/src/controllers/attachments_controller.d.ts +13 -2
  39. package/build/src/controllers/attachments_controller.d.ts.map +1 -1
  40. package/build/src/controllers/attachments_controller.js +20 -107
  41. package/build/src/controllers/attachments_controller.js.map +1 -0
  42. package/build/src/core/attachment.d.ts +35 -0
  43. package/build/src/core/attachment.d.ts.map +1 -0
  44. package/build/src/core/attachment.js +47 -0
  45. package/build/src/core/attachment.js.map +1 -0
  46. package/build/src/core/attachment_job_processor.d.ts +30 -0
  47. package/build/src/core/attachment_job_processor.d.ts.map +1 -0
  48. package/build/src/core/attachment_job_processor.js +47 -0
  49. package/build/src/core/attachment_job_processor.js.map +1 -0
  50. package/build/src/core/attachment_repository.d.ts +15 -0
  51. package/build/src/core/attachment_repository.d.ts.map +1 -0
  52. package/build/src/core/attachment_repository.js +8 -0
  53. package/build/src/core/attachment_repository.js.map +1 -0
  54. package/build/src/core/attachment_service.d.ts +28 -0
  55. package/build/src/core/attachment_service.d.ts.map +1 -0
  56. package/build/src/core/attachment_service.js +47 -0
  57. package/build/src/core/attachment_service.js.map +1 -0
  58. package/build/src/core/attachment_state.d.ts +11 -0
  59. package/build/src/core/attachment_state.d.ts.map +1 -0
  60. package/build/src/core/attachment_state.js +17 -0
  61. package/build/src/core/attachment_state.js.map +1 -0
  62. package/build/src/core/index.d.ts +13 -0
  63. package/build/src/core/index.d.ts.map +1 -0
  64. package/build/src/core/index.js +10 -0
  65. package/build/src/core/index.js.map +1 -0
  66. package/build/src/core/queue.d.ts +20 -0
  67. package/build/src/core/queue.d.ts.map +1 -0
  68. package/build/src/{types/event.js → core/queue.js} +1 -0
  69. package/build/src/core/queue.js.map +1 -0
  70. package/build/src/core/storage.d.ts +23 -0
  71. package/build/src/core/storage.d.ts.map +1 -0
  72. package/build/src/{types/config.js → core/storage.js} +1 -0
  73. package/build/src/core/storage.js.map +1 -0
  74. package/build/src/define_config.d.ts +35 -20
  75. package/build/src/define_config.d.ts.map +1 -1
  76. package/build/src/define_config.js +45 -24
  77. package/build/src/define_config.js.map +1 -0
  78. package/build/src/integrations/lucid/attachment_column.d.ts +11 -0
  79. package/build/src/integrations/lucid/attachment_column.d.ts.map +1 -0
  80. package/build/src/integrations/lucid/attachment_column.js +138 -0
  81. package/build/src/integrations/lucid/attachment_column.js.map +1 -0
  82. package/build/src/integrations/lucid/attachment_model.d.ts +36 -0
  83. package/build/src/integrations/lucid/attachment_model.d.ts.map +1 -0
  84. package/build/src/integrations/lucid/attachment_model.js +96 -0
  85. package/build/src/integrations/lucid/attachment_model.js.map +1 -0
  86. package/build/src/integrations/lucid/attachment_owner.d.ts +17 -0
  87. package/build/src/integrations/lucid/attachment_owner.d.ts.map +1 -0
  88. package/build/src/integrations/lucid/attachment_owner.js +15 -0
  89. package/build/src/integrations/lucid/attachment_owner.js.map +1 -0
  90. package/build/src/integrations/lucid/attachments_table_stub.d.ts +21 -0
  91. package/build/src/integrations/lucid/attachments_table_stub.d.ts.map +1 -0
  92. package/build/src/integrations/lucid/attachments_table_stub.js +26 -0
  93. package/build/src/integrations/lucid/attachments_table_stub.js.map +1 -0
  94. package/build/src/integrations/lucid/create_legacy_attachment_migration_script.d.ts +13 -0
  95. package/build/src/integrations/lucid/create_legacy_attachment_migration_script.d.ts.map +1 -0
  96. package/build/src/integrations/lucid/create_legacy_attachment_migration_script.js +20 -0
  97. package/build/src/integrations/lucid/create_legacy_attachment_migration_script.js.map +1 -0
  98. package/build/src/integrations/lucid/index.d.ts +19 -0
  99. package/build/src/integrations/lucid/index.d.ts.map +1 -0
  100. package/build/src/integrations/lucid/index.js +19 -0
  101. package/build/src/integrations/lucid/index.js.map +1 -0
  102. package/build/src/integrations/lucid/lucid_attachment_lifecycle_service.d.ts +21 -0
  103. package/build/src/integrations/lucid/lucid_attachment_lifecycle_service.d.ts.map +1 -0
  104. package/build/src/integrations/lucid/lucid_attachment_lifecycle_service.js +68 -0
  105. package/build/src/integrations/lucid/lucid_attachment_lifecycle_service.js.map +1 -0
  106. package/build/src/integrations/lucid/lucid_attachment_repository.d.ts +18 -0
  107. package/build/src/integrations/lucid/lucid_attachment_repository.d.ts.map +1 -0
  108. package/build/src/integrations/lucid/lucid_attachment_repository.js +21 -0
  109. package/build/src/integrations/lucid/lucid_attachment_repository.js.map +1 -0
  110. package/build/src/integrations/lucid/lucid_attachment_store.d.ts +27 -0
  111. package/build/src/integrations/lucid/lucid_attachment_store.d.ts.map +1 -0
  112. package/build/src/integrations/lucid/lucid_attachment_store.js +84 -0
  113. package/build/src/integrations/lucid/lucid_attachment_store.js.map +1 -0
  114. package/build/src/integrations/lucid/lucid_variant_generation_service.d.ts +24 -0
  115. package/build/src/integrations/lucid/lucid_variant_generation_service.d.ts.map +1 -0
  116. package/build/src/integrations/lucid/lucid_variant_generation_service.js +42 -0
  117. package/build/src/integrations/lucid/lucid_variant_generation_service.js.map +1 -0
  118. package/build/src/integrations/lucid/migrate_legacy_attachment.d.ts +57 -0
  119. package/build/src/integrations/lucid/migrate_legacy_attachment.d.ts.map +1 -0
  120. package/build/src/integrations/lucid/migrate_legacy_attachment.js +67 -0
  121. package/build/src/integrations/lucid/migrate_legacy_attachment.js.map +1 -0
  122. package/build/src/integrations/lucid/migrate_legacy_attachment_records.d.ts +34 -0
  123. package/build/src/integrations/lucid/migrate_legacy_attachment_records.d.ts.map +1 -0
  124. package/build/src/integrations/lucid/migrate_legacy_attachment_records.js +47 -0
  125. package/build/src/integrations/lucid/migrate_legacy_attachment_records.js.map +1 -0
  126. package/build/src/integrations/lucid/render_legacy_attachment_migration_script.d.ts +11 -0
  127. package/build/src/integrations/lucid/render_legacy_attachment_migration_script.d.ts.map +1 -0
  128. package/build/src/integrations/lucid/render_legacy_attachment_migration_script.js +41 -0
  129. package/build/src/integrations/lucid/render_legacy_attachment_migration_script.js.map +1 -0
  130. package/build/src/queues/adonis_queue.d.ts +27 -0
  131. package/build/src/queues/adonis_queue.d.ts.map +1 -0
  132. package/build/src/queues/adonis_queue.js +22 -0
  133. package/build/src/queues/adonis_queue.js.map +1 -0
  134. package/build/src/queues/memory_queue.d.ts +22 -0
  135. package/build/src/queues/memory_queue.d.ts.map +1 -0
  136. package/build/src/queues/memory_queue.js +67 -0
  137. package/build/src/queues/memory_queue.js.map +1 -0
  138. package/build/src/sources/attachment_manager.d.ts +51 -0
  139. package/build/src/sources/attachment_manager.d.ts.map +1 -0
  140. package/build/src/sources/attachment_manager.js +169 -0
  141. package/build/src/sources/attachment_manager.js.map +1 -0
  142. package/build/src/variants/variant_converter.d.ts +23 -0
  143. package/build/src/variants/variant_converter.d.ts.map +1 -0
  144. package/build/src/{types/converter.js → variants/variant_converter.js} +1 -0
  145. package/build/src/variants/variant_converter.js.map +1 -0
  146. package/build/src/variants/variant_generation_service.d.ts +28 -0
  147. package/build/src/variants/variant_generation_service.d.ts.map +1 -0
  148. package/build/src/variants/variant_generation_service.js +44 -0
  149. package/build/src/variants/variant_generation_service.js.map +1 -0
  150. package/build/stubs/config/attachment.stub +12 -0
  151. package/build/stubs/main.d.ts.map +1 -1
  152. package/build/stubs/main.js +1 -0
  153. package/build/stubs/main.js.map +1 -0
  154. package/build/stubs/migrations/attachments_table.stub +38 -0
  155. package/build/tests/adonis_drive_storage.spec.d.ts +8 -0
  156. package/build/tests/adonis_drive_storage.spec.d.ts.map +1 -0
  157. package/build/tests/adonis_drive_storage.spec.js +69 -0
  158. package/build/tests/adonis_drive_storage.spec.js.map +1 -0
  159. package/build/{src/types/attachment.js → tests/adonis_queue.spec.d.ts} +1 -0
  160. package/build/tests/adonis_queue.spec.d.ts.map +1 -0
  161. package/build/tests/adonis_queue.spec.js +52 -0
  162. package/build/tests/adonis_queue.spec.js.map +1 -0
  163. package/build/tests/attachment_job_processor.spec.d.ts +8 -0
  164. package/build/tests/attachment_job_processor.spec.d.ts.map +1 -0
  165. package/build/tests/attachment_job_processor.spec.js +89 -0
  166. package/build/tests/attachment_job_processor.spec.js.map +1 -0
  167. package/build/tests/attachment_manager.spec.d.ts +8 -0
  168. package/build/tests/attachment_manager.spec.d.ts.map +1 -0
  169. package/build/tests/attachment_manager.spec.js +128 -0
  170. package/build/tests/attachment_manager.spec.js.map +1 -0
  171. package/build/tests/attachment_manager_service.spec.d.ts +8 -0
  172. package/build/tests/attachment_manager_service.spec.d.ts.map +1 -0
  173. package/build/tests/attachment_manager_service.spec.js +47 -0
  174. package/build/tests/attachment_manager_service.spec.js.map +1 -0
  175. package/build/tests/attachment_provider.spec.d.ts +8 -0
  176. package/build/tests/attachment_provider.spec.d.ts.map +1 -0
  177. package/build/tests/attachment_provider.spec.js +71 -0
  178. package/build/tests/attachment_provider.spec.js.map +1 -0
  179. package/build/tests/attachment_service.spec.d.ts +8 -0
  180. package/build/tests/attachment_service.spec.d.ts.map +1 -0
  181. package/build/tests/attachment_service.spec.js +91 -0
  182. package/build/tests/attachment_service.spec.js.map +1 -0
  183. package/build/tests/attachments_controller.spec.d.ts +8 -0
  184. package/build/tests/attachments_controller.spec.d.ts.map +1 -0
  185. package/build/tests/attachments_controller.spec.js +34 -0
  186. package/build/tests/attachments_controller.spec.js.map +1 -0
  187. package/build/tests/attachments_table_stub.spec.d.ts +2 -0
  188. package/build/tests/attachments_table_stub.spec.d.ts.map +1 -0
  189. package/build/tests/attachments_table_stub.spec.js +65 -0
  190. package/build/tests/attachments_table_stub.spec.js.map +1 -0
  191. package/build/tests/configure.spec.d.ts +2 -0
  192. package/build/tests/configure.spec.d.ts.map +1 -0
  193. package/build/tests/configure.spec.js +38 -0
  194. package/build/tests/configure.spec.js.map +1 -0
  195. package/build/tests/container_bindings.types.d.ts +8 -0
  196. package/build/tests/container_bindings.types.d.ts.map +1 -0
  197. package/build/tests/container_bindings.types.js +9 -0
  198. package/build/tests/container_bindings.types.js.map +1 -0
  199. package/build/tests/create_legacy_attachment_migration_script.spec.d.ts +8 -0
  200. package/build/tests/create_legacy_attachment_migration_script.spec.d.ts.map +1 -0
  201. package/build/tests/create_legacy_attachment_migration_script.spec.js +31 -0
  202. package/build/tests/create_legacy_attachment_migration_script.spec.js.map +1 -0
  203. package/build/tests/define_config.spec.d.ts +8 -0
  204. package/build/tests/define_config.spec.d.ts.map +1 -0
  205. package/build/tests/define_config.spec.js +191 -0
  206. package/build/tests/define_config.spec.js.map +1 -0
  207. package/build/tests/helpers/lucid_test_database.d.ts +9 -0
  208. package/build/tests/helpers/lucid_test_database.d.ts.map +1 -0
  209. package/build/tests/helpers/lucid_test_database.js +51 -0
  210. package/build/tests/helpers/lucid_test_database.js.map +1 -0
  211. package/build/tests/local_file_storage.spec.d.ts +8 -0
  212. package/build/tests/local_file_storage.spec.d.ts.map +1 -0
  213. package/build/tests/local_file_storage.spec.js +44 -0
  214. package/build/tests/local_file_storage.spec.js.map +1 -0
  215. package/build/tests/lucid_attachment_column.spec.d.ts +8 -0
  216. package/build/tests/lucid_attachment_column.spec.d.ts.map +1 -0
  217. package/build/tests/lucid_attachment_column.spec.js +137 -0
  218. package/build/tests/lucid_attachment_column.spec.js.map +1 -0
  219. package/build/tests/lucid_attachment_lifecycle_service.spec.d.ts +8 -0
  220. package/build/tests/lucid_attachment_lifecycle_service.spec.d.ts.map +1 -0
  221. package/build/tests/lucid_attachment_lifecycle_service.spec.js +206 -0
  222. package/build/tests/lucid_attachment_lifecycle_service.spec.js.map +1 -0
  223. package/build/tests/lucid_attachment_repository.spec.d.ts +8 -0
  224. package/build/tests/lucid_attachment_repository.spec.d.ts.map +1 -0
  225. package/build/tests/lucid_attachment_repository.spec.js +50 -0
  226. package/build/tests/lucid_attachment_repository.spec.js.map +1 -0
  227. package/build/tests/lucid_attachment_store.spec.d.ts +8 -0
  228. package/build/tests/lucid_attachment_store.spec.d.ts.map +1 -0
  229. package/build/tests/lucid_attachment_store.spec.js +71 -0
  230. package/build/tests/lucid_attachment_store.spec.js.map +1 -0
  231. package/build/tests/lucid_sqlite_integration.spec.d.ts +8 -0
  232. package/build/tests/lucid_sqlite_integration.spec.d.ts.map +1 -0
  233. package/build/tests/lucid_sqlite_integration.spec.js +103 -0
  234. package/build/tests/lucid_sqlite_integration.spec.js.map +1 -0
  235. package/build/tests/lucid_variant_generation_service.spec.d.ts +8 -0
  236. package/build/tests/lucid_variant_generation_service.spec.d.ts.map +1 -0
  237. package/build/tests/lucid_variant_generation_service.spec.js +56 -0
  238. package/build/tests/lucid_variant_generation_service.spec.js.map +1 -0
  239. package/build/tests/memory_queue.spec.d.ts +8 -0
  240. package/build/tests/memory_queue.spec.d.ts.map +1 -0
  241. package/build/tests/memory_queue.spec.js +52 -0
  242. package/build/tests/memory_queue.spec.js.map +1 -0
  243. package/build/tests/migrate_legacy_attachment.spec.d.ts +8 -0
  244. package/build/tests/migrate_legacy_attachment.spec.d.ts.map +1 -0
  245. package/build/tests/migrate_legacy_attachment.spec.js +91 -0
  246. package/build/tests/migrate_legacy_attachment.spec.js.map +1 -0
  247. package/build/tests/migrate_legacy_attachment_records.spec.d.ts +8 -0
  248. package/build/tests/migrate_legacy_attachment_records.spec.d.ts.map +1 -0
  249. package/build/tests/migrate_legacy_attachment_records.spec.js +66 -0
  250. package/build/tests/migrate_legacy_attachment_records.spec.js.map +1 -0
  251. package/build/tests/package_exports.spec.d.ts +8 -0
  252. package/build/tests/package_exports.spec.d.ts.map +1 -0
  253. package/build/tests/package_exports.spec.js +31 -0
  254. package/build/tests/package_exports.spec.js.map +1 -0
  255. package/build/tests/variant_generation_service.spec.d.ts +8 -0
  256. package/build/tests/variant_generation_service.spec.d.ts.map +1 -0
  257. package/build/tests/variant_generation_service.spec.js +79 -0
  258. package/build/tests/variant_generation_service.spec.js.map +1 -0
  259. package/package.json +79 -75
  260. package/build/commands/make/converter.d.ts.map +0 -1
  261. package/build/commands/make/converter.js +0 -28
  262. package/build/services/regenerate_service.d.ts +0 -9
  263. package/build/services/regenerate_service.d.ts.map +0 -1
  264. package/build/services/regenerate_service.js +0 -29
  265. package/build/src/adapters/blurhash.d.ts +0 -11
  266. package/build/src/adapters/blurhash.d.ts.map +0 -1
  267. package/build/src/adapters/blurhash.js +0 -12
  268. package/build/src/adapters/exif.d.ts +0 -15
  269. package/build/src/adapters/exif.d.ts.map +0 -1
  270. package/build/src/adapters/exif.js +0 -165
  271. package/build/src/adapters/ffmpeg.d.ts +0 -19
  272. package/build/src/adapters/ffmpeg.d.ts.map +0 -1
  273. package/build/src/adapters/ffmpeg.js +0 -115
  274. package/build/src/adapters/lock.d.ts +0 -9
  275. package/build/src/adapters/lock.d.ts.map +0 -1
  276. package/build/src/adapters/lock.js +0 -21
  277. package/build/src/adapters/meta.d.ts +0 -10
  278. package/build/src/adapters/meta.d.ts.map +0 -1
  279. package/build/src/adapters/meta.js +0 -49
  280. package/build/src/adapters/poppler.d.ts +0 -20
  281. package/build/src/adapters/poppler.d.ts.map +0 -1
  282. package/build/src/adapters/poppler.js +0 -117
  283. package/build/src/adapters/soffice.d.ts +0 -14
  284. package/build/src/adapters/soffice.d.ts.map +0 -1
  285. package/build/src/adapters/soffice.js +0 -64
  286. package/build/src/attachment_manager.d.ts +0 -50
  287. package/build/src/attachment_manager.d.ts.map +0 -1
  288. package/build/src/attachment_manager.js +0 -145
  289. package/build/src/attachments/attachment.d.ts +0 -42
  290. package/build/src/attachments/attachment.d.ts.map +0 -1
  291. package/build/src/attachments/attachment.js +0 -233
  292. package/build/src/attachments/attachment_base.d.ts +0 -59
  293. package/build/src/attachments/attachment_base.d.ts.map +0 -1
  294. package/build/src/attachments/attachment_base.js +0 -211
  295. package/build/src/attachments/variant_attachment.d.ts +0 -27
  296. package/build/src/attachments/variant_attachment.d.ts.map +0 -1
  297. package/build/src/attachments/variant_attachment.js +0 -40
  298. package/build/src/converters/autodetect_converter.d.ts +0 -13
  299. package/build/src/converters/autodetect_converter.d.ts.map +0 -1
  300. package/build/src/converters/autodetect_converter.js +0 -77
  301. package/build/src/converters/converter.d.ts +0 -14
  302. package/build/src/converters/converter.d.ts.map +0 -1
  303. package/build/src/converters/converter.js +0 -14
  304. package/build/src/converters/document_thumbnail_converter.d.ts +0 -14
  305. package/build/src/converters/document_thumbnail_converter.d.ts.map +0 -1
  306. package/build/src/converters/document_thumbnail_converter.js +0 -36
  307. package/build/src/converters/image_converter.d.ts +0 -13
  308. package/build/src/converters/image_converter.d.ts.map +0 -1
  309. package/build/src/converters/image_converter.js +0 -27
  310. package/build/src/converters/pdf_thumbnail_converter.d.ts +0 -14
  311. package/build/src/converters/pdf_thumbnail_converter.d.ts.map +0 -1
  312. package/build/src/converters/pdf_thumbnail_converter.js +0 -39
  313. package/build/src/converters/video_thumbnail_converter.d.ts +0 -14
  314. package/build/src/converters/video_thumbnail_converter.d.ts.map +0 -1
  315. package/build/src/converters/video_thumbnail_converter.js +0 -40
  316. package/build/src/decorators/attachment.d.ts +0 -15
  317. package/build/src/decorators/attachment.d.ts.map +0 -1
  318. package/build/src/decorators/attachment.js +0 -103
  319. package/build/src/errors.d.ts +0 -67
  320. package/build/src/errors.d.ts.map +0 -1
  321. package/build/src/errors.js +0 -68
  322. package/build/src/services/attachment/attachment_detachment_service.d.ts +0 -19
  323. package/build/src/services/attachment/attachment_detachment_service.d.ts.map +0 -1
  324. package/build/src/services/attachment/attachment_detachment_service.js +0 -66
  325. package/build/src/services/attachment/attachment_persister_service.d.ts +0 -22
  326. package/build/src/services/attachment/attachment_persister_service.d.ts.map +0 -1
  327. package/build/src/services/attachment/attachment_persister_service.js +0 -96
  328. package/build/src/services/attachment/attachment_recorder_service.d.ts +0 -68
  329. package/build/src/services/attachment/attachment_recorder_service.d.ts.map +0 -1
  330. package/build/src/services/attachment/attachment_recorder_service.js +0 -121
  331. package/build/src/services/attachment/attachment_transaction_service.d.ts +0 -26
  332. package/build/src/services/attachment/attachment_transaction_service.d.ts.map +0 -1
  333. package/build/src/services/attachment/attachment_transaction_service.js +0 -46
  334. package/build/src/services/attachment/attachment_utils.d.ts +0 -35
  335. package/build/src/services/attachment/attachment_utils.d.ts.map +0 -1
  336. package/build/src/services/attachment/attachment_utils.js +0 -71
  337. package/build/src/services/attachment/attachment_variant_service.d.ts +0 -17
  338. package/build/src/services/attachment/attachment_variant_service.d.ts.map +0 -1
  339. package/build/src/services/attachment/attachment_variant_service.js +0 -99
  340. package/build/src/services/attachment/index.d.ts +0 -15
  341. package/build/src/services/attachment/index.d.ts.map +0 -1
  342. package/build/src/services/attachment/index.js +0 -15
  343. package/build/src/services/attachment_service.d.ts +0 -8
  344. package/build/src/services/attachment_service.d.ts.map +0 -1
  345. package/build/src/services/attachment_service.js +0 -7
  346. package/build/src/services/variant/variant_generator_service.d.ts +0 -24
  347. package/build/src/services/variant/variant_generator_service.d.ts.map +0 -1
  348. package/build/src/services/variant/variant_generator_service.js +0 -101
  349. package/build/src/services/variant/variant_persister_service.d.ts +0 -24
  350. package/build/src/services/variant/variant_persister_service.d.ts.map +0 -1
  351. package/build/src/services/variant/variant_persister_service.js +0 -59
  352. package/build/src/services/variant/variant_purger_service.d.ts +0 -15
  353. package/build/src/services/variant/variant_purger_service.d.ts.map +0 -1
  354. package/build/src/services/variant/variant_purger_service.js +0 -47
  355. package/build/src/services/variant_service.d.ts +0 -13
  356. package/build/src/services/variant_service.d.ts.map +0 -1
  357. package/build/src/services/variant_service.js +0 -63
  358. package/build/src/types/attachment.d.ts +0 -100
  359. package/build/src/types/attachment.d.ts.map +0 -1
  360. package/build/src/types/config.d.ts +0 -58
  361. package/build/src/types/config.d.ts.map +0 -1
  362. package/build/src/types/converter.d.ts +0 -144
  363. package/build/src/types/converter.d.ts.map +0 -1
  364. package/build/src/types/drive.d.ts +0 -6
  365. package/build/src/types/drive.d.ts.map +0 -1
  366. package/build/src/types/drive.js +0 -1
  367. package/build/src/types/event.d.ts +0 -16
  368. package/build/src/types/event.d.ts.map +0 -1
  369. package/build/src/types/index.d.ts +0 -15
  370. package/build/src/types/index.d.ts.map +0 -1
  371. package/build/src/types/index.js +0 -14
  372. package/build/src/types/input.d.ts +0 -35
  373. package/build/src/types/input.d.ts.map +0 -1
  374. package/build/src/types/input.js +0 -7
  375. package/build/src/types/lock.d.ts +0 -14
  376. package/build/src/types/lock.d.ts.map +0 -1
  377. package/build/src/types/lock.js +0 -7
  378. package/build/src/types/metadata.d.ts +0 -24
  379. package/build/src/types/metadata.d.ts.map +0 -1
  380. package/build/src/types/metadata.js +0 -7
  381. package/build/src/types/mixin.d.ts +0 -17
  382. package/build/src/types/mixin.d.ts.map +0 -1
  383. package/build/src/types/mixin.js +0 -7
  384. package/build/src/types/regenerate.d.ts +0 -12
  385. package/build/src/types/regenerate.d.ts.map +0 -1
  386. package/build/src/types/regenerate.js +0 -7
  387. package/build/src/types/service.d.ts +0 -25
  388. package/build/src/types/service.d.ts.map +0 -1
  389. package/build/src/types/service.js +0 -7
  390. package/build/src/utils/default_values.d.ts +0 -20
  391. package/build/src/utils/default_values.d.ts.map +0 -1
  392. package/build/src/utils/default_values.js +0 -19
  393. package/build/src/utils/helpers.d.ts +0 -19
  394. package/build/src/utils/helpers.d.ts.map +0 -1
  395. package/build/src/utils/helpers.js +0 -131
  396. package/build/src/utils/hooks.d.ts +0 -12
  397. package/build/src/utils/hooks.d.ts.map +0 -1
  398. package/build/src/utils/hooks.js +0 -42
  399. package/build/src/utils/symbols.d.ts +0 -8
  400. package/build/src/utils/symbols.d.ts.map +0 -1
  401. package/build/src/utils/symbols.js +0 -7
  402. package/build/stubs/config.stub +0 -140
  403. package/build/stubs/make/converter/main.stub +0 -20
  404. package/build/tsconfig.tsbuildinfo +0 -1
@@ -0,0 +1,51 @@
1
+ /**
2
+ * @jrmc/adonis-attachment
3
+ *
4
+ * @license MIT
5
+ * @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
6
+ */
7
+ import { Database } from '@adonisjs/lucid/database';
8
+ import { AttachmentModel } from '../../src/integrations/lucid/attachment_model.js';
9
+ export async function createLucidTestDatabase() {
10
+ const database = new Database({
11
+ connection: 'sqlite',
12
+ connections: {
13
+ sqlite: {
14
+ client: 'better-sqlite3',
15
+ connection: { filename: ':memory:' },
16
+ useNullAsDefault: true,
17
+ },
18
+ },
19
+ }, { trace() { } }, {
20
+ async emit() { },
21
+ async emitSerial() { },
22
+ hasListeners() {
23
+ return false;
24
+ },
25
+ });
26
+ AttachmentModel.useAdapter(database.modelAdapter());
27
+ await database.connection().schema.createTable('attachments', (table) => {
28
+ table.string('id').primary();
29
+ table.string('attachable_type').notNullable();
30
+ table.string('attachable_id').notNullable();
31
+ table.string('field').notNullable();
32
+ table.string('owner_key', 64).nullable().unique();
33
+ table.string('parent_id').nullable().references('id').inTable('attachments').onDelete('CASCADE');
34
+ table.string('variant_key').nullable();
35
+ table.string('disk').notNullable();
36
+ table.string('path').notNullable();
37
+ table.string('name').notNullable();
38
+ table.string('original_name').notNullable();
39
+ table.string('mime_type').notNullable();
40
+ table.string('extname').notNullable();
41
+ table.bigInteger('size').unsigned().notNullable();
42
+ table.json('metadata').nullable();
43
+ table.timestamp('created_at').notNullable();
44
+ table.timestamp('updated_at').notNullable();
45
+ table.index(['attachable_type', 'attachable_id', 'field']);
46
+ table.index(['parent_id']);
47
+ table.unique(['parent_id', 'variant_key']);
48
+ });
49
+ return database;
50
+ }
51
+ //# sourceMappingURL=lucid_test_database.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lucid_test_database.js","sourceRoot":"","sources":["../../../tests/helpers/lucid_test_database.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AAEnD,OAAO,EAAE,eAAe,EAAE,MAAM,kDAAkD,CAAA;AAElF,MAAM,CAAC,KAAK,UAAU,uBAAuB;IAC3C,MAAM,QAAQ,GAAG,IAAI,QAAQ,CAC3B;QACE,UAAU,EAAE,QAAQ;QACpB,WAAW,EAAE;YACX,MAAM,EAAE;gBACN,MAAM,EAAE,gBAAgB;gBACxB,UAAU,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE;gBACpC,gBAAgB,EAAE,IAAI;aACvB;SACF;KACF,EACD,EAAE,KAAK,KAAI,CAAC,EAAW,EACvB;QACE,KAAK,CAAC,IA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,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE,CAAA;QACrC,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAC,WAAW,EAAE,CAAA;QACjD,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,QAAQ,EAAE,CAAA;QACjC,KAAK,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,WAAW,EAAE,CAAA;QAC3C,KAAK,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,WAAW,EAAE,CAAA;QAC3C,KAAK,CAAC,KAAK,CAAC,CAAC,iBAAiB,EAAE,eAAe,EAAE,OAAO,CAAC,CAAC,CAAA;QAC1D,KAAK,CAAC,KAAK,CAAC,CAAC,WAAW,CAAC,CAAC,CAAA;QAC1B,KAAK,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC,CAAA;IAC5C,CAAC,CAAC,CAAA;IAEF,OAAO,QAAQ,CAAA;AACjB,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @jrmc/adonis-attachment
3
+ *
4
+ * @license MIT
5
+ * @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
6
+ */
7
+ export {};
8
+ //# sourceMappingURL=local_file_storage.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local_file_storage.spec.d.ts","sourceRoot":"","sources":["../../tests/local_file_storage.spec.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * @jrmc/adonis-attachment
3
+ *
4
+ * @license MIT
5
+ * @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
6
+ */
7
+ import { access, mkdtemp, readFile, rm } from 'node:fs/promises';
8
+ import { tmpdir } from 'node:os';
9
+ import { join } from 'node:path';
10
+ import { test } from '@japa/runner';
11
+ import { LocalFileStorage } from '../index.js';
12
+ test.group('LocalFileStorage', () => {
13
+ test('writes, reads, and removes attachments below its root directory', async ({ assert }) => {
14
+ const location = await mkdtemp(join(tmpdir(), 'adonis-attachment-'));
15
+ const storage = new LocalFileStorage({ location });
16
+ try {
17
+ await storage.write({
18
+ disk: 'fs',
19
+ path: 'users/42/avatar.png',
20
+ body: new Uint8Array([1, 2, 3]),
21
+ mimeType: 'image/png',
22
+ });
23
+ assert.deepEqual(await storage.read({ disk: 'fs', path: 'users/42/avatar.png' }), new Uint8Array([1, 2, 3]));
24
+ assert.deepEqual(await readFile(join(location, 'users/42/avatar.png')), Buffer.from([1, 2, 3]));
25
+ await storage.remove({ disk: 'fs', path: 'users/42/avatar.png' });
26
+ await assert.rejects(() => access(join(location, 'users/42/avatar.png')));
27
+ }
28
+ finally {
29
+ await rm(location, { recursive: true, force: true });
30
+ }
31
+ });
32
+ test('rejects paths outside its root and unsupported disks', async ({ assert }) => {
33
+ const location = await mkdtemp(join(tmpdir(), 'adonis-attachment-'));
34
+ const storage = new LocalFileStorage({ location });
35
+ try {
36
+ await assert.rejects(() => storage.write({ disk: 'fs', path: '../outside.txt', body: new Uint8Array(), mimeType: 'text/plain' }), 'Attachment paths must stay inside the local storage directory');
37
+ await assert.rejects(() => storage.write({ disk: 's3', path: 'avatar.txt', body: new Uint8Array(), mimeType: 'text/plain' }), 'LocalFileStorage cannot access the "s3" disk');
38
+ }
39
+ finally {
40
+ await rm(location, { recursive: true, force: true });
41
+ }
42
+ });
43
+ });
44
+ //# sourceMappingURL=local_file_storage.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local_file_storage.spec.js","sourceRoot":"","sources":["../../tests/local_file_storage.spec.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAA;AAChE,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC,OAAO,EAAE,IAAI,EAAE,MAAM,cAA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.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lucid_attachment_column.spec.d.ts","sourceRoot":"","sources":["../../tests/lucid_attachment_column.spec.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
@@ -0,0 +1,137 @@
1
+ /**
2
+ * @jrmc/adonis-attachment
3
+ *
4
+ * @license MIT
5
+ * @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
6
+ */
7
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
8
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
9
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
10
+ 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;
11
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
12
+ };
13
+ import { BaseModel, column } from '@adonisjs/lucid/orm';
14
+ import { setApp } from '@adonisjs/core/services/app';
15
+ import { test } from '@japa/runner';
16
+ import { attachment } from '../index.js';
17
+ import { AttachmentService } from '../src/core/attachment_service.js';
18
+ import { createLucidTestDatabase } from './helpers/lucid_test_database.js';
19
+ class ColumnUser extends BaseModel {
20
+ static table = 'column_users';
21
+ static selfAssignPrimaryKey = true;
22
+ }
23
+ __decorate([
24
+ column({ isPrimary: true })
25
+ ], ColumnUser.prototype, "id", void 0);
26
+ __decorate([
27
+ column()
28
+ ], ColumnUser.prototype, "name", void 0);
29
+ __decorate([
30
+ attachment()
31
+ ], ColumnUser.prototype, "avatar", void 0);
32
+ let database;
33
+ let attachments;
34
+ let removed;
35
+ async function createAttachment(name) {
36
+ return attachments.create({
37
+ body: Buffer.from(name),
38
+ originalName: name,
39
+ mimeType: 'text/plain',
40
+ });
41
+ }
42
+ test.group('Lucid attachment column', (group) => {
43
+ group.setup(async () => {
44
+ database = await createLucidTestDatabase();
45
+ ColumnUser.useAdapter(database.modelAdapter());
46
+ await database.connection().schema.createTable('column_users', (table) => {
47
+ table.string('id').primary();
48
+ table.string('name').notNullable().unique();
49
+ table.json('avatar').nullable();
50
+ });
51
+ });
52
+ group.each.setup(async () => {
53
+ removed = [];
54
+ await database.from('column_users').delete();
55
+ attachments = new AttachmentService({
56
+ defaultDisk: 'fs',
57
+ queue: { async enqueue() { } },
58
+ storage: {
59
+ async write() { },
60
+ async read() {
61
+ return new Uint8Array();
62
+ },
63
+ async remove(location) {
64
+ removed.push(location.path);
65
+ },
66
+ },
67
+ });
68
+ setApp({
69
+ container: {
70
+ async make(binding) {
71
+ if (binding !== 'jrmc.attachment') {
72
+ throw new Error(`Unexpected binding: ${binding}`);
73
+ }
74
+ return attachments;
75
+ },
76
+ },
77
+ });
78
+ });
79
+ group.teardown(async () => {
80
+ await database.manager.closeAll();
81
+ });
82
+ test('serializes an attachment and removes the replaced file after save', async ({ assert }) => {
83
+ const first = await createAttachment('first.txt');
84
+ const user = new ColumnUser();
85
+ user.id = 'user-1';
86
+ user.name = 'Jeremy';
87
+ user.avatar = first;
88
+ await user.save();
89
+ const reloaded = await ColumnUser.findOrFail(user.id);
90
+ assert.deepEqual(reloaded.avatar, first);
91
+ assert.deepEqual(removed, []);
92
+ const replacement = await createAttachment('replacement.txt');
93
+ user.avatar = replacement;
94
+ await user.save();
95
+ assert.deepEqual(removed, [first.path]);
96
+ });
97
+ test('removes a newly assigned file when save fails', async ({ assert }) => {
98
+ const existing = new ColumnUser();
99
+ existing.id = 'user-1';
100
+ existing.name = 'Jeremy';
101
+ existing.avatar = await createAttachment('existing.txt');
102
+ await existing.save();
103
+ removed = [];
104
+ const failedAttachment = await createAttachment('failed.txt');
105
+ const duplicate = new ColumnUser();
106
+ duplicate.id = 'user-1';
107
+ duplicate.name = 'Duplicate';
108
+ duplicate.avatar = failedAttachment;
109
+ await assert.rejects(() => duplicate.save(), /UNIQUE constraint failed/);
110
+ assert.deepEqual(removed, [failedAttachment.path]);
111
+ });
112
+ test('removes a newly assigned file when its transaction rolls back', async ({ assert }) => {
113
+ const pendingAttachment = await createAttachment('rollback.txt');
114
+ await assert.rejects(() => database.transaction(async (trx) => {
115
+ const user = new ColumnUser();
116
+ user.id = 'user-1';
117
+ user.name = 'Jeremy';
118
+ user.avatar = pendingAttachment;
119
+ user.useTransaction(trx);
120
+ await user.save();
121
+ throw new Error('Rollback requested');
122
+ }), /Rollback requested/);
123
+ assert.deepEqual(removed, [pendingAttachment.path]);
124
+ });
125
+ test('removes the attachment after deleting its owner', async ({ assert }) => {
126
+ const avatar = await createAttachment('avatar.txt');
127
+ const user = new ColumnUser();
128
+ user.id = 'user-1';
129
+ user.name = 'Jeremy';
130
+ user.avatar = avatar;
131
+ await user.save();
132
+ removed = [];
133
+ await user.delete();
134
+ assert.deepEqual(removed, [avatar.path]);
135
+ });
136
+ });
137
+ //# sourceMappingURL=lucid_attachment_column.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lucid_attachment_column.spec.js","sourceRoot":"","sources":["../../tests/lucid_attachment_column.spec.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;;;;;;;AAGH,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAA;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAEnC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAExC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAA;AACrE,OAAO,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAA;AAE1E,MAAM,UAAW,SAAQ,SAAS;IAChC,MAAM,CAAC,KAAK,GAAG,cAAc,CAAA;IAC7B,MAAM,CAAC,oBAAoB,GAAG,IAAI,CAAA;;AAG1B;IADP,MAAM,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;sCACV;AAGV;IADP,MAAM,EAAE;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remy Chaufourier <jeremy@chaufourier.fr>
6
+ */
7
+ export {};
8
+ //# sourceMappingURL=lucid_attachment_lifecycle_service.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lucid_attachment_lifecycle_service.spec.d.ts","sourceRoot":"","sources":["../../tests/lucid_attachment_lifecycle_service.spec.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
@@ -0,0 +1,206 @@
1
+ /**
2
+ * @jrmc/adonis-attachment
3
+ *
4
+ * @license MIT
5
+ * @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
6
+ */
7
+ import { test } from '@japa/runner';
8
+ import { LucidAttachmentLifecycleService } from '../src/integrations/lucid/lucid_attachment_lifecycle_service.js';
9
+ const attachment = {
10
+ id: 'attachment-id',
11
+ disk: 'public',
12
+ path: 'users/42/avatar.jpg',
13
+ name: 'avatar.jpg',
14
+ originalName: 'profile.jpg',
15
+ mimeType: 'image/jpeg',
16
+ extname: 'jpg',
17
+ size: 42,
18
+ };
19
+ function makeRow(value, id = value.id) {
20
+ return {
21
+ id,
22
+ toAttachment() {
23
+ return value;
24
+ },
25
+ };
26
+ }
27
+ test.group('LucidAttachmentLifecycleService', () => {
28
+ test('persists the file before creating its polymorphic row', async ({ assert }) => {
29
+ const events = [];
30
+ const service = new LucidAttachmentLifecycleService({
31
+ async create() {
32
+ events.push('write');
33
+ return attachment;
34
+ },
35
+ async remove() { },
36
+ }, {
37
+ async createOriginal() {
38
+ events.push('persist');
39
+ return {};
40
+ },
41
+ async findOriginal() {
42
+ return null;
43
+ },
44
+ async listVariants() {
45
+ return [];
46
+ },
47
+ async releaseOwner() { },
48
+ async restoreOwner() { },
49
+ async remove() { },
50
+ });
51
+ await service.attach({ type: 'users', id: '42', field: 'avatar' }, {
52
+ body: new Uint8Array(),
53
+ originalName: 'profile.jpg',
54
+ });
55
+ assert.deepEqual(events, ['write', 'persist']);
56
+ });
57
+ test('removes a new file when database persistence fails', async ({ assert }) => {
58
+ const removed = [];
59
+ const service = new LucidAttachmentLifecycleService({
60
+ async create() {
61
+ return attachment;
62
+ },
63
+ async remove(value) {
64
+ removed.push(value);
65
+ },
66
+ }, {
67
+ async createOriginal() {
68
+ throw new Error('database unavailable');
69
+ },
70
+ async findOriginal() {
71
+ return null;
72
+ },
73
+ async listVariants() {
74
+ return [];
75
+ },
76
+ async releaseOwner() { },
77
+ async restoreOwner() { },
78
+ async remove() { },
79
+ });
80
+ await assert.rejects(() => service.attach({ type: 'users', id: '42', field: 'avatar' }, {
81
+ body: new Uint8Array(),
82
+ originalName: 'profile.jpg',
83
+ }), 'database unavailable');
84
+ assert.deepEqual(removed, [attachment]);
85
+ });
86
+ test('replaces the persisted row before removing the previous file', async ({ assert }) => {
87
+ const events = [];
88
+ const previousAttachment = { ...attachment, id: 'previous-id', path: 'users/42/previous.jpg' };
89
+ const currentAttachment = { ...attachment, id: 'current-id', path: 'users/42/current.jpg' };
90
+ const previous = makeRow(previousAttachment);
91
+ const current = makeRow(currentAttachment);
92
+ const service = new LucidAttachmentLifecycleService({
93
+ async create() {
94
+ events.push('write-current');
95
+ return currentAttachment;
96
+ },
97
+ async remove(value) {
98
+ events.push(`remove-file:${value.id}`);
99
+ },
100
+ }, {
101
+ async createOriginal() {
102
+ events.push('persist-current');
103
+ return current;
104
+ },
105
+ async findOriginal() {
106
+ return previous;
107
+ },
108
+ async listVariants() {
109
+ return [];
110
+ },
111
+ async releaseOwner() {
112
+ events.push('release-previous');
113
+ },
114
+ async restoreOwner() { },
115
+ async remove(row) {
116
+ events.push(`remove-row:${row.id}`);
117
+ },
118
+ });
119
+ const row = await service.replace({ type: 'users', id: '42', field: 'avatar' }, {
120
+ body: new Uint8Array(),
121
+ originalName: 'profile.jpg',
122
+ });
123
+ assert.equal(row, current);
124
+ assert.deepEqual(events, [
125
+ 'write-current',
126
+ 'release-previous',
127
+ 'persist-current',
128
+ 'remove-row:previous-id',
129
+ 'remove-file:previous-id',
130
+ ]);
131
+ });
132
+ test('restores the previous owner when replacement persistence fails', async ({ assert }) => {
133
+ const events = [];
134
+ const previous = makeRow(attachment, 'previous-id');
135
+ const currentAttachment = { ...attachment, id: 'current-id', path: 'users/42/current.jpg' };
136
+ const service = new LucidAttachmentLifecycleService({
137
+ async create() {
138
+ events.push('write-current');
139
+ return currentAttachment;
140
+ },
141
+ async remove(value) {
142
+ events.push(`remove-file:${value.id}`);
143
+ },
144
+ }, {
145
+ async createOriginal() {
146
+ throw new Error('database unavailable');
147
+ },
148
+ async findOriginal() {
149
+ return previous;
150
+ },
151
+ async listVariants() {
152
+ return [];
153
+ },
154
+ async releaseOwner() {
155
+ events.push('release-previous');
156
+ },
157
+ async restoreOwner() {
158
+ events.push('restore-previous');
159
+ },
160
+ async remove() { },
161
+ });
162
+ await assert.rejects(() => service.replace({ type: 'users', id: '42', field: 'avatar' }, {
163
+ body: new Uint8Array(),
164
+ originalName: 'profile.jpg',
165
+ }), 'database unavailable');
166
+ assert.deepEqual(events, [
167
+ 'write-current',
168
+ 'release-previous',
169
+ 'restore-previous',
170
+ 'remove-file:current-id',
171
+ ]);
172
+ });
173
+ test('detaches the original and every persisted variant', async ({ assert }) => {
174
+ const removedRows = [];
175
+ const removedFiles = [];
176
+ const original = makeRow(attachment);
177
+ const variant = makeRow({ ...attachment, id: 'variant-id', path: 'users/42/thumbnail.webp' });
178
+ const service = new LucidAttachmentLifecycleService({
179
+ async create() {
180
+ return attachment;
181
+ },
182
+ async remove(value) {
183
+ removedFiles.push(value.id);
184
+ },
185
+ }, {
186
+ async createOriginal() {
187
+ return original;
188
+ },
189
+ async findOriginal() {
190
+ return original;
191
+ },
192
+ async listVariants() {
193
+ return [variant];
194
+ },
195
+ async releaseOwner() { },
196
+ async restoreOwner() { },
197
+ async remove(row) {
198
+ removedRows.push(row.id);
199
+ },
200
+ });
201
+ await service.detach({ type: 'users', id: '42', field: 'avatar' });
202
+ assert.deepEqual(removedRows, ['attachment-id']);
203
+ assert.sameDeepMembers(removedFiles, ['attachment-id', 'variant-id']);
204
+ });
205
+ });
206
+ //# sourceMappingURL=lucid_attachment_lifecycle_service.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lucid_attachment_lifecycle_service.spec.js","sourceRoot":"","sources":["../../tests/lucid_attachment_lifecycle_service.spec.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAInC,OAAO,EAAE,+BAA+B,EAAE,MAAM,iEAAiE,CAAA;AAEjH,MAAM,UAAU,GAAe;IAC7B,EAAE,EAAE,eAAe;IACnB,IAAI,EAAE,QAAQ;IACd,IAAI,EAAE,qBAAqB;IAC3B,IAAI,EAAE,YAAY;IAClB,YAAY,EAAE,aAAa;IAC3B,QAAQ,EAAE,YAAY;IACtB,OAAO,EAAE,KAAK;IACd,IAAI,EAAE,EAAE;CACT,CAAA;AAED,SAAS,OAAO,CAAC,KAAiB,EAAE,EAAE,GAAG,KAAK,CAAC,EAAE;IAC/C,OAAO;QACL,EAAE;QACF,YAAY;YACV,OAAO,KAAK,CAAA;QACd,CAAC;KACiB,CAAA;AACtB,CAAC;AAED,IAAI,CAAC,KAAK,CAAC,iCAAiC,EAAE,GAAG,EAAE;IACjD,IAAI,CAAC,uDAAuD,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;QACjF,MAAM,MAAM,GAAa,EAAE,CAAA;QAC3B,MAAM,OAAO,GAAG,IAAI,+BAA+B,CACjD;YACE,KAAK,CAAC,MAAM;gBACV,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;gBACpB,OAAO,UAAU,CAAA;YACnB,CAAC;YACD,KAAK,CAAC,MAAM,KAAI,CAAC;SAClB,EACD;YACE,KAAK,CAAC,cAAc;gBAClB,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;gBACtB,OAAO,EAAqB,CAAA;YAC9B,CAAC;YACD,KAAK,CAAC,YAAY;gBAChB,OAAO,IAAI,CAAA;YACb,CAAC;YAC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CACjD;YACE,KAAK,CAAC,MAAM;gBACV,OAAO,UAAU,CAAA;YACnB,CAAC;YACD,KAAK,CAAC,MAAM,CAAC,KAAK;gBAChB,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;YAC7B,CAAC;SACF,EACD;YACE,KAAK,CAAC,cAAc;gBAClB,OAAO,QAAQ,CAAA;YACjB,CAAC;YACD,KAAK,CAAC,YAAY;gBAChB,OAAO,QAAQ,CAAA;YACjB,CAAC;YACD,KAAK,CAAC,YAAY;gBAChB,OAAO,CAAC,OAAO,CAAC,CAAA;YAClB,CAAC;YACD,KAAK,CAAC,YAAY,KAAI,CAAC;YACvB,KAAK,CAAC,YAAY,KAAI,CAAC;YACvB,KAAK,CAAC,MAAM,CAAC,GAAG;gBACd,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;YAC1B,CAAC;SACF,CACF,CAAA;QAED,MAAM,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAA;QAElE,MAAM,CAAC,SAAS,CAAC,WAAW,EAAE,CAAC,eAAe,CAAC,CAAC,CAAA;QAChD,MAAM,CAAC,eAAe,CAAC,YAAY,EAAE,CAAC,eAAe,EAAE,YAAY,CAAC,CAAC,CAAA;IACvE,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @jrmc/adonis-attachment
3
+ *
4
+ * @license MIT
5
+ * @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
6
+ */
7
+ export {};
8
+ //# sourceMappingURL=lucid_attachment_repository.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lucid_attachment_repository.spec.d.ts","sourceRoot":"","sources":["../../tests/lucid_attachment_repository.spec.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * @jrmc/adonis-attachment
3
+ *
4
+ * @license MIT
5
+ * @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
6
+ */
7
+ import { test } from '@japa/runner';
8
+ import { LucidAttachmentRepository } from '../src/integrations/lucid/lucid_attachment_repository.js';
9
+ test.group('LucidAttachmentRepository', () => {
10
+ test('maps the configured Lucid model to a core attachment', async ({ assert }) => {
11
+ const repository = new LucidAttachmentRepository({
12
+ async find(id) {
13
+ assert.equal(id, 'attachment-id');
14
+ return {
15
+ toAttachment() {
16
+ return {
17
+ id,
18
+ disk: 'public',
19
+ path: 'users/42/avatar.jpg',
20
+ name: 'avatar.jpg',
21
+ originalName: 'profile.jpg',
22
+ mimeType: 'image/jpeg',
23
+ extname: 'jpg',
24
+ size: 42,
25
+ };
26
+ },
27
+ };
28
+ },
29
+ });
30
+ assert.deepEqual(await repository.findById('attachment-id'), {
31
+ id: 'attachment-id',
32
+ disk: 'public',
33
+ path: 'users/42/avatar.jpg',
34
+ name: 'avatar.jpg',
35
+ originalName: 'profile.jpg',
36
+ mimeType: 'image/jpeg',
37
+ extname: 'jpg',
38
+ size: 42,
39
+ });
40
+ });
41
+ test('returns null when the attachment cannot be found', async ({ assert }) => {
42
+ const repository = new LucidAttachmentRepository({
43
+ async find() {
44
+ return null;
45
+ },
46
+ });
47
+ assert.isNull(await repository.findById('missing'));
48
+ });
49
+ });
50
+ //# sourceMappingURL=lucid_attachment_repository.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lucid_attachment_repository.spec.js","sourceRoot":"","sources":["../../tests/lucid_attachment_repository.spec.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAEnC,OAAO,EAAE,yBAAyB,EAAE,MAAM,0DAA0D,CAAA;AAGpG,IAAI,CAAC,KAAK,CAAC,2BAA2B,EAAE,GAAG,EAAE;IAC3C,IAAI,CAAC,sDAAsD,EAAE,KAAK,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chaufourier.fr>
6
+ */
7
+ export {};
8
+ //# sourceMappingURL=lucid_attachment_store.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lucid_attachment_store.spec.d.ts","sourceRoot":"","sources":["../../tests/lucid_attachment_store.spec.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}