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

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 (424) 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 +26 -10
  19. package/build/index.d.ts.map +1 -1
  20. package/build/index.js +16 -9
  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 +70 -0
  43. package/build/src/core/attachment.d.ts.map +1 -0
  44. package/build/src/core/attachment.js +150 -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_options.d.ts +32 -0
  51. package/build/src/core/attachment_options.d.ts.map +1 -0
  52. package/build/src/core/attachment_options.js +24 -0
  53. package/build/src/core/attachment_options.js.map +1 -0
  54. package/build/src/core/attachment_repository.d.ts +15 -0
  55. package/build/src/core/attachment_repository.d.ts.map +1 -0
  56. package/build/src/core/attachment_repository.js +8 -0
  57. package/build/src/core/attachment_repository.js.map +1 -0
  58. package/build/src/core/attachment_service.d.ts +34 -0
  59. package/build/src/core/attachment_service.d.ts.map +1 -0
  60. package/build/src/core/attachment_service.js +93 -0
  61. package/build/src/core/attachment_service.js.map +1 -0
  62. package/build/src/core/attachment_state.d.ts +11 -0
  63. package/build/src/core/attachment_state.d.ts.map +1 -0
  64. package/build/src/core/attachment_state.js +17 -0
  65. package/build/src/core/attachment_state.js.map +1 -0
  66. package/build/src/core/index.d.ts +14 -0
  67. package/build/src/core/index.d.ts.map +1 -0
  68. package/build/src/core/index.js +11 -0
  69. package/build/src/core/index.js.map +1 -0
  70. package/build/src/core/queue.d.ts +20 -0
  71. package/build/src/core/queue.d.ts.map +1 -0
  72. package/build/src/{types/event.js → core/queue.js} +1 -0
  73. package/build/src/core/queue.js.map +1 -0
  74. package/build/src/core/storage.d.ts +23 -0
  75. package/build/src/core/storage.d.ts.map +1 -0
  76. package/build/src/{types/config.js → core/storage.js} +1 -0
  77. package/build/src/core/storage.js.map +1 -0
  78. package/build/src/define_config.d.ts +39 -20
  79. package/build/src/define_config.d.ts.map +1 -1
  80. package/build/src/define_config.js +46 -24
  81. package/build/src/define_config.js.map +1 -0
  82. package/build/src/integrations/lucid/attachment_column.d.ts +18 -0
  83. package/build/src/integrations/lucid/attachment_column.d.ts.map +1 -0
  84. package/build/src/integrations/lucid/attachment_column.js +151 -0
  85. package/build/src/integrations/lucid/attachment_column.js.map +1 -0
  86. package/build/src/integrations/lucid/attachment_model.d.ts +37 -0
  87. package/build/src/integrations/lucid/attachment_model.d.ts.map +1 -0
  88. package/build/src/integrations/lucid/attachment_model.js +99 -0
  89. package/build/src/integrations/lucid/attachment_model.js.map +1 -0
  90. package/build/src/integrations/lucid/attachment_owner.d.ts +18 -0
  91. package/build/src/integrations/lucid/attachment_owner.d.ts.map +1 -0
  92. package/build/src/integrations/lucid/attachment_owner.js +15 -0
  93. package/build/src/integrations/lucid/attachment_owner.js.map +1 -0
  94. package/build/src/integrations/lucid/attachment_relation.d.ts +60 -0
  95. package/build/src/integrations/lucid/attachment_relation.d.ts.map +1 -0
  96. package/build/src/integrations/lucid/attachment_relation.js +163 -0
  97. package/build/src/integrations/lucid/attachment_relation.js.map +1 -0
  98. package/build/src/integrations/lucid/attachments_table_stub.d.ts +21 -0
  99. package/build/src/integrations/lucid/attachments_table_stub.d.ts.map +1 -0
  100. package/build/src/integrations/lucid/attachments_table_stub.js +26 -0
  101. package/build/src/integrations/lucid/attachments_table_stub.js.map +1 -0
  102. package/build/src/integrations/lucid/create_legacy_attachment_migration_script.d.ts +13 -0
  103. package/build/src/integrations/lucid/create_legacy_attachment_migration_script.d.ts.map +1 -0
  104. package/build/src/integrations/lucid/create_legacy_attachment_migration_script.js +20 -0
  105. package/build/src/integrations/lucid/create_legacy_attachment_migration_script.js.map +1 -0
  106. package/build/src/integrations/lucid/index.d.ts +20 -0
  107. package/build/src/integrations/lucid/index.d.ts.map +1 -0
  108. package/build/src/integrations/lucid/index.js +20 -0
  109. package/build/src/integrations/lucid/index.js.map +1 -0
  110. package/build/src/integrations/lucid/lucid_attachment_lifecycle_service.d.ts +30 -0
  111. package/build/src/integrations/lucid/lucid_attachment_lifecycle_service.d.ts.map +1 -0
  112. package/build/src/integrations/lucid/lucid_attachment_lifecycle_service.js +188 -0
  113. package/build/src/integrations/lucid/lucid_attachment_lifecycle_service.js.map +1 -0
  114. package/build/src/integrations/lucid/lucid_attachment_repository.d.ts +18 -0
  115. package/build/src/integrations/lucid/lucid_attachment_repository.d.ts.map +1 -0
  116. package/build/src/integrations/lucid/lucid_attachment_repository.js +21 -0
  117. package/build/src/integrations/lucid/lucid_attachment_repository.js.map +1 -0
  118. package/build/src/integrations/lucid/lucid_attachment_store.d.ts +36 -0
  119. package/build/src/integrations/lucid/lucid_attachment_store.d.ts.map +1 -0
  120. package/build/src/integrations/lucid/lucid_attachment_store.js +179 -0
  121. package/build/src/integrations/lucid/lucid_attachment_store.js.map +1 -0
  122. package/build/src/integrations/lucid/lucid_variant_generation_service.d.ts +24 -0
  123. package/build/src/integrations/lucid/lucid_variant_generation_service.d.ts.map +1 -0
  124. package/build/src/integrations/lucid/lucid_variant_generation_service.js +42 -0
  125. package/build/src/integrations/lucid/lucid_variant_generation_service.js.map +1 -0
  126. package/build/src/integrations/lucid/migrate_legacy_attachment.d.ts +64 -0
  127. package/build/src/integrations/lucid/migrate_legacy_attachment.d.ts.map +1 -0
  128. package/build/src/integrations/lucid/migrate_legacy_attachment.js +89 -0
  129. package/build/src/integrations/lucid/migrate_legacy_attachment.js.map +1 -0
  130. package/build/src/integrations/lucid/migrate_legacy_attachment_records.d.ts +34 -0
  131. package/build/src/integrations/lucid/migrate_legacy_attachment_records.d.ts.map +1 -0
  132. package/build/src/integrations/lucid/migrate_legacy_attachment_records.js +47 -0
  133. package/build/src/integrations/lucid/migrate_legacy_attachment_records.js.map +1 -0
  134. package/build/src/integrations/lucid/render_legacy_attachment_migration_script.d.ts +11 -0
  135. package/build/src/integrations/lucid/render_legacy_attachment_migration_script.d.ts.map +1 -0
  136. package/build/src/integrations/lucid/render_legacy_attachment_migration_script.js +41 -0
  137. package/build/src/integrations/lucid/render_legacy_attachment_migration_script.js.map +1 -0
  138. package/build/src/queues/adonis_queue.d.ts +27 -0
  139. package/build/src/queues/adonis_queue.d.ts.map +1 -0
  140. package/build/src/queues/adonis_queue.js +22 -0
  141. package/build/src/queues/adonis_queue.js.map +1 -0
  142. package/build/src/queues/memory_queue.d.ts +22 -0
  143. package/build/src/queues/memory_queue.d.ts.map +1 -0
  144. package/build/src/queues/memory_queue.js +67 -0
  145. package/build/src/queues/memory_queue.js.map +1 -0
  146. package/build/src/sources/attachment_manager.d.ts +53 -0
  147. package/build/src/sources/attachment_manager.d.ts.map +1 -0
  148. package/build/src/sources/attachment_manager.js +177 -0
  149. package/build/src/sources/attachment_manager.js.map +1 -0
  150. package/build/src/variants/variant_converter.d.ts +23 -0
  151. package/build/src/variants/variant_converter.d.ts.map +1 -0
  152. package/build/src/{types/converter.js → variants/variant_converter.js} +1 -0
  153. package/build/src/variants/variant_converter.js.map +1 -0
  154. package/build/src/variants/variant_generation_service.d.ts +28 -0
  155. package/build/src/variants/variant_generation_service.d.ts.map +1 -0
  156. package/build/src/variants/variant_generation_service.js +44 -0
  157. package/build/src/variants/variant_generation_service.js.map +1 -0
  158. package/build/stubs/config/attachment.stub +12 -0
  159. package/build/stubs/main.d.ts.map +1 -1
  160. package/build/stubs/main.js +1 -0
  161. package/build/stubs/main.js.map +1 -0
  162. package/build/stubs/migrations/attachments_table.stub +39 -0
  163. package/build/tests/adonis_drive_storage.spec.d.ts +8 -0
  164. package/build/tests/adonis_drive_storage.spec.d.ts.map +1 -0
  165. package/build/tests/adonis_drive_storage.spec.js +69 -0
  166. package/build/tests/adonis_drive_storage.spec.js.map +1 -0
  167. package/build/{src/types/attachment.js → tests/adonis_queue.spec.d.ts} +1 -0
  168. package/build/tests/adonis_queue.spec.d.ts.map +1 -0
  169. package/build/tests/adonis_queue.spec.js +52 -0
  170. package/build/tests/adonis_queue.spec.js.map +1 -0
  171. package/build/tests/attachment_job_processor.spec.d.ts +8 -0
  172. package/build/tests/attachment_job_processor.spec.d.ts.map +1 -0
  173. package/build/tests/attachment_job_processor.spec.js +89 -0
  174. package/build/tests/attachment_job_processor.spec.js.map +1 -0
  175. package/build/tests/attachment_manager.spec.d.ts +8 -0
  176. package/build/tests/attachment_manager.spec.d.ts.map +1 -0
  177. package/build/tests/attachment_manager.spec.js +131 -0
  178. package/build/tests/attachment_manager.spec.js.map +1 -0
  179. package/build/tests/attachment_manager_service.spec.d.ts +8 -0
  180. package/build/tests/attachment_manager_service.spec.d.ts.map +1 -0
  181. package/build/tests/attachment_manager_service.spec.js +47 -0
  182. package/build/tests/attachment_manager_service.spec.js.map +1 -0
  183. package/build/tests/attachment_options.spec.d.ts +2 -0
  184. package/build/tests/attachment_options.spec.d.ts.map +1 -0
  185. package/build/tests/attachment_options.spec.js +31 -0
  186. package/build/tests/attachment_options.spec.js.map +1 -0
  187. package/build/tests/attachment_provider.spec.d.ts +8 -0
  188. package/build/tests/attachment_provider.spec.d.ts.map +1 -0
  189. package/build/tests/attachment_provider.spec.js +71 -0
  190. package/build/tests/attachment_provider.spec.js.map +1 -0
  191. package/build/tests/attachment_service.spec.d.ts +8 -0
  192. package/build/tests/attachment_service.spec.d.ts.map +1 -0
  193. package/build/tests/attachment_service.spec.js +146 -0
  194. package/build/tests/attachment_service.spec.js.map +1 -0
  195. package/build/tests/attachments_controller.spec.d.ts +8 -0
  196. package/build/tests/attachments_controller.spec.d.ts.map +1 -0
  197. package/build/tests/attachments_controller.spec.js +34 -0
  198. package/build/tests/attachments_controller.spec.js.map +1 -0
  199. package/build/tests/attachments_table_stub.spec.d.ts +2 -0
  200. package/build/tests/attachments_table_stub.spec.d.ts.map +1 -0
  201. package/build/tests/attachments_table_stub.spec.js +66 -0
  202. package/build/tests/attachments_table_stub.spec.js.map +1 -0
  203. package/build/tests/configure.spec.d.ts +2 -0
  204. package/build/tests/configure.spec.d.ts.map +1 -0
  205. package/build/tests/configure.spec.js +38 -0
  206. package/build/tests/configure.spec.js.map +1 -0
  207. package/build/tests/container_bindings.types.d.ts +8 -0
  208. package/build/tests/container_bindings.types.d.ts.map +1 -0
  209. package/build/tests/container_bindings.types.js +9 -0
  210. package/build/tests/container_bindings.types.js.map +1 -0
  211. package/build/tests/create_legacy_attachment_migration_script.spec.d.ts +8 -0
  212. package/build/tests/create_legacy_attachment_migration_script.spec.d.ts.map +1 -0
  213. package/build/tests/create_legacy_attachment_migration_script.spec.js +31 -0
  214. package/build/tests/create_legacy_attachment_migration_script.spec.js.map +1 -0
  215. package/build/tests/define_config.spec.d.ts +8 -0
  216. package/build/tests/define_config.spec.d.ts.map +1 -0
  217. package/build/tests/define_config.spec.js +203 -0
  218. package/build/tests/define_config.spec.js.map +1 -0
  219. package/build/tests/helpers/lucid_test_database.d.ts +9 -0
  220. package/build/tests/helpers/lucid_test_database.d.ts.map +1 -0
  221. package/build/tests/helpers/lucid_test_database.js +52 -0
  222. package/build/tests/helpers/lucid_test_database.js.map +1 -0
  223. package/build/tests/local_file_storage.spec.d.ts +8 -0
  224. package/build/tests/local_file_storage.spec.d.ts.map +1 -0
  225. package/build/tests/local_file_storage.spec.js +44 -0
  226. package/build/tests/local_file_storage.spec.js.map +1 -0
  227. package/build/tests/lucid_attachment_collection_store.spec.d.ts +2 -0
  228. package/build/tests/lucid_attachment_collection_store.spec.d.ts.map +1 -0
  229. package/build/tests/lucid_attachment_collection_store.spec.js +52 -0
  230. package/build/tests/lucid_attachment_collection_store.spec.js.map +1 -0
  231. package/build/tests/lucid_attachment_column.spec.d.ts +8 -0
  232. package/build/tests/lucid_attachment_column.spec.d.ts.map +1 -0
  233. package/build/tests/lucid_attachment_column.spec.js +193 -0
  234. package/build/tests/lucid_attachment_column.spec.js.map +1 -0
  235. package/build/tests/lucid_attachment_lifecycle_service.spec.d.ts +8 -0
  236. package/build/tests/lucid_attachment_lifecycle_service.spec.d.ts.map +1 -0
  237. package/build/tests/lucid_attachment_lifecycle_service.spec.js +378 -0
  238. package/build/tests/lucid_attachment_lifecycle_service.spec.js.map +1 -0
  239. package/build/tests/lucid_attachment_relation.spec.d.ts +8 -0
  240. package/build/tests/lucid_attachment_relation.spec.d.ts.map +1 -0
  241. package/build/tests/lucid_attachment_relation.spec.js +216 -0
  242. package/build/tests/lucid_attachment_relation.spec.js.map +1 -0
  243. package/build/tests/lucid_attachment_repository.spec.d.ts +8 -0
  244. package/build/tests/lucid_attachment_repository.spec.d.ts.map +1 -0
  245. package/build/tests/lucid_attachment_repository.spec.js +50 -0
  246. package/build/tests/lucid_attachment_repository.spec.js.map +1 -0
  247. package/build/tests/lucid_attachment_store.spec.d.ts +8 -0
  248. package/build/tests/lucid_attachment_store.spec.d.ts.map +1 -0
  249. package/build/tests/lucid_attachment_store.spec.js +73 -0
  250. package/build/tests/lucid_attachment_store.spec.js.map +1 -0
  251. package/build/tests/lucid_sqlite_integration.spec.d.ts +8 -0
  252. package/build/tests/lucid_sqlite_integration.spec.d.ts.map +1 -0
  253. package/build/tests/lucid_sqlite_integration.spec.js +103 -0
  254. package/build/tests/lucid_sqlite_integration.spec.js.map +1 -0
  255. package/build/tests/lucid_variant_generation_service.spec.d.ts +8 -0
  256. package/build/tests/lucid_variant_generation_service.spec.d.ts.map +1 -0
  257. package/build/tests/lucid_variant_generation_service.spec.js +56 -0
  258. package/build/tests/lucid_variant_generation_service.spec.js.map +1 -0
  259. package/build/tests/memory_queue.spec.d.ts +8 -0
  260. package/build/tests/memory_queue.spec.d.ts.map +1 -0
  261. package/build/tests/memory_queue.spec.js +52 -0
  262. package/build/tests/memory_queue.spec.js.map +1 -0
  263. package/build/tests/migrate_legacy_attachment.spec.d.ts +8 -0
  264. package/build/tests/migrate_legacy_attachment.spec.d.ts.map +1 -0
  265. package/build/tests/migrate_legacy_attachment.spec.js +133 -0
  266. package/build/tests/migrate_legacy_attachment.spec.js.map +1 -0
  267. package/build/tests/migrate_legacy_attachment_records.spec.d.ts +8 -0
  268. package/build/tests/migrate_legacy_attachment_records.spec.d.ts.map +1 -0
  269. package/build/tests/migrate_legacy_attachment_records.spec.js +66 -0
  270. package/build/tests/migrate_legacy_attachment_records.spec.js.map +1 -0
  271. package/build/tests/package_exports.spec.d.ts +8 -0
  272. package/build/tests/package_exports.spec.d.ts.map +1 -0
  273. package/build/tests/package_exports.spec.js +31 -0
  274. package/build/tests/package_exports.spec.js.map +1 -0
  275. package/build/tests/variant_generation_service.spec.d.ts +8 -0
  276. package/build/tests/variant_generation_service.spec.d.ts.map +1 -0
  277. package/build/tests/variant_generation_service.spec.js +79 -0
  278. package/build/tests/variant_generation_service.spec.js.map +1 -0
  279. package/package.json +82 -76
  280. package/build/commands/make/converter.d.ts.map +0 -1
  281. package/build/commands/make/converter.js +0 -28
  282. package/build/services/regenerate_service.d.ts +0 -9
  283. package/build/services/regenerate_service.d.ts.map +0 -1
  284. package/build/services/regenerate_service.js +0 -29
  285. package/build/src/adapters/blurhash.d.ts +0 -11
  286. package/build/src/adapters/blurhash.d.ts.map +0 -1
  287. package/build/src/adapters/blurhash.js +0 -12
  288. package/build/src/adapters/exif.d.ts +0 -15
  289. package/build/src/adapters/exif.d.ts.map +0 -1
  290. package/build/src/adapters/exif.js +0 -165
  291. package/build/src/adapters/ffmpeg.d.ts +0 -19
  292. package/build/src/adapters/ffmpeg.d.ts.map +0 -1
  293. package/build/src/adapters/ffmpeg.js +0 -115
  294. package/build/src/adapters/lock.d.ts +0 -9
  295. package/build/src/adapters/lock.d.ts.map +0 -1
  296. package/build/src/adapters/lock.js +0 -21
  297. package/build/src/adapters/meta.d.ts +0 -10
  298. package/build/src/adapters/meta.d.ts.map +0 -1
  299. package/build/src/adapters/meta.js +0 -49
  300. package/build/src/adapters/poppler.d.ts +0 -20
  301. package/build/src/adapters/poppler.d.ts.map +0 -1
  302. package/build/src/adapters/poppler.js +0 -117
  303. package/build/src/adapters/soffice.d.ts +0 -14
  304. package/build/src/adapters/soffice.d.ts.map +0 -1
  305. package/build/src/adapters/soffice.js +0 -64
  306. package/build/src/attachment_manager.d.ts +0 -50
  307. package/build/src/attachment_manager.d.ts.map +0 -1
  308. package/build/src/attachment_manager.js +0 -145
  309. package/build/src/attachments/attachment.d.ts +0 -42
  310. package/build/src/attachments/attachment.d.ts.map +0 -1
  311. package/build/src/attachments/attachment.js +0 -233
  312. package/build/src/attachments/attachment_base.d.ts +0 -59
  313. package/build/src/attachments/attachment_base.d.ts.map +0 -1
  314. package/build/src/attachments/attachment_base.js +0 -211
  315. package/build/src/attachments/variant_attachment.d.ts +0 -27
  316. package/build/src/attachments/variant_attachment.d.ts.map +0 -1
  317. package/build/src/attachments/variant_attachment.js +0 -40
  318. package/build/src/converters/autodetect_converter.d.ts +0 -13
  319. package/build/src/converters/autodetect_converter.d.ts.map +0 -1
  320. package/build/src/converters/autodetect_converter.js +0 -77
  321. package/build/src/converters/converter.d.ts +0 -14
  322. package/build/src/converters/converter.d.ts.map +0 -1
  323. package/build/src/converters/converter.js +0 -14
  324. package/build/src/converters/document_thumbnail_converter.d.ts +0 -14
  325. package/build/src/converters/document_thumbnail_converter.d.ts.map +0 -1
  326. package/build/src/converters/document_thumbnail_converter.js +0 -36
  327. package/build/src/converters/image_converter.d.ts +0 -13
  328. package/build/src/converters/image_converter.d.ts.map +0 -1
  329. package/build/src/converters/image_converter.js +0 -27
  330. package/build/src/converters/pdf_thumbnail_converter.d.ts +0 -14
  331. package/build/src/converters/pdf_thumbnail_converter.d.ts.map +0 -1
  332. package/build/src/converters/pdf_thumbnail_converter.js +0 -39
  333. package/build/src/converters/video_thumbnail_converter.d.ts +0 -14
  334. package/build/src/converters/video_thumbnail_converter.d.ts.map +0 -1
  335. package/build/src/converters/video_thumbnail_converter.js +0 -40
  336. package/build/src/decorators/attachment.d.ts +0 -15
  337. package/build/src/decorators/attachment.d.ts.map +0 -1
  338. package/build/src/decorators/attachment.js +0 -103
  339. package/build/src/errors.d.ts +0 -67
  340. package/build/src/errors.d.ts.map +0 -1
  341. package/build/src/errors.js +0 -68
  342. package/build/src/services/attachment/attachment_detachment_service.d.ts +0 -19
  343. package/build/src/services/attachment/attachment_detachment_service.d.ts.map +0 -1
  344. package/build/src/services/attachment/attachment_detachment_service.js +0 -66
  345. package/build/src/services/attachment/attachment_persister_service.d.ts +0 -22
  346. package/build/src/services/attachment/attachment_persister_service.d.ts.map +0 -1
  347. package/build/src/services/attachment/attachment_persister_service.js +0 -96
  348. package/build/src/services/attachment/attachment_recorder_service.d.ts +0 -68
  349. package/build/src/services/attachment/attachment_recorder_service.d.ts.map +0 -1
  350. package/build/src/services/attachment/attachment_recorder_service.js +0 -121
  351. package/build/src/services/attachment/attachment_transaction_service.d.ts +0 -26
  352. package/build/src/services/attachment/attachment_transaction_service.d.ts.map +0 -1
  353. package/build/src/services/attachment/attachment_transaction_service.js +0 -46
  354. package/build/src/services/attachment/attachment_utils.d.ts +0 -35
  355. package/build/src/services/attachment/attachment_utils.d.ts.map +0 -1
  356. package/build/src/services/attachment/attachment_utils.js +0 -71
  357. package/build/src/services/attachment/attachment_variant_service.d.ts +0 -17
  358. package/build/src/services/attachment/attachment_variant_service.d.ts.map +0 -1
  359. package/build/src/services/attachment/attachment_variant_service.js +0 -99
  360. package/build/src/services/attachment/index.d.ts +0 -15
  361. package/build/src/services/attachment/index.d.ts.map +0 -1
  362. package/build/src/services/attachment/index.js +0 -15
  363. package/build/src/services/attachment_service.d.ts +0 -8
  364. package/build/src/services/attachment_service.d.ts.map +0 -1
  365. package/build/src/services/attachment_service.js +0 -7
  366. package/build/src/services/variant/variant_generator_service.d.ts +0 -24
  367. package/build/src/services/variant/variant_generator_service.d.ts.map +0 -1
  368. package/build/src/services/variant/variant_generator_service.js +0 -101
  369. package/build/src/services/variant/variant_persister_service.d.ts +0 -24
  370. package/build/src/services/variant/variant_persister_service.d.ts.map +0 -1
  371. package/build/src/services/variant/variant_persister_service.js +0 -59
  372. package/build/src/services/variant/variant_purger_service.d.ts +0 -15
  373. package/build/src/services/variant/variant_purger_service.d.ts.map +0 -1
  374. package/build/src/services/variant/variant_purger_service.js +0 -47
  375. package/build/src/services/variant_service.d.ts +0 -13
  376. package/build/src/services/variant_service.d.ts.map +0 -1
  377. package/build/src/services/variant_service.js +0 -63
  378. package/build/src/types/attachment.d.ts +0 -100
  379. package/build/src/types/attachment.d.ts.map +0 -1
  380. package/build/src/types/config.d.ts +0 -58
  381. package/build/src/types/config.d.ts.map +0 -1
  382. package/build/src/types/converter.d.ts +0 -144
  383. package/build/src/types/converter.d.ts.map +0 -1
  384. package/build/src/types/drive.d.ts +0 -6
  385. package/build/src/types/drive.d.ts.map +0 -1
  386. package/build/src/types/drive.js +0 -1
  387. package/build/src/types/event.d.ts +0 -16
  388. package/build/src/types/event.d.ts.map +0 -1
  389. package/build/src/types/index.d.ts +0 -15
  390. package/build/src/types/index.d.ts.map +0 -1
  391. package/build/src/types/index.js +0 -14
  392. package/build/src/types/input.d.ts +0 -35
  393. package/build/src/types/input.d.ts.map +0 -1
  394. package/build/src/types/input.js +0 -7
  395. package/build/src/types/lock.d.ts +0 -14
  396. package/build/src/types/lock.d.ts.map +0 -1
  397. package/build/src/types/lock.js +0 -7
  398. package/build/src/types/metadata.d.ts +0 -24
  399. package/build/src/types/metadata.d.ts.map +0 -1
  400. package/build/src/types/metadata.js +0 -7
  401. package/build/src/types/mixin.d.ts +0 -17
  402. package/build/src/types/mixin.d.ts.map +0 -1
  403. package/build/src/types/mixin.js +0 -7
  404. package/build/src/types/regenerate.d.ts +0 -12
  405. package/build/src/types/regenerate.d.ts.map +0 -1
  406. package/build/src/types/regenerate.js +0 -7
  407. package/build/src/types/service.d.ts +0 -25
  408. package/build/src/types/service.d.ts.map +0 -1
  409. package/build/src/types/service.js +0 -7
  410. package/build/src/utils/default_values.d.ts +0 -20
  411. package/build/src/utils/default_values.d.ts.map +0 -1
  412. package/build/src/utils/default_values.js +0 -19
  413. package/build/src/utils/helpers.d.ts +0 -19
  414. package/build/src/utils/helpers.d.ts.map +0 -1
  415. package/build/src/utils/helpers.js +0 -131
  416. package/build/src/utils/hooks.d.ts +0 -12
  417. package/build/src/utils/hooks.d.ts.map +0 -1
  418. package/build/src/utils/hooks.js +0 -42
  419. package/build/src/utils/symbols.d.ts +0 -8
  420. package/build/src/utils/symbols.d.ts.map +0 -1
  421. package/build/src/utils/symbols.js +0 -7
  422. package/build/stubs/config.stub +0 -140
  423. package/build/stubs/make/converter/main.stub +0 -20
  424. package/build/tsconfig.tsbuildinfo +0 -1
@@ -0,0 +1,177 @@
1
+ /**
2
+ * @jrmc/adonis-attachment
3
+ *
4
+ * @license MIT
5
+ * @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
6
+ */
7
+ import { basename, extname } from 'node:path';
8
+ import { readFile, stat } from 'node:fs/promises';
9
+ /**
10
+ * Normalizes common input sources into drafts. The file is written only when the
11
+ * caller invokes `draft.persist()` or an integration persists it automatically.
12
+ */
13
+ export class AttachmentManager {
14
+ #attachments;
15
+ #maxBytes;
16
+ #fetch;
17
+ constructor(attachments, options = {}) {
18
+ if (options.maxBytes !== undefined && (!Number.isSafeInteger(options.maxBytes) || options.maxBytes < 1)) {
19
+ throw new Error('Attachment source maxBytes must be a positive integer');
20
+ }
21
+ this.#attachments = attachments;
22
+ this.#maxBytes = options.maxBytes;
23
+ this.#fetch = options.fetch ?? globalThis.fetch;
24
+ }
25
+ createFromBuffer(input, options = {}) {
26
+ return this.#create(input, {
27
+ originalName: options.originalName ?? 'attachment.bin',
28
+ mimeType: options.mimeType ?? mimeTypeFromName(options.originalName),
29
+ options,
30
+ });
31
+ }
32
+ createFromBase64(input, options = {}) {
33
+ const parsed = parseBase64(input);
34
+ return this.#create(parsed.body, {
35
+ originalName: options.originalName ?? 'attachment.bin',
36
+ mimeType: options.mimeType ?? parsed.mimeType ?? mimeTypeFromName(options.originalName),
37
+ options,
38
+ });
39
+ }
40
+ async createFromPath(input, options = {}) {
41
+ const file = await stat(input);
42
+ this.#assertSize(file.size, options.maxBytes);
43
+ const body = await readFile(input);
44
+ const originalName = options.originalName ?? basename(input);
45
+ return this.#create(body, {
46
+ originalName,
47
+ mimeType: options.mimeType ?? mimeTypeFromName(originalName),
48
+ options,
49
+ });
50
+ }
51
+ async createFromStream(input, options = {}) {
52
+ const chunks = [];
53
+ let size = 0;
54
+ for await (const chunk of input) {
55
+ const bytes = typeof chunk === 'string' ? Buffer.from(chunk) : new Uint8Array(chunk);
56
+ size += bytes.byteLength;
57
+ this.#assertSize(size, options.maxBytes);
58
+ chunks.push(bytes);
59
+ }
60
+ const originalName = options.originalName ?? 'attachment.bin';
61
+ return this.#create(Buffer.concat(chunks), {
62
+ originalName,
63
+ mimeType: options.mimeType ?? mimeTypeFromName(originalName),
64
+ options,
65
+ });
66
+ }
67
+ async createFromUrl(input, options = {}) {
68
+ const response = await this.#fetch(input);
69
+ if (!response.ok) {
70
+ throw new AttachmentSourceError(`Unable to download attachment source: ${response.status} ${response.statusText}`);
71
+ }
72
+ const contentLength = response.headers.get('content-length');
73
+ if (contentLength && Number.isSafeInteger(Number(contentLength))) {
74
+ this.#assertSize(Number(contentLength), options.maxBytes);
75
+ }
76
+ const body = new Uint8Array(await response.arrayBuffer());
77
+ const url = typeof input === 'string' ? new URL(input) : input;
78
+ const originalName = options.originalName ?? (basename(url.pathname) || 'attachment.bin');
79
+ return this.#create(body, {
80
+ originalName,
81
+ mimeType: options.mimeType ?? normalizeMimeType(response.headers.get('content-type')) ?? mimeTypeFromName(originalName),
82
+ options,
83
+ });
84
+ }
85
+ createFromFile(input, options = {}) {
86
+ if (!input.tmpPath) {
87
+ throw new AttachmentSourceError('Multipart attachment file has no temporary path');
88
+ }
89
+ return this.createFromPath(input.tmpPath, {
90
+ ...options,
91
+ originalName: options.originalName ?? input.clientName,
92
+ mimeType: options.mimeType ?? multipartMimeType(input),
93
+ });
94
+ }
95
+ createFromFiles(inputs, options = {}) {
96
+ return Promise.all(inputs.map((input) => this.createFromFile(input, options)));
97
+ }
98
+ async #create(body, input) {
99
+ this.#assertSize(body.byteLength, input.options.maxBytes);
100
+ return this.#attachments.createDraft({
101
+ body,
102
+ originalName: input.originalName,
103
+ mimeType: input.mimeType,
104
+ ...(input.options.metadata ? { metadata: input.options.metadata } : {}),
105
+ }, toPersistenceOptions(input.options));
106
+ }
107
+ #assertSize(size, override) {
108
+ if (override !== undefined && (!Number.isSafeInteger(override) || override < 1)) {
109
+ throw new Error('Attachment source maxBytes must be a positive integer');
110
+ }
111
+ const maxBytes = override === undefined
112
+ ? this.#maxBytes
113
+ : this.#maxBytes === undefined
114
+ ? override
115
+ : Math.min(override, this.#maxBytes);
116
+ if (maxBytes !== undefined && size > maxBytes) {
117
+ throw new AttachmentSourceError(`Attachment source exceeds the ${maxBytes}-byte limit`);
118
+ }
119
+ }
120
+ }
121
+ function toPersistenceOptions(options) {
122
+ return {
123
+ ...(options.disk !== undefined ? { disk: options.disk } : {}),
124
+ ...(options.folder !== undefined ? { folder: options.folder } : {}),
125
+ ...(options.rename !== undefined ? { rename: options.rename } : {}),
126
+ ...(options.meta !== undefined ? { meta: options.meta } : {}),
127
+ ...(options.preComputeUrl !== undefined ? { preComputeUrl: options.preComputeUrl } : {}),
128
+ ...(options.variants !== undefined ? { variants: options.variants } : {}),
129
+ };
130
+ }
131
+ export class AttachmentSourceError extends Error {
132
+ constructor(message) {
133
+ super(message);
134
+ this.name = 'AttachmentSourceError';
135
+ }
136
+ }
137
+ function parseBase64(input) {
138
+ const dataUri = /^data:([^;,]+)?;base64,([A-Za-z0-9+/\s]*={0,2})$/i.exec(input);
139
+ const mimeType = dataUri?.[1];
140
+ const value = (dataUri?.[2] ?? input).replaceAll(/\s/g, '');
141
+ if (!isBase64(value)) {
142
+ throw new AttachmentSourceError('Attachment source must be valid Base64 data');
143
+ }
144
+ return { body: Buffer.from(value, 'base64'), ...(mimeType ? { mimeType } : {}) };
145
+ }
146
+ function isBase64(value) {
147
+ return value.length > 0 && /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(value);
148
+ }
149
+ function multipartMimeType(input) {
150
+ return input.type && input.subtype
151
+ ? `${input.type}/${input.subtype}`
152
+ : mimeTypeFromName(input.clientName);
153
+ }
154
+ function normalizeMimeType(value) {
155
+ const mimeType = value?.split(';')[0]?.trim();
156
+ return mimeType || undefined;
157
+ }
158
+ function mimeTypeFromName(name) {
159
+ switch (extname(name ?? '').slice(1).toLowerCase()) {
160
+ case 'avif': return 'image/avif';
161
+ case 'gif': return 'image/gif';
162
+ case 'jpeg':
163
+ case 'jpg': return 'image/jpeg';
164
+ case 'png': return 'image/png';
165
+ case 'svg': return 'image/svg+xml';
166
+ case 'webp': return 'image/webp';
167
+ case 'pdf': return 'application/pdf';
168
+ case 'doc': return 'application/msword';
169
+ case 'docx': return 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
170
+ case 'mp4': return 'video/mp4';
171
+ case 'webm': return 'video/webm';
172
+ case 'mp3': return 'audio/mpeg';
173
+ case 'wav': return 'audio/wav';
174
+ default: return 'application/octet-stream';
175
+ }
176
+ }
177
+ //# sourceMappingURL=attachment_manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attachment_manager.js","sourceRoot":"","sources":["../../../src/sources/attachment_manager.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAC7C,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAuCjD;;;GAGG;AACH,MAAM,OAAO,iBAAiB;IACnB,YAAY,CAAwC;IACpD,SAAS,CAAoB;IAC7B,MAAM,CAAuB;IAEtC,YAAY,WAAmD,EAAE,UAAoC,EAAE;QACrG,IAAI,OAAO,CAAC,QAAQ,KAAK,SAAS,IAAI,CAAC,CAAC,MAAM,C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AAS,CAAA;AAC9B,CAAC;AAED,SAAS,gBAAgB,CAAC,IAAwB;IAChD,QAAQ,OAAO,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC;QACnD,KAAK,MAAM,CAAC,CAAC,OAAO,YAAY,CAAA;QAChC,KAAK,KAAK,CAAC,CAAC,OAAO,WAAW,CAAA;QAC9B,KAAK,MAAM,CAAC;QACZ,KAAK,KAAK,CAAC,CAAC,OAAO,YAAY,CAAA;QAC/B,KAAK,KAAK,CAAC,CAAC,OAAO,WAAW,CAAA;QAC9B,KAAK,KAAK,CAAC,CAAC,OAAO,eAAe,CAAA;QAClC,KAAK,MAAM,CAAC,CAAC,OAAO,YAAY,CAAA;QAChC,KAAK,KAAK,CAAC,CAAC,OAAO,iBAAiB,CAAA;QACpC,KAAK,KAAK,CAAC,CAAC,OAAO,oBAAoB,CAAA;QACvC,KAAK,MAAM,CAAC,CAAC,OAAO,yEAAyE,CAAA;QAC7F,KAAK,KAAK,CAAC,CAAC,OAAO,WAAW,CAAA;QAC9B,KAAK,MAAM,CAAC,CAAC,OAAO,YAAY,CAAA;QAChC,KAAK,KAAK,CAAC,CAAC,OAAO,YAAY,CAAA;QAC/B,KAAK,KAAK,CAAC,CAAC,OAAO,WAAW,CAAA;QAC9B,OAAO,CAAC,CAAC,OAAO,0BAA0B,CAAA;IAC5C,CAAC;AACH,CAAC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @jrmc/adonis-attachment
3
+ *
4
+ * @license MIT
5
+ * @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
6
+ */
7
+ import type { Attachment } from '../core/attachment.js';
8
+ export type VariantConversionInput = {
9
+ attachment: Attachment;
10
+ body: Uint8Array;
11
+ };
12
+ export type VariantConversionOutput = {
13
+ body: Uint8Array;
14
+ fileName: string;
15
+ mimeType: string;
16
+ folder?: string;
17
+ metadata?: Record<string, unknown>;
18
+ };
19
+ export interface VariantConverter {
20
+ key: string;
21
+ convert(input: VariantConversionInput): Promise<VariantConversionOutput>;
22
+ }
23
+ //# sourceMappingURL=variant_converter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"variant_converter.d.ts","sourceRoot":"","sources":["../../../src/variants/variant_converter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAEvD,MAAM,MAAM,sBAAsB,GAAG;IACnC,UAAU,EAAE,UAAU,CAAA;IACtB,IAAI,EAAE,UAAU,CAAA;CACjB,CAAA;AAED,MAAM,MAAM,uBAAuB,GAAG;IACpC,IAAI,EAAE,UAAU,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACnC,CAAA;AAED,MAAM,WAAW,gBAAgB;IAC/B,GAAG,EAAE,MAAM,CAAA;IACX,OAAO,CAAC,KAAK,EAAE,sBAAsB,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAA;CACzE"}
@@ -5,3 +5,4 @@
5
5
  * @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
6
6
  */
7
7
  export {};
8
+ //# sourceMappingURL=variant_converter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"variant_converter.js","sourceRoot":"","sources":["../../../src/variants/variant_converter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @jrmc/adonis-attachment
3
+ *
4
+ * @license MIT
5
+ * @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
6
+ */
7
+ import type { Attachment } from '../core/attachment.js';
8
+ import type { AttachmentService } from '../core/attachment_service.js';
9
+ import type { VariantGenerationRequest, VariantGenerator } from '../core/attachment_job_processor.js';
10
+ import type { VariantConverter } from './variant_converter.js';
11
+ export type GeneratedVariant = {
12
+ key: string;
13
+ attachment: Attachment;
14
+ };
15
+ export type VariantGenerationServiceOptions = {
16
+ attachments: Pick<AttachmentService, 'create' | 'read'>;
17
+ converters: readonly VariantConverter[];
18
+ };
19
+ export declare class VariantGenerationService implements VariantGenerator {
20
+ #private;
21
+ constructor(options: VariantGenerationServiceOptions);
22
+ generate(request: VariantGenerationRequest): Promise<void>;
23
+ generateAll(request: VariantGenerationRequest): Promise<GeneratedVariant[]>;
24
+ }
25
+ export declare class UnknownVariantConverterError extends Error {
26
+ constructor(key: string);
27
+ }
28
+ //# sourceMappingURL=variant_generation_service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"variant_generation_service.d.ts","sourceRoot":"","sources":["../../../src/variants/variant_generation_service.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAyB,MAAM,uBAAuB,CAAA;AAC9E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAA;AACtE,OAAO,KAAK,EAAE,wBAAwB,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAA;AACrG,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAE9D,MAAM,MAAM,gBAAgB,GAAG;IAC7B,GAAG,EAAE,MAAM,CAAA;IACX,UAAU,EAAE,UAAU,CAAA;CACvB,CAAA;AAED,MAAM,MAAM,+BAA+B,GAAG;IAC5C,WAAW,EAAE,IAAI,CAAC,iBAAiB,EAAE,QAAQ,GAAG,MAAM,CAAC,CAAA;IACvD,UAAU,EAAE,SAAS,gBAAgB,EAAE,CAAA;CACxC,CAAA;AAED,qBAAa,wBAAyB,YAAW,gBAAgB;;gBAInD,OAAO,EAAE,+BAA+B;IAK9C,QAAQ,CAAC,OAAO,EAAE,wBAAwB,GAAG,OAAO,CAAC,IAAI,CAAC;IAI1D,WAAW,CAAC,OAAO,EAAE,wBAAwB,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC;CA0BlF;AAED,qBAAa,4BAA6B,SAAQ,KAAK;gBACzC,GAAG,EAAE,MAAM;CAIxB"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * @jrmc/adonis-attachment
3
+ *
4
+ * @license MIT
5
+ * @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
6
+ */
7
+ export class VariantGenerationService {
8
+ #attachments;
9
+ #converters;
10
+ constructor(options) {
11
+ this.#attachments = options.attachments;
12
+ this.#converters = new Map(options.converters.map((converter) => [converter.key, converter]));
13
+ }
14
+ async generate(request) {
15
+ await this.generateAll(request);
16
+ }
17
+ async generateAll(request) {
18
+ const source = await this.#attachments.read(request.attachment);
19
+ const keys = request.variantKeys ?? [...this.#converters.keys()];
20
+ return Promise.all(keys.map(async (key) => {
21
+ const converter = this.#converters.get(key);
22
+ if (!converter) {
23
+ throw new UnknownVariantConverterError(key);
24
+ }
25
+ const output = await converter.convert({ attachment: request.attachment, body: source });
26
+ const input = {
27
+ body: output.body,
28
+ originalName: output.fileName,
29
+ mimeType: output.mimeType,
30
+ ...(output.folder ? { folder: output.folder } : {}),
31
+ ...(output.metadata ? { metadata: output.metadata } : {}),
32
+ disk: request.attachment.disk,
33
+ };
34
+ return { key, attachment: await this.#attachments.create(input) };
35
+ }));
36
+ }
37
+ }
38
+ export class UnknownVariantConverterError extends Error {
39
+ constructor(key) {
40
+ super(`No variant converter is registered for "${key}"`);
41
+ this.name = 'UnknownVariantConverterError';
42
+ }
43
+ }
44
+ //# sourceMappingURL=variant_generation_service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"variant_generation_service.js","sourceRoot":"","sources":["../../../src/variants/variant_generation_service.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAiBH,MAAM,OAAO,wBAAwB;IAC1B,YAAY,CAA4C;IACxD,WAAW,CAA+B;IAEnD,YAAY,OAAwC;QAClD,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,WAAW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MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBACzD,IAAI,EAAE,OAAO,CAAC,UAAU,CAAC,IAAI;aAC9B,CAAA;YAED,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAA;QACnE,CAAC,CAAC,CACH,CAAA;IACH,CAAC;CACF;AAED,MAAM,OAAO,4BAA6B,SAAQ,KAAK;IACrD,YAAY,GAAW;QACrB,KAAK,CAAC,2CAA2C,GAAG,GAAG,CAAC,CAAA;QACxD,IAAI,CAAC,IAAI,GAAG,8BAA8B,CAAA;IAC5C,CAAC;CACF"}
@@ -0,0 +1,12 @@
1
+ {{{
2
+ exports({ to: app.configPath('attachment.ts') })
3
+ }}}
4
+ import { defineConfig, LocalFileStorage } from '@jrmc/adonis-attachment'
5
+
6
+ /**
7
+ * Attachments are stored locally by default. Lucid, Drive, external queues,
8
+ * custom storage, and read routes can be added as the application needs them.
9
+ */
10
+ export default defineConfig({
11
+ storage: LocalFileStorage.fromApp,
12
+ })
@@ -1 +1 @@
1
- {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../stubs/main.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,SAAS,QAAsB,CAAA"}
1
+ {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../stubs/main.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS,QAAsB,CAAA"}
@@ -1 +1,2 @@
1
1
  export const stubsRoot = import.meta.dirname;
2
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.js","sourceRoot":"","sources":["../../stubs/main.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAA"}
@@ -0,0 +1,39 @@
1
+ {{{
2
+ exports({ to: destination })
3
+ }}}
4
+ import { BaseSchema } from '@adonisjs/lucid/schema'
5
+
6
+ export default class Create{{ className }}Table extends BaseSchema {
7
+ protected tableName = '{{ tableName }}'
8
+
9
+ async up() {
10
+ this.schema.createTable(this.tableName, (table) => {
11
+ table.uuid('id').primary()
12
+ table.string('attachable_type').notNullable()
13
+ table.string('attachable_id').notNullable()
14
+ table.string('field').notNullable()
15
+ table.string('owner_key', 64).nullable().unique()
16
+ table.integer('position').unsigned().nullable()
17
+ table.uuid('parent_id').nullable().references('id').inTable(this.tableName).onDelete('CASCADE')
18
+ table.string('variant_key').nullable()
19
+ table.string('disk').notNullable()
20
+ table.string('path').notNullable()
21
+ table.string('name').notNullable()
22
+ table.string('original_name').notNullable()
23
+ table.string('mime_type').notNullable()
24
+ table.string('extname').notNullable()
25
+ table.bigInteger('size').unsigned().notNullable()
26
+ table.json('metadata').nullable()
27
+ table.timestamp('created_at').notNullable()
28
+ table.timestamp('updated_at').notNullable()
29
+
30
+ table.index(['attachable_type', 'attachable_id', 'field'])
31
+ table.index(['parent_id'])
32
+ table.unique(['parent_id', 'variant_key'])
33
+ })
34
+ }
35
+
36
+ async down() {
37
+ this.schema.dropTable(this.tableName)
38
+ }
39
+ }
@@ -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=adonis_drive_storage.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adonis_drive_storage.spec.d.ts","sourceRoot":"","sources":["../../tests/adonis_drive_storage.spec.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
@@ -0,0 +1,69 @@
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 { AdonisDriveStorage } from '../index.js';
9
+ test.group('AdonisDriveStorage', () => {
10
+ test('writes an attachment through the selected Drive disk', async ({ assert }) => {
11
+ const calls = [];
12
+ const storage = new AdonisDriveStorage({
13
+ use(disk) {
14
+ return {
15
+ async put(path, contents) {
16
+ calls.push({ disk, path, contents });
17
+ },
18
+ async getBytes() {
19
+ return new Uint8Array();
20
+ },
21
+ async delete() { },
22
+ };
23
+ },
24
+ });
25
+ await storage.write({
26
+ disk: 's3',
27
+ path: 'users/42/avatar.jpg',
28
+ body: new Uint8Array([1, 2, 3]),
29
+ mimeType: 'image/jpeg',
30
+ });
31
+ assert.deepEqual(calls, [
32
+ { disk: 's3', path: 'users/42/avatar.jpg', contents: new Uint8Array([1, 2, 3]) },
33
+ ]);
34
+ });
35
+ test('deletes an attachment through the selected Drive disk', async ({ assert }) => {
36
+ const calls = [];
37
+ const storage = new AdonisDriveStorage({
38
+ use(disk) {
39
+ return {
40
+ async put() { },
41
+ async getBytes() {
42
+ return new Uint8Array();
43
+ },
44
+ async delete(path) {
45
+ calls.push({ disk, path });
46
+ },
47
+ };
48
+ },
49
+ });
50
+ await storage.remove({ disk: 'public', path: 'users/42/avatar.jpg' });
51
+ assert.deepEqual(calls, [{ disk: 'public', path: 'users/42/avatar.jpg' }]);
52
+ });
53
+ test('reads an attachment through the selected Drive disk', async ({ assert }) => {
54
+ const storage = new AdonisDriveStorage({
55
+ use() {
56
+ return {
57
+ async put() { },
58
+ async getBytes(path) {
59
+ assert.equal(path, 'users/42/avatar.jpg');
60
+ return new Uint8Array([1, 2, 3]);
61
+ },
62
+ async delete() { },
63
+ };
64
+ },
65
+ });
66
+ assert.deepEqual(await storage.read({ disk: 'public', path: 'users/42/avatar.jpg' }), new Uint8Array([1, 2, 3]));
67
+ });
68
+ });
69
+ //# sourceMappingURL=adonis_drive_storage.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adonis_drive_storage.spec.js","sourceRoot":"","sources":["../../tests/adonis_drive_storage.spec.ts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CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAC1B,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -5,3 +5,4 @@
5
5
  * @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
6
6
  */
7
7
  export {};
8
+ //# sourceMappingURL=adonis_queue.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adonis_queue.spec.d.ts","sourceRoot":"","sources":["../../tests/adonis_queue.spec.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
@@ -0,0 +1,52 @@
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 { AdonisAttachmentQueue } from '../index.js';
9
+ test.group('AdonisAttachmentQueue', () => {
10
+ test('dispatches an attachment job to the configured queue', async ({ assert }) => {
11
+ const calls = [];
12
+ const queue = new AdonisAttachmentQueue({
13
+ queue: 'attachments',
14
+ job: {
15
+ dispatch(payload) {
16
+ calls.push(`dispatch:${payload.attachmentId}`);
17
+ return {
18
+ toQueue(name) {
19
+ calls.push(`queue:${name}`);
20
+ return this;
21
+ },
22
+ async run() {
23
+ calls.push('run');
24
+ },
25
+ };
26
+ },
27
+ },
28
+ });
29
+ await queue.enqueue({ type: 'generate-variants', attachmentId: 'attachment-id' });
30
+ assert.deepEqual(calls, ['dispatch:attachment-id', 'queue:attachments', 'run']);
31
+ });
32
+ test('uses the job default queue when no queue name is configured', async ({ assert }) => {
33
+ const calls = [];
34
+ const queue = new AdonisAttachmentQueue({
35
+ job: {
36
+ dispatch() {
37
+ return {
38
+ toQueue() {
39
+ throw new Error('should not select a queue');
40
+ },
41
+ async run() {
42
+ calls.push('run');
43
+ },
44
+ };
45
+ },
46
+ },
47
+ });
48
+ await queue.enqueue({ type: 'generate-variants', attachmentId: 'attachment-id' });
49
+ assert.deepEqual(calls, ['run']);
50
+ });
51
+ });
52
+ //# sourceMappingURL=adonis_queue.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adonis_queue.spec.js","sourceRoot":"","sources":["../../tests/adonis_queue.spec.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAEnC,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAEnD,IAAI,CAAC,KAAK,CAAC,uBAAuB,EAAE,GAAG,EAAE;IACvC,IAAI,CAAC,sDAAsD,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;QAChF,MAAM,KAAK,GAAa,EAAE,CAAA;QAC1B,MAAM,KAAK,GAAG,IAAI,qBAAqB,CAAC;YACtC,KAAK,EAAE,aAAa;YACpB,GAAG,EAAE;gBACH,QAAQ,CAAC,OAAO;oBACd,KAAK,CAAC,IAAI,CAAC,YAAY,OAAO,CAAC,YAAY,EAAE,CAAC,CAAA;oBAC9C,OAAO;wBACL,OAAO,CAAC,IAAI;4BACV,KAAK,CAAC,IAAI,CAAC,SAAS,IAAI,EAAE,CAAC,CAAA;4BAC3B,OAAO,IAAI,CAAA;wBACb,CAAC;wBACD,KAAK,CAAC,GAAG;4BACP,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;wBACnB,CAAC;qBACF,CAAA;gBACH,CAAC;aACF;SACF,CAAC,CAAA;QAEF,MAAM,KAAK,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,mBAAmB,EAAE,YAAY,EAAE,eAAe,EAAE,CAAC,CAAA;QAEjF,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,wBAAwB,EAAE,mBAAmB,EAAE,KAAK,CAAC,CAAC,CAAA;IACjF,CAAC,CAAC,CAAA;IAEF,IAAI,CAAC,6DAA6D,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;QACvF,MAAM,KAAK,GAAa,EAAE,CAAA;QAC1B,MAAM,KAAK,GAAG,IAAI,qBAAqB,CAAC;YACtC,GAAG,EAAE;gBACH,QAAQ;oBACN,OAAO;wBACL,OAAO;4BACL,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAA;wBAC9C,CAAC;wBACD,KAAK,CAAC,GAAG;4BACP,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;wBACnB,CAAC;qBACF,CAAA;gBACH,CAAC;aACF;SACF,CAAC,CAAA;QAEF,MAAM,KAAK,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,mBAAmB,EAAE,YAAY,EAAE,eAAe,EAAE,CAAC,CAAA;QAEjF,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC,CAAA;IAClC,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=attachment_job_processor.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attachment_job_processor.spec.d.ts","sourceRoot":"","sources":["../../tests/attachment_job_processor.spec.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
@@ -0,0 +1,89 @@
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 { AttachmentJobProcessor, AttachmentNotFoundError, } from '../index.js';
9
+ const attachment = {
10
+ id: 'attachment-id',
11
+ disk: 'public',
12
+ name: 'attachment-id.jpg',
13
+ originalName: 'avatar.jpg',
14
+ path: 'users/42/attachment-id.jpg',
15
+ size: 3,
16
+ extname: 'jpg',
17
+ mimeType: 'image/jpeg',
18
+ };
19
+ class FakeRepository {
20
+ value;
21
+ constructor(value) {
22
+ this.value = value;
23
+ }
24
+ async findById() {
25
+ return this.value;
26
+ }
27
+ }
28
+ class FakeVariantGenerator {
29
+ requests = [];
30
+ async generate(request) {
31
+ this.requests.push(request);
32
+ }
33
+ }
34
+ test.group('AttachmentJobProcessor', () => {
35
+ test('resolves an attachment before delegating variant generation', async ({ assert }) => {
36
+ const variants = new FakeVariantGenerator();
37
+ const processor = new AttachmentJobProcessor({
38
+ attachments: new FakeRepository(attachment),
39
+ variants,
40
+ });
41
+ await processor.process({
42
+ type: 'generate-variants',
43
+ attachmentId: 'attachment-id',
44
+ variantKeys: ['thumbnail'],
45
+ });
46
+ assert.deepEqual(variants.requests, [{ attachment, variantKeys: ['thumbnail'] }]);
47
+ });
48
+ test('fails a job when its attachment no longer exists', async ({ assert }) => {
49
+ const processor = new AttachmentJobProcessor({
50
+ attachments: new FakeRepository(null),
51
+ variants: new FakeVariantGenerator(),
52
+ });
53
+ await assert.rejects(() => processor.process({ type: 'generate-variants', attachmentId: 'missing' }), AttachmentNotFoundError);
54
+ });
55
+ test('resolves a deferred variant generator once when a job is processed', async ({ assert }) => {
56
+ let resolutions = 0;
57
+ const requests = [];
58
+ const processor = new AttachmentJobProcessor({
59
+ attachments: {
60
+ async findById(id) {
61
+ return {
62
+ id,
63
+ disk: 'public',
64
+ path: 'users/42/avatar.jpg',
65
+ name: 'avatar.jpg',
66
+ originalName: 'profile.jpg',
67
+ mimeType: 'image/jpeg',
68
+ extname: 'jpg',
69
+ size: 42,
70
+ };
71
+ },
72
+ },
73
+ async variants() {
74
+ resolutions += 1;
75
+ return {
76
+ async generate({ attachment }) {
77
+ requests.push(attachment.id);
78
+ },
79
+ };
80
+ },
81
+ });
82
+ assert.equal(resolutions, 0);
83
+ await processor.process({ type: 'generate-variants', attachmentId: 'first-id' });
84
+ await processor.process({ type: 'generate-variants', attachmentId: 'second-id' });
85
+ assert.equal(resolutions, 1);
86
+ assert.deepEqual(requests, ['first-id', 'second-id']);
87
+ });
88
+ });
89
+ //# sourceMappingURL=attachment_job_processor.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attachment_job_processor.spec.js","sourceRoot":"","sources":["../../tests/attachment_job_processor.spec.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAEnC,OAAO,EACL,sBAAsB,EACtB,uBAAuB,GAKxB,MAAM,aAAa,CAAA;AAEpB,MAAM,UAAU,GAAe;IAC7B,EAAE,EAAE,eAAe;IACnB,IAAI,EAAE,QAAQ;IACd,IAAI,EAAE,mBAAmB;IACzB,YAAY,EAAE,YAAY;IAC1B,IAAI,EAAE,4BAA4B;IAClC,IAAI,EAAE,CAAC;IACP,OAAO,EAAE,KAAK;IACd,QAAQ,EAAE,YAAY;CACvB,CAAA;AAED,MAAM,cAAc;IACW;IAA7B,YAA6B,KAAwB;QAAxB,UAAK,GAAL,KAAK,CAAmB;IAAG,CAAC;IAEzD,KAAK,CAAC,QAAQ;QACZ,OAAO,IAAI,CAAC,KAAK,CAAA;IACnB,CAAC;CACF;AAED,MAAM,oBAAoB;IACxB,QAAQ,GAA+B,EAAE,CAAA;IAEzC,KAAK,CAAC,QAAQ,CAAC,OAAiC;QAC9C,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IAC7B,CAAC;CACF;AAED,IAAI,CAAC,KAAK,CAAC,wBAAwB,EAAE,GAAG,EAAE;IACxC,IAAI,CAAC,6DAA6D,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;QACvF,MAAM,QAAQ,GAAG,IAAI,oBAAoB,EAAE,CAAA;QAC3C,MAAM,SAAS,GAAG,IAAI,sBAAsB,CAAC;YAC3C,WAAW,EAAE,IAAI,cAAc,CAAC,UAAU,CAAC;YAC3C,QAAQ;SACT,CAAC,CAAA;QAEF,MAAM,SAAS,CAAC,OAAO,CAAC;YACtB,IAAI,EAAE,mBAAmB;YACzB,YAAY,EAAE,eA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