@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,47 @@
1
+ /**
2
+ * @jrmc/adonis-attachment
3
+ *
4
+ * @license MIT
5
+ * @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
6
+ */
7
+ import { migrateLegacyAttachment, } from './migrate_legacy_attachment.js';
8
+ /**
9
+ * Migrates a stream of legacy v5 JSON values into attachment-table rows.
10
+ * The caller owns source-model iteration and database transactions; this keeps
11
+ * the migration compatible with custom Lucid models and other persistence layouts.
12
+ */
13
+ export async function migrateLegacyAttachmentRecords(options) {
14
+ const batchSize = options.batchSize ?? 100;
15
+ if (!Number.isSafeInteger(batchSize) || batchSize < 1) {
16
+ throw new Error('Legacy attachment migration batchSize must be a positive integer');
17
+ }
18
+ const result = {
19
+ attachments: 0,
20
+ variants: 0,
21
+ skipped: 0,
22
+ };
23
+ let batch = [];
24
+ for await (const record of options.records) {
25
+ if (record.value === null || record.value === undefined) {
26
+ result.skipped += 1;
27
+ continue;
28
+ }
29
+ const rows = migrateLegacyAttachment(record.value, {
30
+ owner: record.owner,
31
+ defaultDisk: options.defaultDisk,
32
+ createId: options.createId,
33
+ });
34
+ result.attachments += 1;
35
+ result.variants += rows.length - 1;
36
+ batch.push(...rows);
37
+ if (batch.length >= batchSize) {
38
+ await options.writer.insert(batch);
39
+ batch = [];
40
+ }
41
+ }
42
+ if (batch.length > 0) {
43
+ await options.writer.insert(batch);
44
+ }
45
+ return result;
46
+ }
47
+ //# sourceMappingURL=migrate_legacy_attachment_records.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrate_legacy_attachment_records.js","sourceRoot":"","sources":["../../../../src/integrations/lucid/migrate_legacy_attachment_records.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EACL,uBAAuB,GAGxB,MAAM,gCAAgC,CAAA;AAyBvC;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,8BAA8B,CAClD,OAA8C;IAE9C,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,GAAG,CAAA;IAE1C,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,SAAS,CAAC,IAAI,SAAS,GAAG,CAAC,EAAE,CAAC;QACtD,MAAM,IAAI,KAAK,CAAC,kEAAkE,CAAC,CAAA;IACrF,CAAC;IAED,MAAM,MAAM,GAAoC;QAC9C,WAAW,EAAE,CAAC;QACd,QAAQ,EAAE,CAAC;QACX,OAAO,EAAE,CAAC;KACX,CAAA;IACD,IAAI,KAAK,GAA4B,EAAE,CAAA;IAEvC,IAAI,KAAK,EAAE,MAAM,MAAM,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;QAC3C,IAAI,MAAM,CAAC,KAAK,KAAK,IAAI,IAAI,MAAM,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;YACxD,MAAM,CAAC,OAAO,IAAI,CAAC,CAAA;YACnB,SAAQ;QACV,CAAC;QAED,MAAM,IAAI,GAAG,uBAAuB,CAAC,MAAM,CAAC,KAAK,EAAE;YACjD,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,WAAW,EAAE,OAAO,CAAC,WAAW;YAChC,QAAQ,EAAE,OAAO,CAAC,QAAQ;SAC3B,CAAC,CAAA;QAEF,MAAM,CAAC,WAAW,IAAI,CAAC,CAAA;QACvB,MAAM,CAAC,QAAQ,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,CAAA;QAClC,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAA;QAEnB,IAAI,KAAK,CAAC,MAAM,IAAI,SAAS,EAAE,CAAC;YAC9B,MAAM,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;YAClC,KAAK,GAAG,EAAE,CAAA;QACZ,CAAC;IACH,CAAC;IAED,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACrB,MAAM,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IACpC,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @jrmc/adonis-attachment
3
+ *
4
+ * @license MIT
5
+ * @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
6
+ */
7
+ export type RenderLegacyAttachmentMigrationScriptOptions = {
8
+ defaultDisk?: string;
9
+ };
10
+ export declare function renderLegacyAttachmentMigrationScript(options?: RenderLegacyAttachmentMigrationScriptOptions): string;
11
+ //# sourceMappingURL=render_legacy_attachment_migration_script.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render_legacy_attachment_migration_script.d.ts","sourceRoot":"","sources":["../../../../src/integrations/lucid/render_legacy_attachment_migration_script.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,MAAM,4CAA4C,GAAG;IACzD,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB,CAAA;AAED,wBAAgB,qCAAqC,CACnD,OAAO,GAAE,4CAAiD,GACzD,MAAM,CAkCR"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * @jrmc/adonis-attachment
3
+ *
4
+ * @license MIT
5
+ * @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
6
+ */
7
+ export function renderLegacyAttachmentMigrationScript(options = {}) {
8
+ const defaultDisk = options.defaultDisk ?? 'public';
9
+ return `import { randomUUID } from 'node:crypto'
10
+
11
+ import {
12
+ AttachmentModel,
13
+ migrateLegacyAttachmentRecords,
14
+ type LegacyAttachmentMigrationRecord,
15
+ } from '@jrmc/adonis-attachment/lucid'
16
+
17
+ async function main(): Promise<void> {
18
+ const result = await migrateLegacyAttachmentRecords({
19
+ records: legacyAttachmentRecords(),
20
+ defaultDisk: '${defaultDisk}',
21
+ createId: randomUUID,
22
+ writer: {
23
+ insert: (rows) => AttachmentModel.createMany(rows),
24
+ },
25
+ })
26
+
27
+ console.info(
28
+ \`Migrated \${result.attachments} attachments and \${result.variants} variants; skipped \${result.skipped} empty values.\`
29
+ )
30
+ }
31
+
32
+ async function* legacyAttachmentRecords(): AsyncGenerator<LegacyAttachmentMigrationRecord> {
33
+ // Iterate over the legacy model and yield one value per attachment field.
34
+ // Example owner: { type: 'users', id: user.id.toString(), field: 'avatar' }
35
+ throw new Error('Implement legacyAttachmentRecords before running this script')
36
+ }
37
+
38
+ void main()
39
+ `;
40
+ }
41
+ //# sourceMappingURL=render_legacy_attachment_migration_script.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render_legacy_attachment_migration_script.js","sourceRoot":"","sources":["../../../../src/integrations/lucid/render_legacy_attachment_migration_script.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,MAAM,UAAU,qCAAqC,CACnD,UAAwD,EAAE;IAE1D,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,QAAQ,CAAA;IAEnD,OAAO;;;;;;;;;;;oBAWW,WAAW;;;;;;;;;;;;;;;;;;;CAmB9B,CAAA;AACD,CAAC"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @jrmc/adonis-attachment
3
+ *
4
+ * @license MIT
5
+ * @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
6
+ */
7
+ import type { AttachmentJob, AttachmentQueue } from '../core/queue.js';
8
+ export type AdonisQueueDispatcher = {
9
+ toQueue(name: string): AdonisQueueDispatcher;
10
+ run(): Promise<unknown>;
11
+ };
12
+ export type AdonisAttachmentJob = {
13
+ dispatch(payload: AttachmentJob): AdonisQueueDispatcher;
14
+ };
15
+ export type AdonisAttachmentQueueOptions = {
16
+ job: AdonisAttachmentJob;
17
+ queue?: string;
18
+ };
19
+ /**
20
+ * Dispatches attachment jobs through an application-defined @adonisjs/queue Job class.
21
+ */
22
+ export declare class AdonisAttachmentQueue implements AttachmentQueue {
23
+ #private;
24
+ constructor(options: AdonisAttachmentQueueOptions);
25
+ enqueue(job: AttachmentJob): Promise<void>;
26
+ }
27
+ //# sourceMappingURL=adonis_queue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adonis_queue.d.ts","sourceRoot":"","sources":["../../../src/queues/adonis_queue.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAEtE,MAAM,MAAM,qBAAqB,GAAG;IAClC,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,qBAAqB,CAAA;IAC5C,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,CAAA;CACxB,CAAA;AAED,MAAM,MAAM,mBAAmB,GAAG;IAChC,QAAQ,CAAC,OAAO,EAAE,aAAa,GAAG,qBAAqB,CAAA;CACxD,CAAA;AAED,MAAM,MAAM,4BAA4B,GAAG;IACzC,GAAG,EAAE,mBAAmB,CAAA;IACxB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAED;;GAEG;AACH,qBAAa,qBAAsB,YAAW,eAAe;;gBAI/C,OAAO,EAAE,4BAA4B;IAK3C,OAAO,CAAC,GAAG,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;CAIjD"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @jrmc/adonis-attachment
3
+ *
4
+ * @license MIT
5
+ * @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
6
+ */
7
+ /**
8
+ * Dispatches attachment jobs through an application-defined @adonisjs/queue Job class.
9
+ */
10
+ export class AdonisAttachmentQueue {
11
+ #job;
12
+ #queue;
13
+ constructor(options) {
14
+ this.#job = options.job;
15
+ this.#queue = options.queue;
16
+ }
17
+ async enqueue(job) {
18
+ const dispatcher = this.#job.dispatch(job);
19
+ await (this.#queue ? dispatcher.toQueue(this.#queue) : dispatcher).run();
20
+ }
21
+ }
22
+ //# sourceMappingURL=adonis_queue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adonis_queue.js","sourceRoot":"","sources":["../../../src/queues/adonis_queue.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAkBH;;GAEG;AACH,MAAM,OAAO,qBAAqB;IACvB,IAAI,CAAqB;IACzB,MAAM,CAAoB;IAEnC,YAAY,OAAqC;QAC/C,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,GAAG,CAAA;QACvB,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,KAAK,CAAA;IAC7B,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,GAAkB;QAC9B,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAA;QAC1C,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,GAAG,EAAE,CAAA;IAC1E,CAAC;CACF"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @jrmc/adonis-attachment
3
+ *
4
+ * @license MIT
5
+ * @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
6
+ */
7
+ import type { AttachmentJob, AttachmentJobHandler, AttachmentQueue } from '../core/queue.js';
8
+ export type MemoryAttachmentQueueOptions = {
9
+ handler: AttachmentJobHandler;
10
+ concurrency?: number;
11
+ onFailure?: (job: AttachmentJob, error: unknown) => void | Promise<void>;
12
+ };
13
+ /**
14
+ * In-process default queue for local development and applications without a worker.
15
+ */
16
+ export declare class MemoryAttachmentQueue implements AttachmentQueue {
17
+ #private;
18
+ constructor(options: MemoryAttachmentQueueOptions);
19
+ enqueue(job: AttachmentJob): Promise<void>;
20
+ drain(): Promise<void>;
21
+ }
22
+ //# sourceMappingURL=memory_queue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory_queue.d.ts","sourceRoot":"","sources":["../../../src/queues/memory_queue.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAE5F,MAAM,MAAM,4BAA4B,GAAG;IACzC,OAAO,EAAE,oBAAoB,CAAA;IAC7B,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,SAAS,CAAC,EAAE,CAAC,GAAG,EAAE,aAAa,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CACzE,CAAA;AAED;;GAEG;AACH,qBAAa,qBAAsB,YAAW,eAAe;;gBAQ/C,OAAO,EAAE,4BAA4B;IAU3C,OAAO,CAAC,GAAG,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAK1C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CA0C7B"}
@@ -0,0 +1,67 @@
1
+ /**
2
+ * @jrmc/adonis-attachment
3
+ *
4
+ * @license MIT
5
+ * @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
6
+ */
7
+ /**
8
+ * In-process default queue for local development and applications without a worker.
9
+ */
10
+ export class MemoryAttachmentQueue {
11
+ #handler;
12
+ #onFailure;
13
+ #concurrency;
14
+ #pending = [];
15
+ #active = 0;
16
+ #drainWaiters = [];
17
+ constructor(options) {
18
+ if (!Number.isInteger(options.concurrency ?? 1) || (options.concurrency ?? 1) < 1) {
19
+ throw new Error('Memory queue concurrency must be a positive integer');
20
+ }
21
+ this.#handler = options.handler;
22
+ this.#onFailure = options.onFailure;
23
+ this.#concurrency = options.concurrency ?? 1;
24
+ }
25
+ async enqueue(job) {
26
+ this.#pending.push(job);
27
+ this.#process();
28
+ }
29
+ async drain() {
30
+ if (this.#pending.length === 0 && this.#active === 0) {
31
+ return;
32
+ }
33
+ await new Promise((resolve) => this.#drainWaiters.push(resolve));
34
+ }
35
+ #process() {
36
+ while (this.#active < this.#concurrency) {
37
+ const job = this.#pending.shift();
38
+ if (!job) {
39
+ this.#resolveDrainWaiters();
40
+ return;
41
+ }
42
+ this.#active += 1;
43
+ void this.#run(job);
44
+ }
45
+ }
46
+ async #run(job) {
47
+ try {
48
+ await this.#handler(job);
49
+ }
50
+ catch (error) {
51
+ await this.#onFailure?.(job, error);
52
+ }
53
+ finally {
54
+ this.#active -= 1;
55
+ this.#process();
56
+ }
57
+ }
58
+ #resolveDrainWaiters() {
59
+ if (this.#active !== 0 || this.#pending.length !== 0) {
60
+ return;
61
+ }
62
+ const waiters = this.#drainWaiters;
63
+ this.#drainWaiters = [];
64
+ waiters.forEach((resolve) => resolve());
65
+ }
66
+ }
67
+ //# sourceMappingURL=memory_queue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory_queue.js","sourceRoot":"","sources":["../../../src/queues/memory_queue.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAUH;;GAEG;AACH,MAAM,OAAO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gBAC3B,OAAM;YACR,CAAC;YAED,IAAI,CAAC,OAAO,IAAI,CAAC,CAAA;YACjB,KAAK,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QACrB,CAAC;IACH,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,GAAkB;QAC3B,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAA;QAC1B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;QACrC,CAAC;gBAAS,CAAC;YACT,IAAI,CAAC,OAAO,IAAI,CAAC,CAAA;YACjB,IAAI,CAAC,QAAQ,EAAE,CAAA;QACjB,CAAC;IACH,CAAC;IAED,oBAAoB;QAClB,IAAI,IAAI,CAAC,OAAO,KAAK,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACrD,OAAM;QACR,CAAC;QAED,MAAM,OAAO,GAAG,IAAI,CAAC,aAAa,CAAA;QAClC,IAAI,CAAC,aAAa,GAAG,EAAE,CAAA;QACvB,OAAO,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,EAAE,CAAC,CAAA;IACzC,CAAC;CACF"}
@@ -0,0 +1,51 @@
1
+ /**
2
+ * @jrmc/adonis-attachment
3
+ *
4
+ * @license MIT
5
+ * @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
6
+ */
7
+ import type { Readable } from 'node:stream';
8
+ import type { Attachment, CreateAttachmentInput } from '../core/attachment.js';
9
+ import type { AttachmentService } from '../core/attachment_service.js';
10
+ export type MultipartAttachmentFile = {
11
+ tmpPath?: string;
12
+ clientName: string;
13
+ type?: string;
14
+ subtype?: string;
15
+ };
16
+ export type AttachmentSourceOptions = Omit<CreateAttachmentInput, 'body' | 'originalName' | 'mimeType'> & {
17
+ originalName?: string;
18
+ mimeType?: string;
19
+ maxBytes?: number;
20
+ };
21
+ export type AttachmentSourceResponse = {
22
+ ok: boolean;
23
+ status: number;
24
+ statusText: string;
25
+ headers: Pick<Headers, 'get'>;
26
+ arrayBuffer(): Promise<ArrayBuffer>;
27
+ };
28
+ export type AttachmentSourceFetch = (input: URL | string) => Promise<AttachmentSourceResponse>;
29
+ export type AttachmentManagerOptions = {
30
+ maxBytes?: number;
31
+ fetch?: AttachmentSourceFetch;
32
+ };
33
+ /**
34
+ * Normalizes common input sources before delegating storage to AttachmentService.
35
+ * It does not inspect media metadata; the media pipeline owns that concern.
36
+ */
37
+ export declare class AttachmentManager {
38
+ #private;
39
+ constructor(attachments: Pick<AttachmentService, 'create'>, options?: AttachmentManagerOptions);
40
+ createFromBuffer(input: Uint8Array, options?: AttachmentSourceOptions): Promise<Attachment>;
41
+ createFromBase64(input: string, options?: AttachmentSourceOptions): Promise<Attachment>;
42
+ createFromPath(input: string, options?: AttachmentSourceOptions): Promise<Attachment>;
43
+ createFromStream(input: Readable, options?: AttachmentSourceOptions): Promise<Attachment>;
44
+ createFromUrl(input: URL | string, options?: AttachmentSourceOptions): Promise<Attachment>;
45
+ createFromFile(input: MultipartAttachmentFile, options?: AttachmentSourceOptions): Promise<Attachment>;
46
+ createFromFiles(inputs: readonly MultipartAttachmentFile[], options?: AttachmentSourceOptions): Promise<Attachment[]>;
47
+ }
48
+ export declare class AttachmentSourceError extends Error {
49
+ constructor(message: string);
50
+ }
51
+ //# sourceMappingURL=attachment_manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attachment_manager.d.ts","sourceRoot":"","sources":["../../../src/sources/attachment_manager.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAE3C,OAAO,KAAK,EAAE,UAAU,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAA;AAC9E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,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,EAAE,OAAO,GAAE,uBAA4B,GAAG,OAAO,CAAC,UAAU,CAAC;IAazF,gBAAgB,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,GAAE,uBAA4B,GAAG,OAAO,CAAC,UAAU,CAAC;IAmB7F,aAAa,CAAC,KAAK,EAAE,GAAG,GAAG,MAAM,EAAE,OAAO,GAAE,uBAA4B,GAAG,OAAO,CAAC,UAAU,CAAC;IAyBpG,cAAc,CAAC,KAAK,EAAE,uBAAuB,EAAE,OAAO,GAAE,uBAA4B,GAAG,OAAO,CAAC,UAAU,CAAC;IAY1G,eAAe,CACb,MAAM,EAAE,SAAS,uBAAuB,EAAE,EAC1C,OAAO,GAAE,uBAA4B,GACpC,OAAO,CAAC,UAAU,EAAE,CAAC;CAoCzB;AAED,qBAAa,qBAAsB,SAAQ,KAAK;gBAClC,OAAO,EAAE,MAAM;CAI5B"}
@@ -0,0 +1,169 @@
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 before delegating storage to AttachmentService.
11
+ * It does not inspect media metadata; the media pipeline owns that concern.
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.create({
101
+ body,
102
+ originalName: input.originalName,
103
+ mimeType: input.mimeType,
104
+ ...(input.options.disk ? { disk: input.options.disk } : {}),
105
+ ...(input.options.folder ? { folder: input.options.folder } : {}),
106
+ ...(input.options.metadata ? { metadata: input.options.metadata } : {}),
107
+ });
108
+ }
109
+ #assertSize(size, override) {
110
+ if (override !== undefined && (!Number.isSafeInteger(override) || override < 1)) {
111
+ throw new Error('Attachment source maxBytes must be a positive integer');
112
+ }
113
+ const maxBytes = override === undefined
114
+ ? this.#maxBytes
115
+ : this.#maxBytes === undefined
116
+ ? override
117
+ : Math.min(override, this.#maxBytes);
118
+ if (maxBytes !== undefined && size > maxBytes) {
119
+ throw new AttachmentSourceError(`Attachment source exceeds the ${maxBytes}-byte limit`);
120
+ }
121
+ }
122
+ }
123
+ export class AttachmentSourceError extends Error {
124
+ constructor(message) {
125
+ super(message);
126
+ this.name = 'AttachmentSourceError';
127
+ }
128
+ }
129
+ function parseBase64(input) {
130
+ const dataUri = /^data:([^;,]+)?;base64,([A-Za-z0-9+/\s]*={0,2})$/i.exec(input);
131
+ const mimeType = dataUri?.[1];
132
+ const value = (dataUri?.[2] ?? input).replaceAll(/\s/g, '');
133
+ if (!isBase64(value)) {
134
+ throw new AttachmentSourceError('Attachment source must be valid Base64 data');
135
+ }
136
+ return { body: Buffer.from(value, 'base64'), ...(mimeType ? { mimeType } : {}) };
137
+ }
138
+ function isBase64(value) {
139
+ return value.length > 0 && /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(value);
140
+ }
141
+ function multipartMimeType(input) {
142
+ return input.type && input.subtype
143
+ ? `${input.type}/${input.subtype}`
144
+ : mimeTypeFromName(input.clientName);
145
+ }
146
+ function normalizeMimeType(value) {
147
+ const mimeType = value?.split(';')[0]?.trim();
148
+ return mimeType || undefined;
149
+ }
150
+ function mimeTypeFromName(name) {
151
+ switch (extname(name ?? '').slice(1).toLowerCase()) {
152
+ case 'avif': return 'image/avif';
153
+ case 'gif': return 'image/gif';
154
+ case 'jpeg':
155
+ case 'jpg': return 'image/jpeg';
156
+ case 'png': return 'image/png';
157
+ case 'svg': return 'image/svg+xml';
158
+ case 'webp': return 'image/webp';
159
+ case 'pdf': return 'application/pdf';
160
+ case 'doc': return 'application/msword';
161
+ case 'docx': return 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
162
+ case 'mp4': return 'video/mp4';
163
+ case 'webm': return 'video/webm';
164
+ case 'mp3': return 'audio/mpeg';
165
+ case 'wav': return 'audio/wav';
166
+ default: return 'application/octet-stream';
167
+ }
168
+ }
169
+ //# 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;AAqCjD;;;GAGG;AACH,MAAM,OAAO,iBAAiB;IACnB,YAAY,CAAmC;IAC/C,SAAS,CAAoB;IAC7B,MAAM,CAAuB;IAEtC,YAAY,WAA8C,EAAE,UAAoC,EAAE;QAChG,IAAI,OAAO,CAAC,QAAQ,KAAK,SAAS,IAAI,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,OAAO,CAAC,QAAQ,GAAG,CA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AAY,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,CAAA;QACvC,IAAI,CAAC,WAAW,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC,CAAC,CAAA;IAC/F,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,OAAiC;QAC9C,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAA;IACjC,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,OAAiC;QACjD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;QAC/D,MAAM,IAAI,GAAG,OAAO,CAAC,WAAW,IAAI,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,CAAA;QAEhE,OAAO,OAAO,CAAC,GAAG,CAChB,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;YACrB,MAAM,SAAS,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;YAE3C,IAA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