@jrmc/adonis-attachment 6.0.0-alpha.1 → 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 (162) 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 +6 -6
  8. package/build/index.d.ts.map +1 -1
  9. package/build/index.js +5 -5
  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/define_config.d.ts +13 -0
  15. package/build/src/define_config.d.ts.map +1 -1
  16. package/build/src/define_config.js +8 -0
  17. package/build/src/define_config.js.map +1 -1
  18. package/build/src/integrations/lucid/{attachment_column.d.ts → column/attachment_column.d.ts} +2 -2
  19. package/build/src/integrations/lucid/column/attachment_column.d.ts.map +1 -0
  20. package/build/src/integrations/lucid/{attachment_column.js → column/attachment_column.js} +2 -2
  21. package/build/src/integrations/lucid/column/attachment_column.js.map +1 -0
  22. package/build/src/integrations/lucid/index.d.ts +16 -13
  23. package/build/src/integrations/lucid/index.d.ts.map +1 -1
  24. package/build/src/integrations/lucid/index.js +16 -13
  25. package/build/src/integrations/lucid/index.js.map +1 -1
  26. package/build/src/integrations/lucid/migrations/legacy/legacy_attachment_migration_stub.d.ts +20 -0
  27. package/build/src/integrations/lucid/migrations/legacy/legacy_attachment_migration_stub.d.ts.map +1 -0
  28. package/build/src/integrations/lucid/migrations/legacy/legacy_attachment_migration_stub.js +18 -0
  29. package/build/src/integrations/lucid/migrations/legacy/legacy_attachment_migration_stub.js.map +1 -0
  30. package/build/src/integrations/lucid/{migrate_legacy_attachment.d.ts → migrations/legacy/migrate_legacy_attachment.d.ts} +19 -10
  31. package/build/src/integrations/lucid/migrations/legacy/migrate_legacy_attachment.d.ts.map +1 -0
  32. package/build/src/integrations/lucid/{migrate_legacy_attachment.js → migrations/legacy/migrate_legacy_attachment.js} +28 -23
  33. package/build/src/integrations/lucid/migrations/legacy/migrate_legacy_attachment.js.map +1 -0
  34. package/build/src/integrations/lucid/{migrate_legacy_attachment_records.d.ts → migrations/legacy/migrate_legacy_attachment_records.d.ts} +3 -3
  35. package/build/src/integrations/lucid/migrations/legacy/migrate_legacy_attachment_records.d.ts.map +1 -0
  36. package/build/src/integrations/lucid/{migrate_legacy_attachment_records.js → migrations/legacy/migrate_legacy_attachment_records.js} +7 -6
  37. package/build/src/integrations/lucid/migrations/legacy/migrate_legacy_attachment_records.js.map +1 -0
  38. package/build/src/integrations/lucid/models/attachment_link_model.d.ts +30 -0
  39. package/build/src/integrations/lucid/models/attachment_link_model.d.ts.map +1 -0
  40. package/build/src/integrations/lucid/models/attachment_link_model.js +58 -0
  41. package/build/src/integrations/lucid/models/attachment_link_model.js.map +1 -0
  42. package/build/src/integrations/lucid/{attachment_model.d.ts → models/attachment_model.d.ts} +2 -7
  43. package/build/src/integrations/lucid/models/attachment_model.d.ts.map +1 -0
  44. package/build/src/integrations/lucid/{attachment_model.js → models/attachment_model.js} +1 -16
  45. package/build/src/integrations/lucid/models/attachment_model.js.map +1 -0
  46. package/build/src/integrations/lucid/{lucid_attachment_lifecycle_service.d.ts → persistence/lucid_attachment_lifecycle_service.d.ts} +17 -13
  47. package/build/src/integrations/lucid/persistence/lucid_attachment_lifecycle_service.d.ts.map +1 -0
  48. package/build/src/integrations/lucid/{lucid_attachment_lifecycle_service.js → persistence/lucid_attachment_lifecycle_service.js} +27 -20
  49. package/build/src/integrations/lucid/persistence/lucid_attachment_lifecycle_service.js.map +1 -0
  50. package/build/src/integrations/lucid/{lucid_attachment_repository.d.ts → persistence/lucid_attachment_repository.d.ts} +3 -3
  51. package/build/src/integrations/lucid/persistence/lucid_attachment_repository.d.ts.map +1 -0
  52. package/build/src/integrations/lucid/{lucid_attachment_repository.js → persistence/lucid_attachment_repository.js} +1 -1
  53. package/build/src/integrations/lucid/persistence/lucid_attachment_repository.js.map +1 -0
  54. package/build/src/integrations/lucid/persistence/lucid_attachment_store.d.ts +48 -0
  55. package/build/src/integrations/lucid/persistence/lucid_attachment_store.d.ts.map +1 -0
  56. package/build/src/integrations/lucid/persistence/lucid_attachment_store.js +224 -0
  57. package/build/src/integrations/lucid/persistence/lucid_attachment_store.js.map +1 -0
  58. package/build/src/integrations/lucid/{lucid_variant_generation_service.d.ts → persistence/lucid_variant_generation_service.d.ts} +3 -3
  59. package/build/src/integrations/lucid/persistence/lucid_variant_generation_service.d.ts.map +1 -0
  60. package/build/src/integrations/lucid/persistence/lucid_variant_generation_service.js.map +1 -0
  61. package/build/src/integrations/lucid/relations/attachment_owner.d.ts.map +1 -0
  62. package/build/src/integrations/lucid/relations/attachment_owner.js.map +1 -0
  63. package/build/src/integrations/lucid/{attachment_relation.d.ts → relations/attachment_relation.d.ts} +25 -14
  64. package/build/src/integrations/lucid/relations/attachment_relation.d.ts.map +1 -0
  65. package/build/src/integrations/lucid/relations/attachment_relation.js +266 -0
  66. package/build/src/integrations/lucid/relations/attachment_relation.js.map +1 -0
  67. package/build/src/integrations/lucid/schema/attachment_schema_service.d.ts +24 -0
  68. package/build/src/integrations/lucid/schema/attachment_schema_service.d.ts.map +1 -0
  69. package/build/src/integrations/lucid/schema/attachment_schema_service.js +68 -0
  70. package/build/src/integrations/lucid/schema/attachment_schema_service.js.map +1 -0
  71. package/build/src/integrations/lucid/schema/attachment_table_names.d.ts +15 -0
  72. package/build/src/integrations/lucid/schema/attachment_table_names.d.ts.map +1 -0
  73. package/build/src/integrations/lucid/schema/attachment_table_names.js +20 -0
  74. package/build/src/integrations/lucid/schema/attachment_table_names.js.map +1 -0
  75. package/build/src/integrations/lucid/schema/attachments_table_stub.d.ts.map +1 -0
  76. package/build/src/integrations/lucid/{attachments_table_stub.js → schema/attachments_table_stub.js} +2 -4
  77. package/build/src/integrations/lucid/schema/attachments_table_stub.js.map +1 -0
  78. package/build/src/integrations/lucid/schema/configure_lucid_attachment_tables.d.ts +12 -0
  79. package/build/src/integrations/lucid/schema/configure_lucid_attachment_tables.d.ts.map +1 -0
  80. package/build/src/integrations/lucid/schema/configure_lucid_attachment_tables.js +19 -0
  81. package/build/src/integrations/lucid/schema/configure_lucid_attachment_tables.js.map +1 -0
  82. package/build/stubs/migrations/attachments_table.stub +7 -25
  83. package/build/{src/integrations/lucid/render_legacy_attachment_migration_script.js → stubs/migrations/legacy_attachment_migration.stub} +13 -15
  84. package/build/tests/attachment_provider.spec.js +30 -1
  85. package/build/tests/attachment_provider.spec.js.map +1 -1
  86. package/build/tests/{create_legacy_attachment_migration_script.spec.d.ts → attachment_schema_service.spec.d.ts} +1 -1
  87. package/build/tests/attachment_schema_service.spec.d.ts.map +1 -0
  88. package/build/tests/attachment_schema_service.spec.js +38 -0
  89. package/build/tests/attachment_schema_service.spec.js.map +1 -0
  90. package/build/tests/attachment_table_names.spec.d.ts +8 -0
  91. package/build/tests/attachment_table_names.spec.d.ts.map +1 -0
  92. package/build/tests/attachment_table_names.spec.js +36 -0
  93. package/build/tests/attachment_table_names.spec.js.map +1 -0
  94. package/build/tests/attachments_table_stub.spec.js +41 -6
  95. package/build/tests/attachments_table_stub.spec.js.map +1 -1
  96. package/build/tests/define_config.spec.js +22 -0
  97. package/build/tests/define_config.spec.js.map +1 -1
  98. package/build/tests/helpers/lucid_test_database.d.ts.map +1 -1
  99. package/build/tests/helpers/lucid_test_database.js +16 -7
  100. package/build/tests/helpers/lucid_test_database.js.map +1 -1
  101. package/build/tests/legacy_attachment_migration_stub.spec.d.ts +8 -0
  102. package/build/tests/legacy_attachment_migration_stub.spec.d.ts.map +1 -0
  103. package/build/tests/legacy_attachment_migration_stub.spec.js +57 -0
  104. package/build/tests/legacy_attachment_migration_stub.spec.js.map +1 -0
  105. package/build/tests/lucid_attachment_collection_store.spec.js +5 -4
  106. package/build/tests/lucid_attachment_collection_store.spec.js.map +1 -1
  107. package/build/tests/lucid_attachment_lifecycle_service.spec.js +96 -262
  108. package/build/tests/lucid_attachment_lifecycle_service.spec.js.map +1 -1
  109. package/build/tests/lucid_attachment_relation.spec.js +103 -24
  110. package/build/tests/lucid_attachment_relation.spec.js.map +1 -1
  111. package/build/tests/lucid_attachment_repository.spec.js +1 -1
  112. package/build/tests/lucid_attachment_repository.spec.js.map +1 -1
  113. package/build/tests/lucid_attachment_store.spec.js +24 -52
  114. package/build/tests/lucid_attachment_store.spec.js.map +1 -1
  115. package/build/tests/lucid_sqlite_integration.spec.js +23 -18
  116. package/build/tests/lucid_sqlite_integration.spec.js.map +1 -1
  117. package/build/tests/lucid_variant_generation_service.spec.js +1 -1
  118. package/build/tests/lucid_variant_generation_service.spec.js.map +1 -1
  119. package/build/tests/migrate_legacy_attachment.spec.js +48 -43
  120. package/build/tests/migrate_legacy_attachment.spec.js.map +1 -1
  121. package/build/tests/migrate_legacy_attachment_records.spec.js +4 -3
  122. package/build/tests/migrate_legacy_attachment_records.spec.js.map +1 -1
  123. package/package.json +1 -1
  124. package/build/src/integrations/lucid/attachment_column.d.ts.map +0 -1
  125. package/build/src/integrations/lucid/attachment_column.js.map +0 -1
  126. package/build/src/integrations/lucid/attachment_model.d.ts.map +0 -1
  127. package/build/src/integrations/lucid/attachment_model.js.map +0 -1
  128. package/build/src/integrations/lucid/attachment_owner.d.ts.map +0 -1
  129. package/build/src/integrations/lucid/attachment_owner.js.map +0 -1
  130. package/build/src/integrations/lucid/attachment_relation.d.ts.map +0 -1
  131. package/build/src/integrations/lucid/attachment_relation.js +0 -163
  132. package/build/src/integrations/lucid/attachment_relation.js.map +0 -1
  133. package/build/src/integrations/lucid/attachments_table_stub.d.ts.map +0 -1
  134. package/build/src/integrations/lucid/attachments_table_stub.js.map +0 -1
  135. package/build/src/integrations/lucid/create_legacy_attachment_migration_script.d.ts +0 -13
  136. package/build/src/integrations/lucid/create_legacy_attachment_migration_script.d.ts.map +0 -1
  137. package/build/src/integrations/lucid/create_legacy_attachment_migration_script.js +0 -20
  138. package/build/src/integrations/lucid/create_legacy_attachment_migration_script.js.map +0 -1
  139. package/build/src/integrations/lucid/lucid_attachment_lifecycle_service.d.ts.map +0 -1
  140. package/build/src/integrations/lucid/lucid_attachment_lifecycle_service.js.map +0 -1
  141. package/build/src/integrations/lucid/lucid_attachment_repository.d.ts.map +0 -1
  142. package/build/src/integrations/lucid/lucid_attachment_repository.js.map +0 -1
  143. package/build/src/integrations/lucid/lucid_attachment_store.d.ts +0 -36
  144. package/build/src/integrations/lucid/lucid_attachment_store.d.ts.map +0 -1
  145. package/build/src/integrations/lucid/lucid_attachment_store.js +0 -179
  146. package/build/src/integrations/lucid/lucid_attachment_store.js.map +0 -1
  147. package/build/src/integrations/lucid/lucid_variant_generation_service.d.ts.map +0 -1
  148. package/build/src/integrations/lucid/lucid_variant_generation_service.js.map +0 -1
  149. package/build/src/integrations/lucid/migrate_legacy_attachment.d.ts.map +0 -1
  150. package/build/src/integrations/lucid/migrate_legacy_attachment.js.map +0 -1
  151. package/build/src/integrations/lucid/migrate_legacy_attachment_records.d.ts.map +0 -1
  152. package/build/src/integrations/lucid/migrate_legacy_attachment_records.js.map +0 -1
  153. package/build/src/integrations/lucid/render_legacy_attachment_migration_script.d.ts +0 -11
  154. package/build/src/integrations/lucid/render_legacy_attachment_migration_script.d.ts.map +0 -1
  155. package/build/src/integrations/lucid/render_legacy_attachment_migration_script.js.map +0 -1
  156. package/build/tests/create_legacy_attachment_migration_script.spec.d.ts.map +0 -1
  157. package/build/tests/create_legacy_attachment_migration_script.spec.js +0 -31
  158. package/build/tests/create_legacy_attachment_migration_script.spec.js.map +0 -1
  159. /package/build/src/integrations/lucid/{lucid_variant_generation_service.js → persistence/lucid_variant_generation_service.js} +0 -0
  160. /package/build/src/integrations/lucid/{attachment_owner.d.ts → relations/attachment_owner.d.ts} +0 -0
  161. /package/build/src/integrations/lucid/{attachment_owner.js → relations/attachment_owner.js} +0 -0
  162. /package/build/src/integrations/lucid/{attachments_table_stub.d.ts → schema/attachments_table_stub.d.ts} +0 -0
@@ -5,7 +5,8 @@
5
5
  * @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
6
6
  */
7
7
  import { Database } from '@adonisjs/lucid/database';
8
- import { AttachmentModel } from '../../src/integrations/lucid/attachment_model.js';
8
+ import { AttachmentModel } from '../../src/integrations/lucid/models/attachment_model.js';
9
+ import { AttachmentLinkModel } from '../../src/integrations/lucid/models/attachment_link_model.js';
9
10
  export async function createLucidTestDatabase() {
10
11
  const database = new Database({
11
12
  connection: 'sqlite',
@@ -24,13 +25,9 @@ export async function createLucidTestDatabase() {
24
25
  },
25
26
  });
26
27
  AttachmentModel.useAdapter(database.modelAdapter());
28
+ AttachmentLinkModel.useAdapter(database.modelAdapter());
27
29
  await database.connection().schema.createTable('attachments', (table) => {
28
30
  table.string('id').primary();
29
- table.string('attachable_type').notNullable();
30
- table.string('attachable_id').notNullable();
31
- table.string('field').notNullable();
32
- table.string('owner_key', 64).nullable().unique();
33
- table.integer('position').unsigned().nullable();
34
31
  table.string('parent_id').nullable().references('id').inTable('attachments').onDelete('CASCADE');
35
32
  table.string('variant_key').nullable();
36
33
  table.string('disk').notNullable();
@@ -43,10 +40,22 @@ export async function createLucidTestDatabase() {
43
40
  table.json('metadata').nullable();
44
41
  table.timestamp('created_at').notNullable();
45
42
  table.timestamp('updated_at').notNullable();
46
- table.index(['attachable_type', 'attachable_id', 'field']);
47
43
  table.index(['parent_id']);
48
44
  table.unique(['parent_id', 'variant_key']);
49
45
  });
46
+ await database.connection().schema.createTable('attachment_links', (table) => {
47
+ table.string('id').primary();
48
+ table.string('attachable_type').notNullable();
49
+ table.string('attachable_id').notNullable();
50
+ table.string('field').notNullable();
51
+ table.string('owner_key', 64).nullable().unique();
52
+ table.integer('position').unsigned().nullable();
53
+ table.string('attachment_id').notNullable().references('id').inTable('attachments').onDelete('CASCADE');
54
+ table.timestamp('created_at').notNullable();
55
+ table.timestamp('updated_at').notNullable();
56
+ table.index(['attachable_type', 'attachable_id', 'field']);
57
+ table.index(['attachment_id']);
58
+ });
50
59
  return database;
51
60
  }
52
61
  //# sourceMappingURL=lucid_test_database.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"lucid_test_database.js","sourceRoot":"","sources":["../../../tests/helpers/lucid_test_database.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AAEnD,OAAO,EAAE,eAAe,EAAE,MAAM,kDAAkD,CAAA;AAElF,MAAM,CAAC,KAAK,UAAU,uBAAuB;IAC3C,MAAM,QAAQ,GAAG,IAAI,QAAQ,CAC3B;QACE,UAAU,EAAE,QAAQ;QACpB,WAAW,EAAE;YACX,MAAM,EAAE;gBACN,MAAM,EAAE,gBAAgB;gBACxB,UAAU,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE;gBACpC,gBAAgB,EAAE,IAAI;aACvB;SACF;KACF,EACD,EAAE,KAAK,KAAI,CAAC,EAAW,EACvB;QACE,KAAK,CAAC,IAAI,KAAI,CAAC;QACf,KAAK,CAAC,UAAU,KAAI,CAAC;QACrB,YAAY;YACV,OAAO,KAAK,CAAA;QACd,CAAC;KACO,CACX,CAAA;IAED,eAAe,CAAC,UAAU,CAAC,QAAQ,CAAC,YAAY,EAAE,CAAC,CAAA;IAEnD,MAAM,QAAQ,CAAC,UAAU,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,aAAa,EAAE,CAAC,KAAK,EAAE,EAAE;QACtE,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,CAAA;QAC5B,KAAK,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,WAAW,EAAE,CAAA;QAC7C,KAAK,CAAC,MAAM,CAAC,eAAe,CAAC,CAA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AC,OAAO,EAAE,CAAA;QAC5B,KAAK,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,WAAW,EAAE,CAAA;QAC7C,KAAK,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,WAAW,EAAE,CAAA;QAC3C,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,CAAA;QACnC,KAAK,CAAC,MAAM,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,CAAA;QACjD,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,CAAA;QAC/C,KAAK,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAA;QACvG,KAAK,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,WAAW,EAAE,CAAA;QAC3C,KAAK,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,WAAW,EAAE,CAAA;QAC3C,KAAK,CAAC,KAAK,CAAC,CAAC,iBAAiB,EAAE,eAAe,EAAE,OAAO,CAAC,CAAC,CAAA;QAC1D,KAAK,CAAC,KAAK,CAAC,CAAC,eAAe,CAAC,CAAC,CAAA;IAChC,CAAC,CAAC,CAAA;IAEF,OAAO,QAAQ,CAAA;AACjB,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @jrmc/adonis-attachment
3
+ *
4
+ * @license MIT
5
+ * @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
6
+ */
7
+ export {};
8
+ //# sourceMappingURL=legacy_attachment_migration_stub.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"legacy_attachment_migration_stub.spec.d.ts","sourceRoot":"","sources":["../../tests/legacy_attachment_migration_stub.spec.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * @jrmc/adonis-attachment
3
+ *
4
+ * @license MIT
5
+ * @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
6
+ */
7
+ import { readFile } from 'node:fs/promises';
8
+ import { join } from 'node:path';
9
+ import { test } from '@japa/runner';
10
+ import MakeAttachmentV5Migration from '../commands/make/attachment_v5_migration.js';
11
+ import { stubsRoot } from '../stubs/main.js';
12
+ import { createLegacyAttachmentMigrationStubState } from '../src/integrations/lucid/index.js';
13
+ test.group('legacy attachment migration stub', () => {
14
+ test('prepares a timestamped destination and template state', ({ assert }) => {
15
+ assert.deepEqual(createLegacyAttachmentMigrationStubState({
16
+ directory: '/app/database/scripts',
17
+ defaultDisk: 's3',
18
+ timestamp: 1700000000000,
19
+ }), {
20
+ destination: '/app/database/scripts/1700000000000_migrate_v5_attachments.ts',
21
+ defaultDisk: 's3',
22
+ });
23
+ });
24
+ test('uses a package stub for the generated data migration', async ({ assert }) => {
25
+ const stub = await readFile(join(stubsRoot, 'migrations/legacy_attachment_migration.stub'), 'utf8');
26
+ assert.include(stub, 'exports({ to: destination })');
27
+ assert.include(stub, "defaultDisk: '{{ defaultDisk }}'");
28
+ assert.include(stub, 'migrateLegacyAttachmentRecords');
29
+ assert.include(stub, 'AttachmentLinkModel.createMany(rows.links');
30
+ });
31
+ test('uses the package stub from the Ace command', async ({ assert }) => {
32
+ const generated = [];
33
+ const messages = [];
34
+ await MakeAttachmentV5Migration.prototype.run.call({
35
+ parsed: { flags: { disk: 's3', folder: 'database/scripts' } },
36
+ app: { makePath: (path) => `/app/${path}` },
37
+ async createCodemods() {
38
+ return {
39
+ async makeUsingStub(root, path, state) {
40
+ generated.push({ root, path, state });
41
+ },
42
+ };
43
+ },
44
+ logger: {
45
+ success(message) {
46
+ messages.push(message);
47
+ },
48
+ },
49
+ });
50
+ assert.equal(generated[0]?.root, stubsRoot);
51
+ assert.equal(generated[0]?.path, 'migrations/legacy_attachment_migration.stub');
52
+ assert.equal(generated[0]?.state.defaultDisk, 's3');
53
+ assert.match(String(generated[0]?.state.destination), /^\/app\/database\/scripts\/\d+_migrate_v5_attachments\.ts$/);
54
+ assert.match(messages[0] ?? '', /^Created \/app\/database\/scripts\//);
55
+ });
56
+ });
57
+ //# sourceMappingURL=legacy_attachment_migration_stub.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"legacy_attachment_migration_stub.spec.js","sourceRoot":"","sources":["../../tests/legacy_attachment_migration_stub.spec.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAEnC,OAAO,yBAAyB,MAAM,6CAA6C,CAAA;AACnF,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAC5C,OAAO,EAAE,wCAAwC,EAAE,MAAM,oCAAoC,CAAA;AAE7F,IAAI,CAAC,KAAK,CAAC,kCAAkC,EAAE,GAAG,EAAE;IAClD,IAAI,CAAC,uDAAuD,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE;QAC3E,MAAM,CAAC,SAAS,CACd,wCAAwC,CAAC;YACvC,SAAS,EAAE,uBAAuB;YAClC,WAAW,EAAE,IAAI;YACjB,SAAS,EAAE,aAAa;SACzB,CAAC,EACF;YACE,WAAW,EAAE,+DAA+D;YAC5E,WAAW,EAAE,IAAI;SAClB,CACF,CAAA;IACH,CAAC,CAAC,CAAA;IAEF,IAAI,CAAC,sDAAsD,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;QAChF,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,SAAS,EAAE,6CAA6C,CAAC,EAAE,MAAM,CAAC,CAAA;QAEnG,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,8BAA8B,CAAC,CAAA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AAE,IAAI,CAAC,CAAA;QACnD,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,WAAW,CAAC,EAAE,4DAA4D,CAAC,CAAA;QACnH,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,qCAAqC,CAAC,CAAA;IACxE,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -1,5 +1,5 @@
1
1
  import { test } from '@japa/runner';
2
- import { LucidAttachmentStore } from '../src/integrations/lucid/lucid_attachment_store.js';
2
+ import { LucidAttachmentStore } from '../src/integrations/lucid/persistence/lucid_attachment_store.js';
3
3
  import { createLucidTestDatabase } from './helpers/lucid_test_database.js';
4
4
  const owner = { type: 'users', id: 'user-1', field: 'avatars' };
5
5
  let database;
@@ -20,6 +20,7 @@ test.group('Lucid attachment collection store', (group) => {
20
20
  database = await createLucidTestDatabase();
21
21
  });
22
22
  group.each.setup(async () => {
23
+ await database.from('attachment_links').delete();
23
24
  await database.from('attachments').delete();
24
25
  });
25
26
  group.teardown(async () => {
@@ -30,20 +31,20 @@ test.group('Lucid attachment collection store', (group) => {
30
31
  const first = await store.createCollectionItem(owner, makeAttachment('first'));
31
32
  const third = await store.createCollectionItem(owner, makeAttachment('third'));
32
33
  const second = await store.createCollectionItem(owner, makeAttachment('second'), 1);
33
- assert.deepEqual((await store.listCollection(owner)).map((item) => [item.id, item.position]), [
34
+ assert.deepEqual((await store.listCollection(owner)).map((item) => [item.attachmentId, item.position]), [
34
35
  ['first', 0],
35
36
  ['second', 1],
36
37
  ['third', 2],
37
38
  ]);
38
39
  assert.isNull(await store.findOriginal(owner));
39
40
  await store.moveCollectionItem(owner, third.id, 0);
40
- assert.deepEqual((await store.listCollection(owner)).map((item) => [item.id, item.position]), [
41
+ assert.deepEqual((await store.listCollection(owner)).map((item) => [item.attachmentId, item.position]), [
41
42
  ['third', 0],
42
43
  ['first', 1],
43
44
  ['second', 2],
44
45
  ]);
45
46
  await store.removeCollectionItem(owner, first);
46
- assert.deepEqual((await store.listCollection(owner)).map((item) => [item.id, item.position]), [
47
+ assert.deepEqual((await store.listCollection(owner)).map((item) => [item.attachmentId, item.position]), [
47
48
  ['third', 0],
48
49
  ['second', 1],
49
50
  ]);
@@ -1 +1 @@
1
- {"version":3,"file":"lucid_attachment_collection_store.spec.js","sourceRoot":"","sources":["../../tests/lucid_attachment_collection_store.spec.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAGnC,OAAO,EAAE,oBAAoB,EAAE,MAAM,qDAAqD,CAAA;AAC1F,OAAO,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAA;AAE1E,MAAM,KAAK,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,CAAA;AAC/D,IAAI,QAAkB,CAAA;AAEtB,SAAS,cAAc,CAAC,EAAU;IAChC,OAAO;QACL,EAAE;QACF,IAAI,EAAE,IAAI;QACV,IAAI,EAAE,gBAAgB,EAAE,MAAM;QAC9B,IAAI,EAAE,GAAG,EAAE,MAAM;QACjB,YAAY,EAAE,GAAG,EAAE,MAAM;QACzB,QAAQ,EAAE,YAAY;QACtB,OAAO,EAAE,KAAK;QACd,IAAI,EAAE,EAAE;KACT,CAAA;AACH,CAAC;AAED,IAAI,CAAC,KAAK,CAAC,mCAAmC,EAAE,CAAC,KAAK,EAAE,EAAE;IACxD,KAAK,CAAC,KAAK,CAAC,KAAK,IAAI,EAAE;QACrB,QAAQ,GAAG,MAAM,uBAAuB,EAAE,CAAA;IAC5C,CAAC,CAAC,CAAA;IAEF,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,IAAI,EAAE;QAC1B,MAAM,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,MAAM,EAAE,CAAA;IAC7C,CAAC,CAAC,CAAA;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C,EAAE,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,EAC3E;YACE,CAAC,OAAO,EAAE,CAAC,CAAC;YACZ,CAAC,OAAO,EAAE,CAAC,CAAC;YACZ,CAAC,QAAQ,EAAE,CAAC,CAAC;SACd,CACF,CAAA;QAED,MAAM,KAAK,CAAC,oBAAoB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;QAE9C,MAAM,CAAC,SAAS,CACd,CAAC,MAAM,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,EAC3E;YACE,CAAC,OAAO,EAAE,CAAC,CAAC;YACZ,CAAC,QAAQ,EAAE,CAAC,CAAC;SACd,CACF,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
1
+ {"version":3,"file":"lucid_attachment_collection_store.spec.js","sourceRoot":"","sources":["../../tests/lucid_attachment_collection_store.spec.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAGnC,OAAO,EAAE,oBAAoB,EAAE,MAAM,iEAAiE,CAAA;AACtG,OAAO,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAA;AAE1E,MAAM,KAAK,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,CAAA;AAC/D,IAAI,QAAkB,CAAA;AAEtB,SAAS,cAAc,CAAC,EAAU;IAChC,OAAO;QACL,EAAE;QACF,IAAI,EAAE,IAAI;QACV,IAAI,EAAE,gBAAgB,EAAE,MAAM;QAC9B,IAAI,EAAE,GAAG,EAAE,MAAM;QACjB,YAAY,EAAE,GAAG,EAAE,MAAM;QACzB,QAAQ,EAAE,YAAY;QACtB,OAAO,EAAE,KAAK;QACd,IAAI,EAAE,EAAE;K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CAAC,OAAO,EAAE,CAAC,CAAC;YACZ,CAAC,QAAQ,EAAE,CAAC,CAAC;YACb,CAAC,OAAO,EAAE,CAAC,CAAC;SACb,CACF,CAAA;QACD,MAAM,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAA;QAE9C,MAAM,KAAK,CAAC,kBAAkB,CAAC,KAAK,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA;QAElD,MAAM,CAAC,SAAS,CACd,CAAC,MAAM,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,EACrF;YACE,CAAC,OAAO,EAAE,CAAC,CAAC;YACZ,CAAC,OAAO,EAAE,CAAC,CAAC;YACZ,CAAC,QAAQ,EAAE,CAAC,CAAC;SACd,CACF,CAAA;QAED,MAAM,KAAK,CAAC,oBAAoB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;QAE9C,MAAM,CAAC,SAAS,CACd,CAAC,MAAM,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,EACrF;YACE,CAAC,OAAO,EAAE,CAAC,CAAC;YACZ,CAAC,QAAQ,EAAE,CAAC,CAAC;SACd,CACF,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -6,7 +6,7 @@
6
6
  */
7
7
  import { test } from '@japa/runner';
8
8
  import { AttachmentService } from '../src/core/attachment_service.js';
9
- import { LucidAttachmentLifecycleService } from '../src/integrations/lucid/lucid_attachment_lifecycle_service.js';
9
+ import { LucidAttachmentLifecycleService } from '../src/integrations/lucid/persistence/lucid_attachment_lifecycle_service.js';
10
10
  const attachment = {
11
11
  id: 'attachment-id',
12
12
  disk: 'public',
@@ -17,20 +17,66 @@ const attachment = {
17
17
  extname: 'jpg',
18
18
  size: 42,
19
19
  };
20
- function makeRow(value, id = value.id) {
20
+ function makeBlob(value) {
21
+ return {
22
+ id: value.id,
23
+ toAttachment() {
24
+ return value;
25
+ },
26
+ };
27
+ }
28
+ function makeLink(value, id = `link-${value.id}`) {
29
+ const blob = makeBlob(value);
21
30
  return {
22
31
  id,
32
+ attachmentId: value.id,
33
+ attachment: blob,
23
34
  toAttachment() {
24
35
  return value;
25
36
  },
26
37
  };
27
38
  }
39
+ function makeStore(overrides = {}) {
40
+ const link = makeLink(attachment);
41
+ return {
42
+ async createOriginal() {
43
+ return link;
44
+ },
45
+ async findOriginal() {
46
+ return null;
47
+ },
48
+ async listVariants() {
49
+ return [];
50
+ },
51
+ async releaseOwner() { },
52
+ async restoreOwner() { },
53
+ async remove() {
54
+ return [];
55
+ },
56
+ async createCollectionItem() {
57
+ return link;
58
+ },
59
+ async findCollectionItem() {
60
+ return null;
61
+ },
62
+ async listCollection() {
63
+ return [];
64
+ },
65
+ async moveCollectionItem() {
66
+ return [];
67
+ },
68
+ async removeCollectionItem() {
69
+ return [];
70
+ },
71
+ ...overrides,
72
+ };
73
+ }
28
74
  test.group('LucidAttachmentLifecycleService', () => {
29
- test('persists a manager draft before inserting its polymorphic row', async ({ assert }) => {
75
+ test('persists a manager draft before creating its polymorphic link', async ({ assert }) => {
30
76
  const events = [];
31
77
  const attachments = new AttachmentService({
32
78
  defaultDisk: 'fs',
33
- createId: () => 'attachment-id',
79
+ createId: () => attachment.id,
34
80
  queue: { async enqueue() { } },
35
81
  storage: {
36
82
  async write() {
@@ -42,60 +88,18 @@ test.group('LucidAttachmentLifecycleService', () => {
42
88
  async remove() { },
43
89
  },
44
90
  });
45
- const draft = attachments.createDraft({
46
- body: new Uint8Array([1]),
47
- originalName: 'profile.jpg',
48
- });
49
- const service = new LucidAttachmentLifecycleService(attachments, {
91
+ const draft = attachments.createDraft({ body: new Uint8Array([1]), originalName: 'profile.jpg' });
92
+ const service = new LucidAttachmentLifecycleService(attachments, makeStore({
50
93
  async createOriginal() {
51
- events.push('persist');
52
- return {};
53
- },
54
- async findOriginal() {
55
- return null;
56
- },
57
- async listVariants() {
58
- return [];
94
+ events.push('link');
95
+ return makeLink(attachment);
59
96
  },
60
- async releaseOwner() { },
61
- async restoreOwner() { },
62
- async remove() { },
63
- });
64
- assert.isFalse(draft.isPersisted);
97
+ }));
65
98
  await service.attach({ type: 'users', id: '42', field: 'avatar' }, draft);
66
99
  assert.isTrue(draft.isPersisted);
67
- assert.deepEqual(events, ['write', 'persist']);
68
- });
69
- test('persists the file before creating its polymorphic row', async ({ assert }) => {
70
- const events = [];
71
- const service = new LucidAttachmentLifecycleService({
72
- async create() {
73
- events.push('write');
74
- return attachment;
75
- },
76
- async remove() { },
77
- }, {
78
- async createOriginal() {
79
- events.push('persist');
80
- return {};
81
- },
82
- async findOriginal() {
83
- return null;
84
- },
85
- async listVariants() {
86
- return [];
87
- },
88
- async releaseOwner() { },
89
- async restoreOwner() { },
90
- async remove() { },
91
- });
92
- await service.attach({ type: 'users', id: '42', field: 'avatar' }, {
93
- body: new Uint8Array(),
94
- originalName: 'profile.jpg',
95
- });
96
- assert.deepEqual(events, ['write', 'persist']);
100
+ assert.deepEqual(events, ['write', 'link']);
97
101
  });
98
- test('removes a new file when database persistence fails', async ({ assert }) => {
102
+ test('removes a new file when blob or link persistence fails', async ({ assert }) => {
99
103
  const removed = [];
100
104
  const service = new LucidAttachmentLifecycleService({
101
105
  async create() {
@@ -104,275 +108,105 @@ test.group('LucidAttachmentLifecycleService', () => {
104
108
  async remove(value) {
105
109
  removed.push(value);
106
110
  },
107
- }, {
111
+ }, makeStore({
108
112
  async createOriginal() {
109
113
  throw new Error('database unavailable');
110
114
  },
111
- async findOriginal() {
112
- return null;
113
- },
114
- async listVariants() {
115
- return [];
116
- },
117
- async releaseOwner() { },
118
- async restoreOwner() { },
119
- async remove() { },
120
- });
115
+ }));
121
116
  await assert.rejects(() => service.attach({ type: 'users', id: '42', field: 'avatar' }, {
122
117
  body: new Uint8Array(),
123
118
  originalName: 'profile.jpg',
124
119
  }), 'database unavailable');
125
120
  assert.deepEqual(removed, [attachment]);
126
121
  });
127
- test('replaces the persisted row before removing the previous file', async ({ assert }) => {
122
+ test('replaces a link before purging its unreferenced blob', async ({ assert }) => {
128
123
  const events = [];
129
124
  const previousAttachment = { ...attachment, id: 'previous-id', path: 'users/42/previous.jpg' };
130
125
  const currentAttachment = { ...attachment, id: 'current-id', path: 'users/42/current.jpg' };
131
- const previous = makeRow(previousAttachment);
132
- const current = makeRow(currentAttachment);
126
+ const previous = makeLink(previousAttachment);
127
+ const current = makeLink(currentAttachment);
133
128
  const service = new LucidAttachmentLifecycleService({
134
129
  async create() {
135
- events.push('write-current');
130
+ events.push('write');
136
131
  return currentAttachment;
137
132
  },
138
133
  async remove(value) {
139
134
  events.push(`remove-file:${value.id}`);
140
135
  },
141
- }, {
136
+ }, makeStore({
142
137
  async createOriginal() {
143
- events.push('persist-current');
138
+ events.push('create-link');
144
139
  return current;
145
140
  },
146
141
  async findOriginal() {
147
142
  return previous;
148
143
  },
149
- async listVariants() {
150
- return [];
151
- },
152
144
  async releaseOwner() {
153
- events.push('release-previous');
145
+ events.push('release-link');
154
146
  },
155
- async restoreOwner() { },
156
- async remove(row) {
157
- events.push(`remove-row:${row.id}`);
147
+ async remove() {
148
+ events.push('remove-link');
149
+ return [makeBlob(previousAttachment)];
158
150
  },
159
- });
160
- const row = await service.replace({ type: 'users', id: '42', field: 'avatar' }, {
151
+ }));
152
+ await service.replace({ type: 'users', id: '42', field: 'avatar' }, {
161
153
  body: new Uint8Array(),
162
154
  originalName: 'profile.jpg',
163
155
  });
164
- assert.equal(row, current);
165
156
  assert.deepEqual(events, [
166
- 'write-current',
167
- 'release-previous',
168
- 'persist-current',
169
- 'remove-row:previous-id',
157
+ 'write',
158
+ 'release-link',
159
+ 'create-link',
160
+ 'remove-link',
170
161
  'remove-file:previous-id',
171
162
  ]);
172
163
  });
173
- test('restores the previous owner when replacement persistence fails', async ({ assert }) => {
174
- const events = [];
175
- const previous = makeRow(attachment, 'previous-id');
176
- const currentAttachment = { ...attachment, id: 'current-id', path: 'users/42/current.jpg' };
177
- const service = new LucidAttachmentLifecycleService({
178
- async create() {
179
- events.push('write-current');
180
- return currentAttachment;
181
- },
182
- async remove(value) {
183
- events.push(`remove-file:${value.id}`);
184
- },
185
- }, {
186
- async createOriginal() {
187
- throw new Error('database unavailable');
188
- },
189
- async findOriginal() {
190
- return previous;
191
- },
192
- async listVariants() {
193
- return [];
194
- },
195
- async releaseOwner() {
196
- events.push('release-previous');
197
- },
198
- async restoreOwner() {
199
- events.push('restore-previous');
200
- },
201
- async remove() { },
202
- });
203
- await assert.rejects(() => service.replace({ type: 'users', id: '42', field: 'avatar' }, {
204
- body: new Uint8Array(),
205
- originalName: 'profile.jpg',
206
- }), 'database unavailable');
207
- assert.deepEqual(events, [
208
- 'write-current',
209
- 'release-previous',
210
- 'restore-previous',
211
- 'remove-file:current-id',
212
- ]);
213
- });
214
- test('detaches the original and every persisted variant', async ({ assert }) => {
215
- const removedRows = [];
216
- const removedFiles = [];
217
- const original = makeRow(attachment);
218
- const variant = makeRow({ ...attachment, id: 'variant-id', path: 'users/42/thumbnail.webp' });
219
- const service = new LucidAttachmentLifecycleService({
220
- async create() {
221
- return attachment;
222
- },
223
- async remove(value) {
224
- removedFiles.push(value.id);
225
- },
226
- }, {
227
- async createOriginal() {
228
- return original;
229
- },
230
- async findOriginal() {
231
- return original;
232
- },
233
- async listVariants() {
234
- return [variant];
235
- },
236
- async releaseOwner() { },
237
- async restoreOwner() { },
238
- async remove(row) {
239
- removedRows.push(row.id);
240
- },
241
- });
242
- await service.detach({ type: 'users', id: '42', field: 'avatar' });
243
- assert.deepEqual(removedRows, ['attachment-id']);
244
- assert.sameDeepMembers(removedFiles, ['attachment-id', 'variant-id']);
245
- });
246
- test('persists a collection item before inserting its polymorphic row', async ({ assert }) => {
247
- const events = [];
248
- const item = makeRow(attachment);
249
- const service = new LucidAttachmentLifecycleService({
250
- async create() {
251
- events.push('write');
252
- return attachment;
253
- },
254
- async remove() { },
255
- }, {
256
- async createOriginal() {
257
- return item;
258
- },
259
- async findOriginal() {
260
- return null;
261
- },
262
- async listVariants() {
263
- return [];
264
- },
265
- async releaseOwner() { },
266
- async restoreOwner() { },
267
- async remove() { },
268
- async createCollectionItem() {
269
- events.push('persist');
270
- return item;
271
- },
272
- async findCollectionItem() {
273
- return null;
274
- },
275
- async listCollection() {
276
- return [];
277
- },
278
- async moveCollectionItem() {
279
- return [];
280
- },
281
- async removeCollectionItem() { },
282
- });
283
- await service.add({ type: 'users', id: '42', field: 'avatars' }, {
284
- body: new Uint8Array(),
285
- originalName: 'profile.jpg',
286
- });
287
- assert.deepEqual(events, ['write', 'persist']);
288
- });
289
- test('removes a collection file when its database insertion fails', async ({ assert }) => {
164
+ test('only removes files for blobs that became unreferenced', async ({ assert }) => {
290
165
  const removed = [];
291
166
  const service = new LucidAttachmentLifecycleService({
292
167
  async create() {
293
168
  return attachment;
294
169
  },
295
170
  async remove(value) {
296
- removed.push(value);
297
- },
298
- }, {
299
- async createOriginal() {
300
- return makeRow(attachment);
171
+ removed.push(value.id);
301
172
  },
173
+ }, makeStore({
302
174
  async findOriginal() {
303
- return null;
304
- },
305
- async listVariants() {
306
- return [];
307
- },
308
- async releaseOwner() { },
309
- async restoreOwner() { },
310
- async remove() { },
311
- async createCollectionItem() {
312
- throw new Error('database unavailable');
313
- },
314
- async findCollectionItem() {
315
- return null;
175
+ return makeLink(attachment);
316
176
  },
317
- async listCollection() {
177
+ async remove() {
318
178
  return [];
319
179
  },
320
- async moveCollectionItem() {
321
- return [];
322
- },
323
- async removeCollectionItem() { },
324
- });
325
- await assert.rejects(() => service.add({ type: 'users', id: '42', field: 'avatars' }, {
326
- body: new Uint8Array(),
327
- originalName: 'profile.jpg',
328
- }), 'database unavailable');
329
- assert.deepEqual(removed, [attachment]);
180
+ }));
181
+ await service.detach({ type: 'users', id: '42', field: 'avatar' });
182
+ assert.deepEqual(removed, []);
330
183
  });
331
- test('removes a collection item and its persisted variants', async ({ assert }) => {
332
- const removedRows = [];
333
- const removedFiles = [];
334
- const item = makeRow(attachment);
335
- const variant = makeRow({ ...attachment, id: 'variant-id', path: 'users/42/thumbnail.webp' });
184
+ test('adds and removes ordered collection links', async ({ assert }) => {
185
+ const item = makeLink(attachment);
186
+ const removed = [];
336
187
  const service = new LucidAttachmentLifecycleService({
337
188
  async create() {
338
189
  return attachment;
339
190
  },
340
191
  async remove(value) {
341
- removedFiles.push(value.id);
192
+ removed.push(value.id);
342
193
  },
343
- }, {
344
- async createOriginal() {
345
- return item;
346
- },
347
- async findOriginal() {
348
- return null;
349
- },
350
- async listVariants() {
351
- return [variant];
352
- },
353
- async releaseOwner() { },
354
- async restoreOwner() { },
355
- async remove() { },
194
+ }, makeStore({
356
195
  async createCollectionItem() {
357
196
  return item;
358
197
  },
359
198
  async findCollectionItem() {
360
199
  return item;
361
200
  },
362
- async listCollection() {
363
- return [item];
364
- },
365
- async moveCollectionItem() {
366
- return [item];
201
+ async removeCollectionItem() {
202
+ return [makeBlob(attachment)];
367
203
  },
368
- async removeCollectionItem(_owner, row) {
369
- removedRows.push(row.id);
370
- },
371
- });
372
- const removed = await service.removeCollectionItem({ type: 'users', id: '42', field: 'avatars' }, attachment.id);
373
- assert.isTrue(removed);
374
- assert.deepEqual(removedRows, ['attachment-id']);
375
- assert.sameDeepMembers(removedFiles, ['attachment-id', 'variant-id']);
204
+ }));
205
+ const added = await service.add({ type: 'users', id: '42', field: 'gallery' }, { body: new Uint8Array(), originalName: 'profile.jpg' });
206
+ const didRemove = await service.removeCollectionItem({ type: 'users', id: '42', field: 'gallery' }, added.id);
207
+ assert.equal(added.id, item.id);
208
+ assert.isTrue(didRemove);
209
+ assert.deepEqual(removed, [attachment.id]);
376
210
  });
377
211
  });
378
212
  //# sourceMappingURL=lucid_attachment_lifecycle_service.spec.js.map