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

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 (199) hide show
  1. package/build/commands/make/attachment_v5_migration.d.ts.map +1 -1
  2. package/build/commands/make/attachment_v5_migration.js +6 -3
  3. package/build/commands/make/attachment_v5_migration.js.map +1 -1
  4. package/build/commands/make/attachments_table.d.ts.map +1 -1
  5. package/build/commands/make/attachments_table.js +8 -2
  6. package/build/commands/make/attachments_table.js.map +1 -1
  7. package/build/index.d.ts +23 -22
  8. package/build/index.d.ts.map +1 -1
  9. package/build/index.js +15 -14
  10. package/build/index.js.map +1 -1
  11. package/build/providers/attachment_provider.d.ts.map +1 -1
  12. package/build/providers/attachment_provider.js +16 -0
  13. package/build/providers/attachment_provider.js.map +1 -1
  14. package/build/src/core/attachment.d.ts +37 -2
  15. package/build/src/core/attachment.d.ts.map +1 -1
  16. package/build/src/core/attachment.js +108 -5
  17. package/build/src/core/attachment.js.map +1 -1
  18. package/build/src/core/attachment_options.d.ts +32 -0
  19. package/build/src/core/attachment_options.d.ts.map +1 -0
  20. package/build/src/core/attachment_options.js +24 -0
  21. package/build/src/core/attachment_options.js.map +1 -0
  22. package/build/src/core/attachment_service.d.ts +7 -1
  23. package/build/src/core/attachment_service.d.ts.map +1 -1
  24. package/build/src/core/attachment_service.js +50 -4
  25. package/build/src/core/attachment_service.js.map +1 -1
  26. package/build/src/core/index.d.ts +2 -1
  27. package/build/src/core/index.d.ts.map +1 -1
  28. package/build/src/core/index.js +2 -1
  29. package/build/src/core/index.js.map +1 -1
  30. package/build/src/define_config.d.ts +17 -0
  31. package/build/src/define_config.d.ts.map +1 -1
  32. package/build/src/define_config.js +9 -0
  33. package/build/src/define_config.js.map +1 -1
  34. package/build/src/integrations/lucid/column/attachment_column.d.ts +18 -0
  35. package/build/src/integrations/lucid/column/attachment_column.d.ts.map +1 -0
  36. package/build/src/integrations/lucid/{attachment_column.js → column/attachment_column.js} +26 -13
  37. package/build/src/integrations/lucid/column/attachment_column.js.map +1 -0
  38. package/build/src/integrations/lucid/index.d.ts +16 -12
  39. package/build/src/integrations/lucid/index.d.ts.map +1 -1
  40. package/build/src/integrations/lucid/index.js +16 -12
  41. package/build/src/integrations/lucid/index.js.map +1 -1
  42. package/build/src/integrations/lucid/migrations/legacy/legacy_attachment_migration_stub.d.ts +20 -0
  43. package/build/src/integrations/lucid/migrations/legacy/legacy_attachment_migration_stub.d.ts.map +1 -0
  44. package/build/src/integrations/lucid/migrations/legacy/legacy_attachment_migration_stub.js +18 -0
  45. package/build/src/integrations/lucid/migrations/legacy/legacy_attachment_migration_stub.js.map +1 -0
  46. package/build/src/integrations/lucid/{migrate_legacy_attachment.d.ts → migrations/legacy/migrate_legacy_attachment.d.ts} +25 -9
  47. package/build/src/integrations/lucid/migrations/legacy/migrate_legacy_attachment.d.ts.map +1 -0
  48. package/build/src/integrations/lucid/migrations/legacy/migrate_legacy_attachment.js +94 -0
  49. package/build/src/integrations/lucid/migrations/legacy/migrate_legacy_attachment.js.map +1 -0
  50. package/build/src/integrations/lucid/{migrate_legacy_attachment_records.d.ts → migrations/legacy/migrate_legacy_attachment_records.d.ts} +3 -3
  51. package/build/src/integrations/lucid/migrations/legacy/migrate_legacy_attachment_records.d.ts.map +1 -0
  52. package/build/src/integrations/lucid/{migrate_legacy_attachment_records.js → migrations/legacy/migrate_legacy_attachment_records.js} +7 -6
  53. package/build/src/integrations/lucid/migrations/legacy/migrate_legacy_attachment_records.js.map +1 -0
  54. package/build/src/integrations/lucid/models/attachment_link_model.d.ts +30 -0
  55. package/build/src/integrations/lucid/models/attachment_link_model.d.ts.map +1 -0
  56. package/build/src/integrations/lucid/models/attachment_link_model.js +58 -0
  57. package/build/src/integrations/lucid/models/attachment_link_model.js.map +1 -0
  58. package/build/src/integrations/lucid/{attachment_model.d.ts → models/attachment_model.d.ts} +2 -6
  59. package/build/src/integrations/lucid/models/attachment_model.d.ts.map +1 -0
  60. package/build/src/integrations/lucid/{attachment_model.js → models/attachment_model.js} +1 -13
  61. package/build/src/integrations/lucid/models/attachment_model.js.map +1 -0
  62. package/build/src/integrations/lucid/persistence/lucid_attachment_lifecycle_service.d.ts +34 -0
  63. package/build/src/integrations/lucid/persistence/lucid_attachment_lifecycle_service.d.ts.map +1 -0
  64. package/build/src/integrations/lucid/persistence/lucid_attachment_lifecycle_service.js +195 -0
  65. package/build/src/integrations/lucid/persistence/lucid_attachment_lifecycle_service.js.map +1 -0
  66. package/build/src/integrations/lucid/{lucid_attachment_repository.d.ts → persistence/lucid_attachment_repository.d.ts} +3 -3
  67. package/build/src/integrations/lucid/persistence/lucid_attachment_repository.d.ts.map +1 -0
  68. package/build/src/integrations/lucid/{lucid_attachment_repository.js → persistence/lucid_attachment_repository.js} +1 -1
  69. package/build/src/integrations/lucid/persistence/lucid_attachment_repository.js.map +1 -0
  70. package/build/src/integrations/lucid/persistence/lucid_attachment_store.d.ts +48 -0
  71. package/build/src/integrations/lucid/persistence/lucid_attachment_store.d.ts.map +1 -0
  72. package/build/src/integrations/lucid/persistence/lucid_attachment_store.js +224 -0
  73. package/build/src/integrations/lucid/persistence/lucid_attachment_store.js.map +1 -0
  74. package/build/src/integrations/lucid/{lucid_variant_generation_service.d.ts → persistence/lucid_variant_generation_service.d.ts} +3 -3
  75. package/build/src/integrations/lucid/persistence/lucid_variant_generation_service.d.ts.map +1 -0
  76. package/build/src/integrations/lucid/persistence/lucid_variant_generation_service.js.map +1 -0
  77. package/build/src/integrations/lucid/{attachment_owner.d.ts → relations/attachment_owner.d.ts} +2 -1
  78. package/build/src/integrations/lucid/relations/attachment_owner.d.ts.map +1 -0
  79. package/build/src/integrations/lucid/relations/attachment_owner.js.map +1 -0
  80. package/build/src/integrations/lucid/relations/attachment_relation.d.ts +71 -0
  81. package/build/src/integrations/lucid/relations/attachment_relation.d.ts.map +1 -0
  82. package/build/src/integrations/lucid/relations/attachment_relation.js +266 -0
  83. package/build/src/integrations/lucid/relations/attachment_relation.js.map +1 -0
  84. package/build/src/integrations/lucid/schema/attachment_schema_service.d.ts +24 -0
  85. package/build/src/integrations/lucid/schema/attachment_schema_service.d.ts.map +1 -0
  86. package/build/src/integrations/lucid/schema/attachment_schema_service.js +68 -0
  87. package/build/src/integrations/lucid/schema/attachment_schema_service.js.map +1 -0
  88. package/build/src/integrations/lucid/schema/attachment_table_names.d.ts +15 -0
  89. package/build/src/integrations/lucid/schema/attachment_table_names.d.ts.map +1 -0
  90. package/build/src/integrations/lucid/schema/attachment_table_names.js +20 -0
  91. package/build/src/integrations/lucid/schema/attachment_table_names.js.map +1 -0
  92. package/build/src/integrations/lucid/schema/attachments_table_stub.d.ts.map +1 -0
  93. package/build/src/integrations/lucid/{attachments_table_stub.js → schema/attachments_table_stub.js} +2 -4
  94. package/build/src/integrations/lucid/schema/attachments_table_stub.js.map +1 -0
  95. package/build/src/integrations/lucid/schema/configure_lucid_attachment_tables.d.ts +12 -0
  96. package/build/src/integrations/lucid/schema/configure_lucid_attachment_tables.d.ts.map +1 -0
  97. package/build/src/integrations/lucid/schema/configure_lucid_attachment_tables.js +19 -0
  98. package/build/src/integrations/lucid/schema/configure_lucid_attachment_tables.js.map +1 -0
  99. package/build/src/sources/attachment_manager.d.ts +14 -12
  100. package/build/src/sources/attachment_manager.d.ts.map +1 -1
  101. package/build/src/sources/attachment_manager.js +14 -6
  102. package/build/src/sources/attachment_manager.js.map +1 -1
  103. package/build/stubs/migrations/attachments_table.stub +7 -24
  104. package/build/{src/integrations/lucid/render_legacy_attachment_migration_script.js → stubs/migrations/legacy_attachment_migration.stub} +13 -15
  105. package/build/tests/attachment_manager.spec.js +21 -18
  106. package/build/tests/attachment_manager.spec.js.map +1 -1
  107. package/build/tests/attachment_manager_service.spec.js +2 -2
  108. package/build/tests/attachment_manager_service.spec.js.map +1 -1
  109. package/build/tests/attachment_options.spec.d.ts +2 -0
  110. package/build/tests/attachment_options.spec.d.ts.map +1 -0
  111. package/build/tests/attachment_options.spec.js +31 -0
  112. package/build/tests/attachment_options.spec.js.map +1 -0
  113. package/build/tests/attachment_provider.spec.js +30 -1
  114. package/build/tests/attachment_provider.spec.js.map +1 -1
  115. package/build/tests/{create_legacy_attachment_migration_script.spec.d.ts → attachment_schema_service.spec.d.ts} +1 -1
  116. package/build/tests/attachment_schema_service.spec.d.ts.map +1 -0
  117. package/build/tests/attachment_schema_service.spec.js +38 -0
  118. package/build/tests/attachment_schema_service.spec.js.map +1 -0
  119. package/build/tests/attachment_service.spec.js +55 -0
  120. package/build/tests/attachment_service.spec.js.map +1 -1
  121. package/build/tests/attachment_table_names.spec.d.ts +8 -0
  122. package/build/tests/attachment_table_names.spec.d.ts.map +1 -0
  123. package/build/tests/attachment_table_names.spec.js +36 -0
  124. package/build/tests/attachment_table_names.spec.js.map +1 -0
  125. package/build/tests/attachments_table_stub.spec.js +41 -5
  126. package/build/tests/attachments_table_stub.spec.js.map +1 -1
  127. package/build/tests/define_config.spec.js +34 -0
  128. package/build/tests/define_config.spec.js.map +1 -1
  129. package/build/tests/helpers/lucid_test_database.d.ts.map +1 -1
  130. package/build/tests/helpers/lucid_test_database.js +16 -6
  131. package/build/tests/helpers/lucid_test_database.js.map +1 -1
  132. package/build/tests/legacy_attachment_migration_stub.spec.d.ts +8 -0
  133. package/build/tests/legacy_attachment_migration_stub.spec.d.ts.map +1 -0
  134. package/build/tests/legacy_attachment_migration_stub.spec.js +57 -0
  135. package/build/tests/legacy_attachment_migration_stub.spec.js.map +1 -0
  136. package/build/tests/lucid_attachment_collection_store.spec.d.ts +2 -0
  137. package/build/tests/lucid_attachment_collection_store.spec.d.ts.map +1 -0
  138. package/build/tests/lucid_attachment_collection_store.spec.js +53 -0
  139. package/build/tests/lucid_attachment_collection_store.spec.js.map +1 -0
  140. package/build/tests/lucid_attachment_column.spec.js +57 -1
  141. package/build/tests/lucid_attachment_column.spec.js.map +1 -1
  142. package/build/tests/lucid_attachment_lifecycle_service.spec.js +117 -111
  143. package/build/tests/lucid_attachment_lifecycle_service.spec.js.map +1 -1
  144. package/build/tests/lucid_attachment_relation.spec.d.ts +8 -0
  145. package/build/tests/lucid_attachment_relation.spec.d.ts.map +1 -0
  146. package/build/tests/lucid_attachment_relation.spec.js +295 -0
  147. package/build/tests/lucid_attachment_relation.spec.js.map +1 -0
  148. package/build/tests/lucid_attachment_repository.spec.js +1 -1
  149. package/build/tests/lucid_attachment_repository.spec.js.map +1 -1
  150. package/build/tests/lucid_attachment_store.spec.js +24 -50
  151. package/build/tests/lucid_attachment_store.spec.js.map +1 -1
  152. package/build/tests/lucid_sqlite_integration.spec.js +23 -18
  153. package/build/tests/lucid_sqlite_integration.spec.js.map +1 -1
  154. package/build/tests/lucid_variant_generation_service.spec.js +1 -1
  155. package/build/tests/lucid_variant_generation_service.spec.js.map +1 -1
  156. package/build/tests/migrate_legacy_attachment.spec.js +114 -67
  157. package/build/tests/migrate_legacy_attachment.spec.js.map +1 -1
  158. package/build/tests/migrate_legacy_attachment_records.spec.js +4 -3
  159. package/build/tests/migrate_legacy_attachment_records.spec.js.map +1 -1
  160. package/package.json +4 -2
  161. package/build/src/integrations/lucid/attachment_column.d.ts +0 -11
  162. package/build/src/integrations/lucid/attachment_column.d.ts.map +0 -1
  163. package/build/src/integrations/lucid/attachment_column.js.map +0 -1
  164. package/build/src/integrations/lucid/attachment_model.d.ts.map +0 -1
  165. package/build/src/integrations/lucid/attachment_model.js.map +0 -1
  166. package/build/src/integrations/lucid/attachment_owner.d.ts.map +0 -1
  167. package/build/src/integrations/lucid/attachment_owner.js.map +0 -1
  168. package/build/src/integrations/lucid/attachments_table_stub.d.ts.map +0 -1
  169. package/build/src/integrations/lucid/attachments_table_stub.js.map +0 -1
  170. package/build/src/integrations/lucid/create_legacy_attachment_migration_script.d.ts +0 -13
  171. package/build/src/integrations/lucid/create_legacy_attachment_migration_script.d.ts.map +0 -1
  172. package/build/src/integrations/lucid/create_legacy_attachment_migration_script.js +0 -20
  173. package/build/src/integrations/lucid/create_legacy_attachment_migration_script.js.map +0 -1
  174. package/build/src/integrations/lucid/lucid_attachment_lifecycle_service.d.ts +0 -21
  175. package/build/src/integrations/lucid/lucid_attachment_lifecycle_service.d.ts.map +0 -1
  176. package/build/src/integrations/lucid/lucid_attachment_lifecycle_service.js +0 -68
  177. package/build/src/integrations/lucid/lucid_attachment_lifecycle_service.js.map +0 -1
  178. package/build/src/integrations/lucid/lucid_attachment_repository.d.ts.map +0 -1
  179. package/build/src/integrations/lucid/lucid_attachment_repository.js.map +0 -1
  180. package/build/src/integrations/lucid/lucid_attachment_store.d.ts +0 -27
  181. package/build/src/integrations/lucid/lucid_attachment_store.d.ts.map +0 -1
  182. package/build/src/integrations/lucid/lucid_attachment_store.js +0 -84
  183. package/build/src/integrations/lucid/lucid_attachment_store.js.map +0 -1
  184. package/build/src/integrations/lucid/lucid_variant_generation_service.d.ts.map +0 -1
  185. package/build/src/integrations/lucid/lucid_variant_generation_service.js.map +0 -1
  186. package/build/src/integrations/lucid/migrate_legacy_attachment.d.ts.map +0 -1
  187. package/build/src/integrations/lucid/migrate_legacy_attachment.js +0 -67
  188. package/build/src/integrations/lucid/migrate_legacy_attachment.js.map +0 -1
  189. package/build/src/integrations/lucid/migrate_legacy_attachment_records.d.ts.map +0 -1
  190. package/build/src/integrations/lucid/migrate_legacy_attachment_records.js.map +0 -1
  191. package/build/src/integrations/lucid/render_legacy_attachment_migration_script.d.ts +0 -11
  192. package/build/src/integrations/lucid/render_legacy_attachment_migration_script.d.ts.map +0 -1
  193. package/build/src/integrations/lucid/render_legacy_attachment_migration_script.js.map +0 -1
  194. package/build/tests/create_legacy_attachment_migration_script.spec.d.ts.map +0 -1
  195. package/build/tests/create_legacy_attachment_migration_script.spec.js +0 -31
  196. package/build/tests/create_legacy_attachment_migration_script.spec.js.map +0 -1
  197. /package/build/src/integrations/lucid/{lucid_variant_generation_service.js → persistence/lucid_variant_generation_service.js} +0 -0
  198. /package/build/src/integrations/lucid/{attachment_owner.js → relations/attachment_owner.js} +0 -0
  199. /package/build/src/integrations/lucid/{attachments_table_stub.d.ts → schema/attachments_table_stub.d.ts} +0 -0
@@ -0,0 +1,48 @@
1
+ /**
2
+ * @jrmc/adonis-attachment
3
+ *
4
+ * @license MIT
5
+ * @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
6
+ */
7
+ import type { TransactionClientContract } from '@adonisjs/lucid/types/database';
8
+ import type { Attachment } from '../../../core/attachment.js';
9
+ import { type AttachmentOwner } from '../relations/attachment_owner.js';
10
+ import { AttachmentLinkModel } from '../models/attachment_link_model.js';
11
+ import { AttachmentModel } from '../models/attachment_model.js';
12
+ export type LucidAttachmentWithVariants = {
13
+ original: AttachmentLinkModel;
14
+ variants: AttachmentModel[];
15
+ };
16
+ export type LucidAttachmentStoreOptions = {
17
+ client?: TransactionClientContract;
18
+ linkModel?: typeof AttachmentLinkModel;
19
+ createLinkId?: () => string;
20
+ };
21
+ /**
22
+ * Persists immutable file blobs separately from their polymorphic owner links.
23
+ */
24
+ export declare class LucidAttachmentStore {
25
+ #private;
26
+ constructor(blobModel?: typeof AttachmentModel, options?: LucidAttachmentStoreOptions);
27
+ createOriginal(owner: AttachmentOwner, attachment: Attachment): Promise<AttachmentLinkModel>;
28
+ createCollectionItem(owner: AttachmentOwner, attachment: Attachment, position?: number): Promise<AttachmentLinkModel>;
29
+ createOriginalLink(owner: AttachmentOwner, attachmentId: string): Promise<AttachmentLinkModel>;
30
+ createCollectionLink(owner: AttachmentOwner, attachmentId: string, position?: number): Promise<AttachmentLinkModel>;
31
+ createVariant(original: AttachmentModel, key: string, attachment: Attachment): Promise<AttachmentModel>;
32
+ releaseOwner(original: AttachmentLinkModel): Promise<void>;
33
+ restoreOwner(original: AttachmentLinkModel): Promise<void>;
34
+ findOriginal(owner: AttachmentOwner): Promise<AttachmentLinkModel | null>;
35
+ listCollection(owner: AttachmentOwner): Promise<AttachmentLinkModel[]>;
36
+ findCollectionItem(owner: AttachmentOwner, id: string): Promise<AttachmentLinkModel | null>;
37
+ removeCollectionItem(owner: AttachmentOwner, item: AttachmentLinkModel): Promise<AttachmentModel[]>;
38
+ moveCollectionItem(owner: AttachmentOwner, id: string, position: number): Promise<AttachmentLinkModel[]>;
39
+ findById(id: string): Promise<AttachmentModel | null>;
40
+ findByOwner(owner: AttachmentOwner): Promise<LucidAttachmentWithVariants | null>;
41
+ listVariants(originalId: string): Promise<AttachmentModel[]>;
42
+ /**
43
+ * Deletes a link and returns blobs that became unreferenced and were removed.
44
+ */
45
+ remove(link: AttachmentLinkModel): Promise<AttachmentModel[]>;
46
+ listOwnerLinks(owner: AttachmentOwner): Promise<AttachmentLinkModel[]>;
47
+ }
48
+ //# sourceMappingURL=lucid_attachment_store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lucid_attachment_store.d.ts","sourceRoot":"","sources":["../../../../../src/integrations/lucid/persistence/lucid_attachment_store.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAA;AAE/E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAA;AAE7D,OAAO,EAA4B,KAAK,eAAe,EAAE,MAAM,kCAAkC,CAAA;AACjG,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAA;AACxE,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAE/D,MAAM,MAAM,2BAA2B,GAAG;IACxC,QAAQ,EAAE,mBAAmB,CAAA;IAC7B,QAAQ,EAAE,eAAe,EAAE,CAAA;CAC5B,CAAA;AAED,MAAM,MAAM,2BAA2B,GAAG;IACxC,MAAM,CAAC,EAAE,yBAAyB,CAAA;IAClC,SAAS,CAAC,EAAE,OAAO,mBAAmB,CAAA;IACtC,YAAY,CAAC,EAAE,MAAM,MAAM,CAAA;CAC5B,CAAA;AAED;;GAEG;AACH,qBAAa,oBAAoB;;gBAO7B,SAAS,GAAE,OAAO,eAA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Q,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;IAI/C,WAAW,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,2BAA2B,GAAG,IAAI,CAAC;IAatF,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC;IAI5D;;OAEG;IACG,MAAM,CAAC,IAAI,EAAE,mBAAmB,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC;IAcnE,cAAc,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,mBAAmB,EAAE,CAAC;CAiGvE"}
@@ -0,0 +1,224 @@
1
+ /**
2
+ * @jrmc/adonis-attachment
3
+ *
4
+ * @license MIT
5
+ * @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
6
+ */
7
+ import { randomUUID } from 'node:crypto';
8
+ import { markAttachmentPersisted } from '../../../core/attachment_state.js';
9
+ import { createAttachmentOwnerKey } from '../relations/attachment_owner.js';
10
+ import { AttachmentLinkModel } from '../models/attachment_link_model.js';
11
+ import { AttachmentModel } from '../models/attachment_model.js';
12
+ /**
13
+ * Persists immutable file blobs separately from their polymorphic owner links.
14
+ */
15
+ export class LucidAttachmentStore {
16
+ #blobModel;
17
+ #linkModel;
18
+ #client;
19
+ #createLinkId;
20
+ constructor(blobModel = AttachmentModel, options = {}) {
21
+ this.#blobModel = blobModel;
22
+ this.#linkModel = options.linkModel ?? AttachmentLinkModel;
23
+ this.#client = options.client;
24
+ this.#createLinkId = options.createLinkId ?? randomUUID;
25
+ }
26
+ async createOriginal(owner, attachment) {
27
+ const blob = await this.#createBlob(attachment);
28
+ try {
29
+ return await this.#createLink(owner, blob, { ownerKey: createAttachmentOwnerKey(owner) });
30
+ }
31
+ catch (error) {
32
+ await blob.delete().catch(() => undefined);
33
+ throw error;
34
+ }
35
+ }
36
+ async createCollectionItem(owner, attachment, position) {
37
+ const items = await this.listCollection(owner);
38
+ const target = normalizePosition(position, items.length);
39
+ const blob = await this.#createBlob(attachment);
40
+ try {
41
+ await this.#shiftCollection(items, target, 1);
42
+ return await this.#createLink(owner, blob, { position: target });
43
+ }
44
+ catch (error) {
45
+ await blob.delete().catch(() => undefined);
46
+ throw error;
47
+ }
48
+ }
49
+ async createOriginalLink(owner, attachmentId) {
50
+ const blob = await this.#findBlobOrFail(attachmentId);
51
+ return this.#createLink(owner, blob, { ownerKey: createAttachmentOwnerKey(owner) });
52
+ }
53
+ async createCollectionLink(owner, attachmentId, position) {
54
+ const items = await this.listCollection(owner);
55
+ const target = normalizePosition(position, items.length);
56
+ const blob = await this.#findBlobOrFail(attachmentId);
57
+ await this.#shiftCollection(items, target, 1);
58
+ return this.#createLink(owner, blob, { position: target });
59
+ }
60
+ createVariant(original, key, attachment) {
61
+ return this.#createBlob(attachment, { parentId: original.id, variantKey: key });
62
+ }
63
+ async releaseOwner(original) {
64
+ original.ownerKey = null;
65
+ await original.save();
66
+ }
67
+ async restoreOwner(original) {
68
+ original.ownerKey = createAttachmentOwnerKey({
69
+ type: original.attachableType,
70
+ id: original.attachableId,
71
+ field: original.field,
72
+ });
73
+ await original.save();
74
+ }
75
+ findOriginal(owner) {
76
+ return this.#linkQuery()
77
+ .where('attachable_type', owner.type)
78
+ .where('attachable_id', owner.id)
79
+ .where('field', owner.field)
80
+ .whereNotNull('owner_key')
81
+ .first();
82
+ }
83
+ listCollection(owner) {
84
+ return this.#linkQuery()
85
+ .where('attachable_type', owner.type)
86
+ .where('attachable_id', owner.id)
87
+ .where('field', owner.field)
88
+ .whereNull('owner_key')
89
+ .orderBy('position', 'asc');
90
+ }
91
+ findCollectionItem(owner, id) {
92
+ return this.#linkQuery()
93
+ .where('id', id)
94
+ .where('attachable_type', owner.type)
95
+ .where('attachable_id', owner.id)
96
+ .where('field', owner.field)
97
+ .whereNull('owner_key')
98
+ .first();
99
+ }
100
+ async removeCollectionItem(owner, item) {
101
+ const removed = await this.remove(item);
102
+ await this.#normalizeCollection(owner);
103
+ return removed;
104
+ }
105
+ async moveCollectionItem(owner, id, position) {
106
+ const items = await this.listCollection(owner);
107
+ const source = items.findIndex((item) => item.id === id);
108
+ if (source === -1) {
109
+ throw new Error(`Attachment link "${id}" does not belong to this collection`);
110
+ }
111
+ const target = normalizePosition(position, items.length - 1);
112
+ if (source === target) {
113
+ return items;
114
+ }
115
+ const [item] = items.splice(source, 1);
116
+ items.splice(target, 0, item);
117
+ await this.#reorderCollection(items);
118
+ return items;
119
+ }
120
+ findById(id) {
121
+ return this.#blobQuery().where('id', id).first();
122
+ }
123
+ async findByOwner(owner) {
124
+ const original = await this.findOriginal(owner);
125
+ if (!original) {
126
+ return null;
127
+ }
128
+ return {
129
+ original,
130
+ variants: await this.listVariants(original.attachmentId),
131
+ };
132
+ }
133
+ listVariants(originalId) {
134
+ return this.#blobQuery().where('parent_id', originalId);
135
+ }
136
+ /**
137
+ * Deletes a link and returns blobs that became unreferenced and were removed.
138
+ */
139
+ async remove(link) {
140
+ const attachment = link.attachment ?? (await this.findById(link.attachmentId));
141
+ await link.delete();
142
+ if (!attachment || (await this.#linkQuery().where('attachment_id', attachment.id).first())) {
143
+ return [];
144
+ }
145
+ const variants = await this.listVariants(attachment.id);
146
+ await attachment.delete();
147
+ return [attachment, ...variants];
148
+ }
149
+ listOwnerLinks(owner) {
150
+ return this.#linkQuery()
151
+ .where('attachable_type', owner.type)
152
+ .where('attachable_id', owner.id);
153
+ }
154
+ async #createBlob(attachment, options = {}) {
155
+ const blob = await this.#blobModel.create({
156
+ ...attachment,
157
+ parentId: options.parentId ?? null,
158
+ variantKey: options.variantKey ?? null,
159
+ metadata: attachment.metadata ?? null,
160
+ }, this.#client ? { client: this.#client } : undefined);
161
+ markAttachmentPersisted(attachment);
162
+ return blob;
163
+ }
164
+ async #findBlobOrFail(id) {
165
+ const blob = await this.findById(id);
166
+ if (!blob) {
167
+ throw new Error(`Attachment blob "${id}" does not exist`);
168
+ }
169
+ return blob;
170
+ }
171
+ async #createLink(owner, attachment, options = {}) {
172
+ const link = await this.#linkModel.create({
173
+ id: this.#createLinkId(),
174
+ attachableType: owner.type,
175
+ attachableId: owner.id,
176
+ field: owner.field,
177
+ ownerKey: options.ownerKey ?? null,
178
+ position: options.position ?? null,
179
+ attachmentId: attachment.id,
180
+ }, this.#client ? { client: this.#client } : undefined);
181
+ return this.#linkQuery().where('id', link.id).firstOrFail();
182
+ }
183
+ async #normalizeCollection(owner) {
184
+ await this.#reorderCollection(await this.listCollection(owner));
185
+ }
186
+ #blobQuery() {
187
+ return this.#blobModel.query(this.#client ? { client: this.#client } : undefined);
188
+ }
189
+ #linkQuery() {
190
+ return this.#linkModel
191
+ .query(this.#client ? { client: this.#client } : undefined)
192
+ .preload('attachment');
193
+ }
194
+ async #shiftCollection(items, from, amount) {
195
+ for (const item of [...items].reverse()) {
196
+ if ((item.position ?? 0) < from) {
197
+ continue;
198
+ }
199
+ item.position = (item.position ?? 0) + amount;
200
+ await item.save();
201
+ }
202
+ }
203
+ async #reorderCollection(items) {
204
+ const offset = items.length + 1;
205
+ for (const item of items) {
206
+ item.position = (item.position ?? 0) + offset;
207
+ await item.save();
208
+ }
209
+ for (const [position, item] of items.entries()) {
210
+ item.position = position;
211
+ await item.save();
212
+ }
213
+ }
214
+ }
215
+ function normalizePosition(position, maximum) {
216
+ if (position === undefined) {
217
+ return maximum;
218
+ }
219
+ if (!Number.isSafeInteger(position) || position < 0) {
220
+ throw new Error('Attachment collection positions must be non-negative integers');
221
+ }
222
+ return Math.min(position, maximum);
223
+ }
224
+ //# sourceMappingURL=lucid_attachment_store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lucid_attachment_store.js","sourceRoot":"","sources":["../../../../../src/integrations/lucid/persistence/lucid_attachment_store.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAKxC,OAAO,EAAE,uBAAuB,EAAE,MAAM,mCAAmC,CAAA;AAC3E,OAAO,EAA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C,QAAQ,IAAI,CAAC,CAAC,GAAG,MAAM,CAAA;YAC7C,MAAM,IAAI,CAAC,IAAI,EAAE,CAAA;QACnB,CAAC;IACH,CAAC;IAED,KAAK,CAAC,kBAAkB,CAAC,KAAqC;QAC5D,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,CAAA;QAE/B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,IAAI,CAAC,QAAQ,GAAG,CAAC,IAAI,CAAC,QAAQ,IAAI,CAAC,CAAC,GAAG,MAAM,CAAA;YAC7C,MAAM,IAAI,CAAC,IAAI,EAAE,CAAA;QACnB,CAAC;QAED,KAAK,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,IAAI,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC;YAC/C,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;YACxB,MAAM,IAAI,CAAC,IAAI,EAAE,CAAA;QACnB,CAAC;IACH,CAAC;CACF;AAED,SAAS,iBAAiB,CAAC,QAA4B,EAAE,OAAe;IACtE,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,OAAO,OAAO,CAAA;IAChB,CAAC;IAED,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,QAAQ,CAAC,IAAI,QAAQ,GAAG,CAAC,EAAE,CAAC;QACpD,MAAM,IAAI,KAAK,CAAC,+DAA+D,CAAC,CAAA;IAClF,CAAC;IAED,OAAO,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;AACpC,CAAC"}
@@ -4,9 +4,9 @@
4
4
  * @license MIT
5
5
  * @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
6
6
  */
7
- import type { AttachmentService } from '../../core/attachment_service.js';
8
- import type { VariantGenerationRequest, VariantGenerator } from '../../core/attachment_job_processor.js';
9
- import type { VariantGenerationService } from '../../variants/variant_generation_service.js';
7
+ import type { AttachmentService } from '../../../core/attachment_service.js';
8
+ import type { VariantGenerationRequest, VariantGenerator } from '../../../core/attachment_job_processor.js';
9
+ import type { VariantGenerationService } from '../../../variants/variant_generation_service.js';
10
10
  import { LucidAttachmentStore } from './lucid_attachment_store.js';
11
11
  export type LucidVariantGenerationServiceOptions = {
12
12
  generator: Pick<VariantGenerationService, 'generateAll'>;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lucid_variant_generation_service.d.ts","sourceRoot":"","sources":["../../../../../src/integrations/lucid/persistence/lucid_variant_generation_service.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAA;AAC5E,OAAO,KAAK,EAAE,wBAAwB,EAAE,gBAAgB,EAAE,MAAM,2CAA2C,CAAA;AAC3G,OAAO,KAAK,EAAoB,wBAAwB,EAAE,MAAM,iDAAiD,CAAA;AAEjH,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAA;AAElE,MAAM,MAAM,oCAAoC,GAAG;IACjD,SAAS,EAAE,IAAI,CAAC,wBAAwB,EAAE,aAAa,CAAC,CAAA;IACxD,WAAW,EAAE,IAAI,CAAC,iBAAiB,EAAE,QAAQ,CAAC,CAAA;IAC9C,KAAK,EAAE,IAAI,CAAC,oBAAoB,EAAE,UAAU,GAAG,eAAe,CAAC,CAAA;CAChE,CAAA;AAED,qBAAa,6BAA8B,YAAW,gBAAgB;;gBAKxD,OAAO,EAAE,oCAAoC;IAMnD,QAAQ,CAAC,OAAO,EAAE,wBAAwB,GAAG,OAAO,CAAC,IAAI,CAAC;CAqBjE;AAED,qBAAa,gCAAiC,SAAQ,KAAK;gBAC7C,EAAE,EAAE,MAAM;CAIvB"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lucid_variant_generation_service.js","sourceRoot":"","sources":["../../../../../src/integrations/lucid/persistence/lucid_variant_generation_service.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAcH,MAAM,OAAO,6BAA6B;IAC/B,UAAU,CAA+C;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AkC,CAAA;IAChD,CAAC;CACF"}
@@ -4,10 +4,11 @@
4
4
  * @license MIT
5
5
  * @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
6
6
  */
7
- export type AttachmentOwner = {
7
+ export type AttachmentOwner<Model = unknown> = {
8
8
  type: string;
9
9
  id: string;
10
10
  field: string;
11
+ model?: Model;
11
12
  };
12
13
  /**
13
14
  * Produces the database key that enforces one original attachment per owner field.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attachment_owner.d.ts","sourceRoot":"","sources":["../../../../../src/integrations/lucid/relations/attachment_owner.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,MAAM,MAAM,eAAe,CAAC,KAAK,GAAG,OAAO,IAAI;IAC7C,IAAI,EAAE,MAAM,CAAA;IACZ,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,KAAK,CAAA;CACd,CAAA;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,eAAe,GAAG,MAAM,CAEvE"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attachment_owner.js","sourceRoot":"","sources":["../../../../../src/integrations/lucid/relations/attachment_owner.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AASxC;;;GAGG;AACH,MAAM,UAAU,wBAAwB,CAAC,KAAsB;IAC7D,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AACvG,CAAC"}
@@ -0,0 +1,71 @@
1
+ /**
2
+ * @jrmc/adonis-attachment
3
+ *
4
+ * @license MIT
5
+ * @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
6
+ */
7
+ import type { LucidRow } from "@adonisjs/lucid/types/model";
8
+ import type { AttachmentDraft, CreateAttachmentInput } from "../../../core/attachment.js";
9
+ import type { AttachmentPersistenceOptions } from "../../../core/attachment_options.js";
10
+ import { AttachmentLinkModel } from "../models/attachment_link_model.js";
11
+ import { AttachmentModel } from "../models/attachment_model.js";
12
+ type AttachmentRelationInput = CreateAttachmentInput | AttachmentDraft;
13
+ type AttachmentRelationRow = LucidRow & {
14
+ $isPersisted: boolean;
15
+ $primaryKeyValue: string | number | null | undefined;
16
+ constructor: {
17
+ table?: string;
18
+ name: string;
19
+ boot(): void;
20
+ prototype: AttachmentRelationRow & {
21
+ save(): Promise<unknown>;
22
+ };
23
+ after(event: "delete", callback: (row: AttachmentRelationRow) => void | Promise<void>): void;
24
+ };
25
+ };
26
+ type RelationKind = "one" | "many";
27
+ type RelationDefinition = {
28
+ kind: RelationKind;
29
+ field: string;
30
+ options: AttachmentRelationOptions<any>;
31
+ };
32
+ export type AttachmentRelationOptions<Model = any> = AttachmentPersistenceOptions<Model> & {
33
+ type?: string;
34
+ };
35
+ /**
36
+ * Declares one attachment persisted in the polymorphic attachments table.
37
+ */
38
+ export declare function attachmentRelation<Model = LucidRow>(options?: AttachmentRelationOptions<Model>): PropertyDecorator;
39
+ /**
40
+ * Declares an ordered attachment collection persisted in the polymorphic attachments table.
41
+ */
42
+ export declare function attachmentsRelation<Model = LucidRow>(options?: AttachmentRelationOptions<Model>): PropertyDecorator;
43
+ export declare class AttachmentRelation {
44
+ #private;
45
+ constructor(row: AttachmentRelationRow, definition: RelationDefinition);
46
+ get(): Promise<AttachmentLinkModel | null>;
47
+ get hasPending(): boolean;
48
+ attach(input: AttachmentRelationInput): void;
49
+ attachExisting(attachmentId: string): void;
50
+ set(input: AttachmentRelationInput): void;
51
+ replace(input: AttachmentRelationInput): void;
52
+ detach(): void;
53
+ persist(): Promise<AttachmentLinkModel | null>;
54
+ variants(): Promise<AttachmentModel[]>;
55
+ regenerateVariants(variantKeys?: readonly string[]): Promise<boolean>;
56
+ }
57
+ export declare class AttachmentCollectionRelation {
58
+ #private;
59
+ constructor(row: AttachmentRelationRow, definition: RelationDefinition);
60
+ all(): Promise<AttachmentLinkModel[]>;
61
+ get hasPending(): boolean;
62
+ add(input: AttachmentRelationInput, position?: number): void;
63
+ addExisting(attachmentId: string, position?: number): void;
64
+ remove(id: string): void;
65
+ clear(): void;
66
+ replaceAll(inputs: readonly AttachmentRelationInput[]): void;
67
+ move(id: string, position: number): void;
68
+ persist(): Promise<AttachmentLinkModel[]>;
69
+ }
70
+ export {};
71
+ //# sourceMappingURL=attachment_relation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attachment_relation.d.ts","sourceRoot":"","sources":["../../../../../src/integrations/lucid/relations/attachment_relation.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAE5D,OAAO,KAAK,EAEV,eAAe,EACf,qBAAqB,EACtB,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,qCAAqC,CAAC;AAGxF,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAIhE,KAAK,uBAAuB,GAAG,qBAAqB,GAAG,eAAe,CAAC;AAEvE,KAAK,qBAAqB,GAAG,QAAQ,GAAG;IACtC,YAAY,EAAE,OAAO,CAAC;IACtB,gBAAgB,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACrD,WAAW,EAAE;QACX,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,IAAI,IAAI,CAAC;QACb,SAAS,EAAE,qBAAqB,GAAG;YACjC,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;SAC1B,CAAC;QACF,KAAK,CACH,KAAK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