@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.
- package/build/commands/make/attachment_v5_migration.d.ts.map +1 -1
- package/build/commands/make/attachment_v5_migration.js +6 -3
- package/build/commands/make/attachment_v5_migration.js.map +1 -1
- package/build/commands/make/attachments_table.d.ts.map +1 -1
- package/build/commands/make/attachments_table.js +8 -2
- package/build/commands/make/attachments_table.js.map +1 -1
- package/build/index.d.ts +6 -6
- package/build/index.d.ts.map +1 -1
- package/build/index.js +5 -5
- package/build/index.js.map +1 -1
- package/build/providers/attachment_provider.d.ts.map +1 -1
- package/build/providers/attachment_provider.js +16 -0
- package/build/providers/attachment_provider.js.map +1 -1
- package/build/src/define_config.d.ts +13 -0
- package/build/src/define_config.d.ts.map +1 -1
- package/build/src/define_config.js +8 -0
- package/build/src/define_config.js.map +1 -1
- package/build/src/integrations/lucid/{attachment_column.d.ts → column/attachment_column.d.ts} +2 -2
- package/build/src/integrations/lucid/column/attachment_column.d.ts.map +1 -0
- package/build/src/integrations/lucid/{attachment_column.js → column/attachment_column.js} +2 -2
- package/build/src/integrations/lucid/column/attachment_column.js.map +1 -0
- package/build/src/integrations/lucid/index.d.ts +16 -13
- package/build/src/integrations/lucid/index.d.ts.map +1 -1
- package/build/src/integrations/lucid/index.js +16 -13
- package/build/src/integrations/lucid/index.js.map +1 -1
- package/build/src/integrations/lucid/migrations/legacy/legacy_attachment_migration_stub.d.ts +20 -0
- package/build/src/integrations/lucid/migrations/legacy/legacy_attachment_migration_stub.d.ts.map +1 -0
- package/build/src/integrations/lucid/migrations/legacy/legacy_attachment_migration_stub.js +18 -0
- package/build/src/integrations/lucid/migrations/legacy/legacy_attachment_migration_stub.js.map +1 -0
- package/build/src/integrations/lucid/{migrate_legacy_attachment.d.ts → migrations/legacy/migrate_legacy_attachment.d.ts} +19 -10
- package/build/src/integrations/lucid/migrations/legacy/migrate_legacy_attachment.d.ts.map +1 -0
- package/build/src/integrations/lucid/{migrate_legacy_attachment.js → migrations/legacy/migrate_legacy_attachment.js} +28 -23
- package/build/src/integrations/lucid/migrations/legacy/migrate_legacy_attachment.js.map +1 -0
- package/build/src/integrations/lucid/{migrate_legacy_attachment_records.d.ts → migrations/legacy/migrate_legacy_attachment_records.d.ts} +3 -3
- package/build/src/integrations/lucid/migrations/legacy/migrate_legacy_attachment_records.d.ts.map +1 -0
- package/build/src/integrations/lucid/{migrate_legacy_attachment_records.js → migrations/legacy/migrate_legacy_attachment_records.js} +7 -6
- package/build/src/integrations/lucid/migrations/legacy/migrate_legacy_attachment_records.js.map +1 -0
- package/build/src/integrations/lucid/models/attachment_link_model.d.ts +30 -0
- package/build/src/integrations/lucid/models/attachment_link_model.d.ts.map +1 -0
- package/build/src/integrations/lucid/models/attachment_link_model.js +58 -0
- package/build/src/integrations/lucid/models/attachment_link_model.js.map +1 -0
- package/build/src/integrations/lucid/{attachment_model.d.ts → models/attachment_model.d.ts} +2 -7
- package/build/src/integrations/lucid/models/attachment_model.d.ts.map +1 -0
- package/build/src/integrations/lucid/{attachment_model.js → models/attachment_model.js} +1 -16
- package/build/src/integrations/lucid/models/attachment_model.js.map +1 -0
- package/build/src/integrations/lucid/{lucid_attachment_lifecycle_service.d.ts → persistence/lucid_attachment_lifecycle_service.d.ts} +17 -13
- package/build/src/integrations/lucid/persistence/lucid_attachment_lifecycle_service.d.ts.map +1 -0
- package/build/src/integrations/lucid/{lucid_attachment_lifecycle_service.js → persistence/lucid_attachment_lifecycle_service.js} +27 -20
- package/build/src/integrations/lucid/persistence/lucid_attachment_lifecycle_service.js.map +1 -0
- package/build/src/integrations/lucid/{lucid_attachment_repository.d.ts → persistence/lucid_attachment_repository.d.ts} +3 -3
- package/build/src/integrations/lucid/persistence/lucid_attachment_repository.d.ts.map +1 -0
- package/build/src/integrations/lucid/{lucid_attachment_repository.js → persistence/lucid_attachment_repository.js} +1 -1
- package/build/src/integrations/lucid/persistence/lucid_attachment_repository.js.map +1 -0
- package/build/src/integrations/lucid/persistence/lucid_attachment_store.d.ts +48 -0
- package/build/src/integrations/lucid/persistence/lucid_attachment_store.d.ts.map +1 -0
- package/build/src/integrations/lucid/persistence/lucid_attachment_store.js +224 -0
- package/build/src/integrations/lucid/persistence/lucid_attachment_store.js.map +1 -0
- package/build/src/integrations/lucid/{lucid_variant_generation_service.d.ts → persistence/lucid_variant_generation_service.d.ts} +3 -3
- package/build/src/integrations/lucid/persistence/lucid_variant_generation_service.d.ts.map +1 -0
- package/build/src/integrations/lucid/persistence/lucid_variant_generation_service.js.map +1 -0
- package/build/src/integrations/lucid/relations/attachment_owner.d.ts.map +1 -0
- package/build/src/integrations/lucid/relations/attachment_owner.js.map +1 -0
- package/build/src/integrations/lucid/{attachment_relation.d.ts → relations/attachment_relation.d.ts} +25 -14
- package/build/src/integrations/lucid/relations/attachment_relation.d.ts.map +1 -0
- package/build/src/integrations/lucid/relations/attachment_relation.js +266 -0
- package/build/src/integrations/lucid/relations/attachment_relation.js.map +1 -0
- package/build/src/integrations/lucid/schema/attachment_schema_service.d.ts +24 -0
- package/build/src/integrations/lucid/schema/attachment_schema_service.d.ts.map +1 -0
- package/build/src/integrations/lucid/schema/attachment_schema_service.js +68 -0
- package/build/src/integrations/lucid/schema/attachment_schema_service.js.map +1 -0
- package/build/src/integrations/lucid/schema/attachment_table_names.d.ts +15 -0
- package/build/src/integrations/lucid/schema/attachment_table_names.d.ts.map +1 -0
- package/build/src/integrations/lucid/schema/attachment_table_names.js +20 -0
- package/build/src/integrations/lucid/schema/attachment_table_names.js.map +1 -0
- package/build/src/integrations/lucid/schema/attachments_table_stub.d.ts.map +1 -0
- package/build/src/integrations/lucid/{attachments_table_stub.js → schema/attachments_table_stub.js} +2 -4
- package/build/src/integrations/lucid/schema/attachments_table_stub.js.map +1 -0
- package/build/src/integrations/lucid/schema/configure_lucid_attachment_tables.d.ts +12 -0
- package/build/src/integrations/lucid/schema/configure_lucid_attachment_tables.d.ts.map +1 -0
- package/build/src/integrations/lucid/schema/configure_lucid_attachment_tables.js +19 -0
- package/build/src/integrations/lucid/schema/configure_lucid_attachment_tables.js.map +1 -0
- package/build/stubs/migrations/attachments_table.stub +7 -25
- package/build/{src/integrations/lucid/render_legacy_attachment_migration_script.js → stubs/migrations/legacy_attachment_migration.stub} +13 -15
- package/build/tests/attachment_provider.spec.js +30 -1
- package/build/tests/attachment_provider.spec.js.map +1 -1
- package/build/tests/{create_legacy_attachment_migration_script.spec.d.ts → attachment_schema_service.spec.d.ts} +1 -1
- package/build/tests/attachment_schema_service.spec.d.ts.map +1 -0
- package/build/tests/attachment_schema_service.spec.js +38 -0
- package/build/tests/attachment_schema_service.spec.js.map +1 -0
- package/build/tests/attachment_table_names.spec.d.ts +8 -0
- package/build/tests/attachment_table_names.spec.d.ts.map +1 -0
- package/build/tests/attachment_table_names.spec.js +36 -0
- package/build/tests/attachment_table_names.spec.js.map +1 -0
- package/build/tests/attachments_table_stub.spec.js +41 -6
- package/build/tests/attachments_table_stub.spec.js.map +1 -1
- package/build/tests/define_config.spec.js +22 -0
- package/build/tests/define_config.spec.js.map +1 -1
- package/build/tests/helpers/lucid_test_database.d.ts.map +1 -1
- package/build/tests/helpers/lucid_test_database.js +16 -7
- package/build/tests/helpers/lucid_test_database.js.map +1 -1
- package/build/tests/legacy_attachment_migration_stub.spec.d.ts +8 -0
- package/build/tests/legacy_attachment_migration_stub.spec.d.ts.map +1 -0
- package/build/tests/legacy_attachment_migration_stub.spec.js +57 -0
- package/build/tests/legacy_attachment_migration_stub.spec.js.map +1 -0
- package/build/tests/lucid_attachment_collection_store.spec.js +5 -4
- package/build/tests/lucid_attachment_collection_store.spec.js.map +1 -1
- package/build/tests/lucid_attachment_lifecycle_service.spec.js +96 -262
- package/build/tests/lucid_attachment_lifecycle_service.spec.js.map +1 -1
- package/build/tests/lucid_attachment_relation.spec.js +103 -24
- package/build/tests/lucid_attachment_relation.spec.js.map +1 -1
- package/build/tests/lucid_attachment_repository.spec.js +1 -1
- package/build/tests/lucid_attachment_repository.spec.js.map +1 -1
- package/build/tests/lucid_attachment_store.spec.js +24 -52
- package/build/tests/lucid_attachment_store.spec.js.map +1 -1
- package/build/tests/lucid_sqlite_integration.spec.js +23 -18
- package/build/tests/lucid_sqlite_integration.spec.js.map +1 -1
- package/build/tests/lucid_variant_generation_service.spec.js +1 -1
- package/build/tests/lucid_variant_generation_service.spec.js.map +1 -1
- package/build/tests/migrate_legacy_attachment.spec.js +48 -43
- package/build/tests/migrate_legacy_attachment.spec.js.map +1 -1
- package/build/tests/migrate_legacy_attachment_records.spec.js +4 -3
- package/build/tests/migrate_legacy_attachment_records.spec.js.map +1 -1
- package/package.json +1 -1
- package/build/src/integrations/lucid/attachment_column.d.ts.map +0 -1
- package/build/src/integrations/lucid/attachment_column.js.map +0 -1
- package/build/src/integrations/lucid/attachment_model.d.ts.map +0 -1
- package/build/src/integrations/lucid/attachment_model.js.map +0 -1
- package/build/src/integrations/lucid/attachment_owner.d.ts.map +0 -1
- package/build/src/integrations/lucid/attachment_owner.js.map +0 -1
- package/build/src/integrations/lucid/attachment_relation.d.ts.map +0 -1
- package/build/src/integrations/lucid/attachment_relation.js +0 -163
- package/build/src/integrations/lucid/attachment_relation.js.map +0 -1
- package/build/src/integrations/lucid/attachments_table_stub.d.ts.map +0 -1
- package/build/src/integrations/lucid/attachments_table_stub.js.map +0 -1
- package/build/src/integrations/lucid/create_legacy_attachment_migration_script.d.ts +0 -13
- package/build/src/integrations/lucid/create_legacy_attachment_migration_script.d.ts.map +0 -1
- package/build/src/integrations/lucid/create_legacy_attachment_migration_script.js +0 -20
- package/build/src/integrations/lucid/create_legacy_attachment_migration_script.js.map +0 -1
- package/build/src/integrations/lucid/lucid_attachment_lifecycle_service.d.ts.map +0 -1
- package/build/src/integrations/lucid/lucid_attachment_lifecycle_service.js.map +0 -1
- package/build/src/integrations/lucid/lucid_attachment_repository.d.ts.map +0 -1
- package/build/src/integrations/lucid/lucid_attachment_repository.js.map +0 -1
- package/build/src/integrations/lucid/lucid_attachment_store.d.ts +0 -36
- package/build/src/integrations/lucid/lucid_attachment_store.d.ts.map +0 -1
- package/build/src/integrations/lucid/lucid_attachment_store.js +0 -179
- package/build/src/integrations/lucid/lucid_attachment_store.js.map +0 -1
- package/build/src/integrations/lucid/lucid_variant_generation_service.d.ts.map +0 -1
- package/build/src/integrations/lucid/lucid_variant_generation_service.js.map +0 -1
- package/build/src/integrations/lucid/migrate_legacy_attachment.d.ts.map +0 -1
- package/build/src/integrations/lucid/migrate_legacy_attachment.js.map +0 -1
- package/build/src/integrations/lucid/migrate_legacy_attachment_records.d.ts.map +0 -1
- package/build/src/integrations/lucid/migrate_legacy_attachment_records.js.map +0 -1
- package/build/src/integrations/lucid/render_legacy_attachment_migration_script.d.ts +0 -11
- package/build/src/integrations/lucid/render_legacy_attachment_migration_script.d.ts.map +0 -1
- package/build/src/integrations/lucid/render_legacy_attachment_migration_script.js.map +0 -1
- package/build/tests/create_legacy_attachment_migration_script.spec.d.ts.map +0 -1
- package/build/tests/create_legacy_attachment_migration_script.spec.js +0 -31
- package/build/tests/create_legacy_attachment_migration_script.spec.js.map +0 -1
- /package/build/src/integrations/lucid/{lucid_variant_generation_service.js → persistence/lucid_variant_generation_service.js} +0 -0
- /package/build/src/integrations/lucid/{attachment_owner.d.ts → relations/attachment_owner.d.ts} +0 -0
- /package/build/src/integrations/lucid/{attachment_owner.js → relations/attachment_owner.js} +0 -0
- /package/build/src/integrations/lucid/{attachments_table_stub.d.ts → schema/attachments_table_stub.d.ts} +0 -0
|
@@ -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,EAAE,wBAAwB,EAAwB,MAAM,kCAAkC,CAAA;AACjG,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAA;AACxE,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAa/D;;GAEG;AACH,MAAM,OAAO,oBAAoB;IACtB,UAAU,CAAwB;IAClC,UAAU,CAA4B;IACtC,OAAO,CA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I,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 '
|
|
8
|
-
import type { VariantGenerationRequest, VariantGenerator } from '
|
|
9
|
-
import type { VariantGenerationService } from '
|
|
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;IACzD,YAAY,CAAmC;IAC/C,MAAM,CAA0D;IAEzE,YAAY,OAA6C;QACvD,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,SAAS,CAAA;QACnC,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,WAAW,CA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;;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"}
|
package/build/src/integrations/lucid/{attachment_relation.d.ts → relations/attachment_relation.d.ts}
RENAMED
|
@@ -5,9 +5,10 @@
|
|
|
5
5
|
* @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
|
|
6
6
|
*/
|
|
7
7
|
import type { LucidRow } from "@adonisjs/lucid/types/model";
|
|
8
|
-
import type { AttachmentDraft, CreateAttachmentInput } from "
|
|
9
|
-
import type { AttachmentPersistenceOptions } from "
|
|
10
|
-
import {
|
|
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";
|
|
11
12
|
type AttachmentRelationInput = CreateAttachmentInput | AttachmentDraft;
|
|
12
13
|
type AttachmentRelationRow = LucidRow & {
|
|
13
14
|
$isPersisted: boolean;
|
|
@@ -16,6 +17,10 @@ type AttachmentRelationRow = LucidRow & {
|
|
|
16
17
|
table?: string;
|
|
17
18
|
name: string;
|
|
18
19
|
boot(): void;
|
|
20
|
+
prototype: AttachmentRelationRow & {
|
|
21
|
+
save(): Promise<unknown>;
|
|
22
|
+
};
|
|
23
|
+
after(event: "delete", callback: (row: AttachmentRelationRow) => void | Promise<void>): void;
|
|
19
24
|
};
|
|
20
25
|
};
|
|
21
26
|
type RelationKind = "one" | "many";
|
|
@@ -38,23 +43,29 @@ export declare function attachmentsRelation<Model = LucidRow>(options?: Attachme
|
|
|
38
43
|
export declare class AttachmentRelation {
|
|
39
44
|
#private;
|
|
40
45
|
constructor(row: AttachmentRelationRow, definition: RelationDefinition);
|
|
41
|
-
get(): Promise<
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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>;
|
|
46
54
|
variants(): Promise<AttachmentModel[]>;
|
|
47
55
|
regenerateVariants(variantKeys?: readonly string[]): Promise<boolean>;
|
|
48
56
|
}
|
|
49
57
|
export declare class AttachmentCollectionRelation {
|
|
50
58
|
#private;
|
|
51
59
|
constructor(row: AttachmentRelationRow, definition: RelationDefinition);
|
|
52
|
-
all(): Promise<
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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[]>;
|
|
58
69
|
}
|
|
59
70
|
export {};
|
|
60
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,EAAE,QAAQ,EACf,QAAQ,EAAE,CAAC,GAAG,EAAE,qBAAqB,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,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;CA4B5E;AAED,qBAAa,4BAA4B;;gBAK3B,GAAG,EAAE,qBAAqB,EAAE,UAAU,EAAE,kBAAkB;IAKhE,GAAG,IAAI,OAAO,CAAC,mBAAmB,EAAE,CAAC;IAK3C,IAAI,UAAU,IAAI,OAAO,CAExB;IAED,GAAG,CACD,KAAK,EAAE,uBAAuB,EAC9B,QAAQ,CAAC,EAAE,MAAM,GAChB,IAAI;IAIP,WAAW,CACT,YAAY,EAAE,MAAM,EACpB,QAAQ,CAAC,EAAE,MAAM,GAChB,IAAI;IAQP,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAIxB,KAAK,IAAI,IAAI;IAIb,UAAU,CACR,MAAM,EAAE,SAAS,uBAAuB,EAAE,GACzC,IAAI;IAIP,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI;IAIlC,OAAO,IAAI,OAAO,CAAC,mBAAmB,EAAE,CAAC;CAmDhD"}
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jrmc/adonis-attachment
|
|
3
|
+
*
|
|
4
|
+
* @license MIT
|
|
5
|
+
* @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
|
|
6
|
+
*/
|
|
7
|
+
import app from "@adonisjs/core/services/app";
|
|
8
|
+
import { AttachmentModel } from "../models/attachment_model.js";
|
|
9
|
+
import { LucidAttachmentLifecycleService } from "../persistence/lucid_attachment_lifecycle_service.js";
|
|
10
|
+
import { LucidAttachmentStore } from "../persistence/lucid_attachment_store.js";
|
|
11
|
+
const relationDefinitions = new WeakMap();
|
|
12
|
+
const relationInstances = new WeakMap();
|
|
13
|
+
const deleteHooks = new WeakSet();
|
|
14
|
+
const saveHooks = new WeakSet();
|
|
15
|
+
/**
|
|
16
|
+
* Declares one attachment persisted in the polymorphic attachments table.
|
|
17
|
+
*/
|
|
18
|
+
export function attachmentRelation(options = {}) {
|
|
19
|
+
return defineRelation("one", options);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Declares an ordered attachment collection persisted in the polymorphic attachments table.
|
|
23
|
+
*/
|
|
24
|
+
export function attachmentsRelation(options = {}) {
|
|
25
|
+
return defineRelation("many", options);
|
|
26
|
+
}
|
|
27
|
+
export class AttachmentRelation {
|
|
28
|
+
#row;
|
|
29
|
+
#definition;
|
|
30
|
+
#pending;
|
|
31
|
+
constructor(row, definition) {
|
|
32
|
+
this.#row = row;
|
|
33
|
+
this.#definition = definition;
|
|
34
|
+
}
|
|
35
|
+
async get() {
|
|
36
|
+
const lifecycle = await this.#lifecycle();
|
|
37
|
+
return lifecycle.get(this.#owner());
|
|
38
|
+
}
|
|
39
|
+
get hasPending() {
|
|
40
|
+
return this.#pending !== undefined;
|
|
41
|
+
}
|
|
42
|
+
attach(input) {
|
|
43
|
+
if (this.#pending && this.#pending.type !== "detach") {
|
|
44
|
+
throw new Error(`Attachment relation "${this.#definition.field}" already has a pending attachment; use replace() or set()`);
|
|
45
|
+
}
|
|
46
|
+
this.#pending = { type: "attach", input };
|
|
47
|
+
}
|
|
48
|
+
attachExisting(attachmentId) {
|
|
49
|
+
if (this.#pending && this.#pending.type !== "detach") {
|
|
50
|
+
throw new Error(`Attachment relation "${this.#definition.field}" already has a pending attachment; use replace() or set()`);
|
|
51
|
+
}
|
|
52
|
+
this.#pending = { type: "attachExisting", attachmentId };
|
|
53
|
+
}
|
|
54
|
+
set(input) {
|
|
55
|
+
this.replace(input);
|
|
56
|
+
}
|
|
57
|
+
replace(input) {
|
|
58
|
+
this.#pending = { type: "replace", input };
|
|
59
|
+
}
|
|
60
|
+
detach() {
|
|
61
|
+
this.#pending = { type: "detach" };
|
|
62
|
+
}
|
|
63
|
+
async persist() {
|
|
64
|
+
const pending = this.#pending;
|
|
65
|
+
if (!pending) {
|
|
66
|
+
return this.get();
|
|
67
|
+
}
|
|
68
|
+
const owner = this.#owner();
|
|
69
|
+
const lifecycle = await this.#lifecycle();
|
|
70
|
+
let result;
|
|
71
|
+
switch (pending.type) {
|
|
72
|
+
case "attach":
|
|
73
|
+
if (await lifecycle.get(owner)) {
|
|
74
|
+
throw new Error(`Attachment relation "${owner.field}" already has an attachment; use replace() or set()`);
|
|
75
|
+
}
|
|
76
|
+
result = await lifecycle.attach(owner, pending.input, this.#definition.options);
|
|
77
|
+
break;
|
|
78
|
+
case "attachExisting":
|
|
79
|
+
if (await lifecycle.get(owner)) {
|
|
80
|
+
throw new Error(`Attachment relation "${owner.field}" already has an attachment; use replace() or set()`);
|
|
81
|
+
}
|
|
82
|
+
result = await lifecycle.attachExisting(owner, pending.attachmentId);
|
|
83
|
+
break;
|
|
84
|
+
case "replace":
|
|
85
|
+
result = await lifecycle.replace(owner, pending.input, this.#definition.options);
|
|
86
|
+
break;
|
|
87
|
+
case "detach":
|
|
88
|
+
await lifecycle.detach(owner);
|
|
89
|
+
result = null;
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
this.#pending = undefined;
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
async variants() {
|
|
96
|
+
const lifecycle = await this.#lifecycle();
|
|
97
|
+
return lifecycle.listVariants(this.#owner());
|
|
98
|
+
}
|
|
99
|
+
async regenerateVariants(variantKeys) {
|
|
100
|
+
const attachment = await this.get();
|
|
101
|
+
if (!attachment) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
const service = await resolveAttachmentService();
|
|
105
|
+
await service.scheduleVariantGeneration(attachment.toAttachment(), variantKeys);
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
async #lifecycle() {
|
|
109
|
+
return new LucidAttachmentLifecycleService(await resolveAttachmentService(), new LucidAttachmentStore(AttachmentModel, this.#row.$trx ? { client: this.#row.$trx } : {}));
|
|
110
|
+
}
|
|
111
|
+
#owner() {
|
|
112
|
+
return createOwner(this.#row, this.#definition);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
export class AttachmentCollectionRelation {
|
|
116
|
+
#row;
|
|
117
|
+
#definition;
|
|
118
|
+
#pending = [];
|
|
119
|
+
constructor(row, definition) {
|
|
120
|
+
this.#row = row;
|
|
121
|
+
this.#definition = definition;
|
|
122
|
+
}
|
|
123
|
+
async all() {
|
|
124
|
+
const lifecycle = await this.#lifecycle();
|
|
125
|
+
return lifecycle.listCollection(this.#owner());
|
|
126
|
+
}
|
|
127
|
+
get hasPending() {
|
|
128
|
+
return this.#pending.length > 0;
|
|
129
|
+
}
|
|
130
|
+
add(input, position) {
|
|
131
|
+
this.#pending.push({ type: "add", input, ...(position !== undefined ? { position } : {}) });
|
|
132
|
+
}
|
|
133
|
+
addExisting(attachmentId, position) {
|
|
134
|
+
this.#pending.push({
|
|
135
|
+
type: "addExisting",
|
|
136
|
+
attachmentId,
|
|
137
|
+
...(position !== undefined ? { position } : {}),
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
remove(id) {
|
|
141
|
+
this.#pending.push({ type: "remove", id });
|
|
142
|
+
}
|
|
143
|
+
clear() {
|
|
144
|
+
this.#pending = [{ type: "clear" }];
|
|
145
|
+
}
|
|
146
|
+
replaceAll(inputs) {
|
|
147
|
+
this.#pending = [{ type: "replaceAll", inputs }];
|
|
148
|
+
}
|
|
149
|
+
move(id, position) {
|
|
150
|
+
this.#pending.push({ type: "move", id, position });
|
|
151
|
+
}
|
|
152
|
+
async persist() {
|
|
153
|
+
if (this.#pending.length === 0) {
|
|
154
|
+
return this.all();
|
|
155
|
+
}
|
|
156
|
+
const lifecycle = await this.#lifecycle();
|
|
157
|
+
const owner = this.#owner();
|
|
158
|
+
while (this.#pending.length > 0) {
|
|
159
|
+
const operation = this.#pending[0];
|
|
160
|
+
switch (operation.type) {
|
|
161
|
+
case "add":
|
|
162
|
+
await lifecycle.add(owner, operation.input, operation.position, this.#definition.options);
|
|
163
|
+
break;
|
|
164
|
+
case "addExisting":
|
|
165
|
+
await lifecycle.addExisting(owner, operation.attachmentId, operation.position);
|
|
166
|
+
break;
|
|
167
|
+
case "remove":
|
|
168
|
+
await lifecycle.removeCollectionItem(owner, operation.id);
|
|
169
|
+
break;
|
|
170
|
+
case "clear":
|
|
171
|
+
await lifecycle.clearCollection(owner);
|
|
172
|
+
break;
|
|
173
|
+
case "replaceAll":
|
|
174
|
+
await lifecycle.replaceCollection(owner, operation.inputs, this.#definition.options);
|
|
175
|
+
break;
|
|
176
|
+
case "move":
|
|
177
|
+
await lifecycle.moveCollectionItem(owner, operation.id, operation.position);
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
this.#pending.shift();
|
|
181
|
+
}
|
|
182
|
+
return lifecycle.listCollection(owner);
|
|
183
|
+
}
|
|
184
|
+
async #lifecycle() {
|
|
185
|
+
return new LucidAttachmentLifecycleService(await resolveAttachmentService(), new LucidAttachmentStore(AttachmentModel, this.#row.$trx ? { client: this.#row.$trx } : {}));
|
|
186
|
+
}
|
|
187
|
+
#owner() {
|
|
188
|
+
return createOwner(this.#row, this.#definition);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
function defineRelation(kind, options) {
|
|
192
|
+
return (target, propertyKey) => {
|
|
193
|
+
const Model = target.constructor;
|
|
194
|
+
const field = String(propertyKey);
|
|
195
|
+
const definitions = relationDefinitions.get(Model) ?? new Map();
|
|
196
|
+
if (definitions.has(field)) {
|
|
197
|
+
throw new Error(`Attachment relation "${field}" is already declared on this model`);
|
|
198
|
+
}
|
|
199
|
+
Model.boot();
|
|
200
|
+
definitions.set(field, { kind, field, options });
|
|
201
|
+
relationDefinitions.set(Model, definitions);
|
|
202
|
+
if (!deleteHooks.has(Model)) {
|
|
203
|
+
deleteHooks.add(Model);
|
|
204
|
+
Model.after("delete", async (row) => {
|
|
205
|
+
for (const definition of relationDefinitions.get(Model)?.values() ?? []) {
|
|
206
|
+
const lifecycle = new LucidAttachmentLifecycleService(await resolveAttachmentService(), new LucidAttachmentStore(AttachmentModel, row.$trx ? { client: row.$trx } : {}));
|
|
207
|
+
await lifecycle.purgeOwner(createOwner(row, definition, true));
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
if (!saveHooks.has(Model)) {
|
|
212
|
+
saveHooks.add(Model);
|
|
213
|
+
wrapSave(Model);
|
|
214
|
+
}
|
|
215
|
+
Object.defineProperty(target, propertyKey, {
|
|
216
|
+
configurable: true,
|
|
217
|
+
enumerable: false,
|
|
218
|
+
get() {
|
|
219
|
+
const instances = relationInstances.get(this) ?? new Map();
|
|
220
|
+
const existing = instances.get(field);
|
|
221
|
+
if (existing) {
|
|
222
|
+
return existing;
|
|
223
|
+
}
|
|
224
|
+
const relation = kind === "one"
|
|
225
|
+
? new AttachmentRelation(this, definitions.get(field))
|
|
226
|
+
: new AttachmentCollectionRelation(this, definitions.get(field));
|
|
227
|
+
instances.set(field, relation);
|
|
228
|
+
relationInstances.set(this, instances);
|
|
229
|
+
return relation;
|
|
230
|
+
},
|
|
231
|
+
});
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
function createOwner(row, definition, allowDeleted = false) {
|
|
235
|
+
if ((!allowDeleted && !row.$isPersisted) ||
|
|
236
|
+
row.$primaryKeyValue === null ||
|
|
237
|
+
row.$primaryKeyValue === undefined) {
|
|
238
|
+
throw new Error("Attachment relations require a persisted Lucid model");
|
|
239
|
+
}
|
|
240
|
+
const type = definition.options.type ?? row.constructor.table;
|
|
241
|
+
if (!type) {
|
|
242
|
+
throw new Error("Attachment relations require a Lucid model table or an explicit relation type");
|
|
243
|
+
}
|
|
244
|
+
return {
|
|
245
|
+
type,
|
|
246
|
+
id: String(row.$primaryKeyValue),
|
|
247
|
+
field: definition.field,
|
|
248
|
+
model: row,
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
async function resolveAttachmentService() {
|
|
252
|
+
return (await app.container.make("jrmc.attachment"));
|
|
253
|
+
}
|
|
254
|
+
function wrapSave(Model) {
|
|
255
|
+
const save = Model.prototype.save;
|
|
256
|
+
Model.prototype.save = (async function saveWithAttachmentRelations() {
|
|
257
|
+
const result = await save.call(this);
|
|
258
|
+
for (const relation of relationInstances.get(this)?.values() ?? []) {
|
|
259
|
+
if (relation.hasPending) {
|
|
260
|
+
await relation.persist();
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
return result;
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
//# sourceMappingURL=attachment_relation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attachment_relation.js","sourceRoot":"","sources":["../../../../../src/integrations/lucid/relations/attachment_relation.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,GAAG,MAAM,6BAA6B,CAAC;AAY9C,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,+BAA+B,EAAE,MAAM,sDAAsD,CAAC;AACvG,OAAO,EAAE,oBAAoB,EAAE,MAAM,0CAA0C,CAAC;AAgDhF,MAAM,mBAAmB,GAAG,IAAI,OAAO,EAGpC,CAAC;AACJ,MAAM,iBAAiB,GAAG,IAAI,OAAO,EAGlC,CAAC;AACJ,MAAM,WAAW,GAAG,IAAI,OAAO,EAAU,CAAC;AAC1C,MAAM,SAAS,GAAG,IAAI,OAAO,EAAU,CAAC;AAExC;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAChC,UAA4C,EAAE;IAE9C,OAAO,cAAc,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;AACxC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CACjC,UAA4C,EAAE;IAE9C,OAAO,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AACzC,CAAC;AAED,MAAM,OAAO,kBAAkB;IACpB,IAAI,CAAwB;IAC5B,WAAW,CAAqB;IACzC,QAAQ,CAAuC;IAE/C,YAAY,GAA0B,EAAE,UAA8B;QACpE,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;QAChB,IAAI,CAAC,WAA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AI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAErC,KAAK,MAAM,QAAQ,IAAI,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC;YACnE,IAAI,QAAQ,CAAC,UAAU,EAAE,CAAC;gBACxB,MAAM,QAAQ,CAAC,OAAO,EAAE,CAAC;YAC3B,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC,CAAgC,CAAC;AACpC,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jrmc/adonis-attachment
|
|
3
|
+
*
|
|
4
|
+
* @license MIT
|
|
5
|
+
* @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
|
|
6
|
+
*/
|
|
7
|
+
import type { Knex } from 'knex';
|
|
8
|
+
export type AttachmentSchemaServiceOptions = {
|
|
9
|
+
tableName?: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Owns the versioned database schema used by the Lucid attachment integration.
|
|
13
|
+
*/
|
|
14
|
+
export declare class AttachmentSchemaService {
|
|
15
|
+
#private;
|
|
16
|
+
constructor(connection: Knex, options?: AttachmentSchemaServiceOptions);
|
|
17
|
+
createTables(): Promise<void>;
|
|
18
|
+
createBlobsTable(): Promise<void>;
|
|
19
|
+
createLinksTable(): Promise<void>;
|
|
20
|
+
dropTables(): Promise<void>;
|
|
21
|
+
dropBlobsTable(): Promise<void>;
|
|
22
|
+
dropLinksTable(): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=attachment_schema_service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attachment_schema_service.d.ts","sourceRoot":"","sources":["../../../../../src/integrations/lucid/schema/attachment_schema_service.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAGhC,MAAM,MAAM,8BAA8B,GAAG;IAC3C,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAAA;AAED;;GAEG;AACH,qBAAa,uBAAuB;;gBAKtB,UAAU,EAAE,IAAI,EAAE,OAAO,GAAE,8BAAmC;IAO1E,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAI7B,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC;IAqBjC,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC;IAiBjC,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAI3B,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAI/B,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;CAGhC"}
|