@jrmc/adonis-attachment 6.0.0-alpha.0 → 6.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/index.d.ts +23 -22
- package/build/index.d.ts.map +1 -1
- package/build/index.js +15 -14
- package/build/index.js.map +1 -1
- package/build/src/core/attachment.d.ts +37 -2
- package/build/src/core/attachment.d.ts.map +1 -1
- package/build/src/core/attachment.js +108 -5
- package/build/src/core/attachment.js.map +1 -1
- package/build/src/core/attachment_options.d.ts +32 -0
- package/build/src/core/attachment_options.d.ts.map +1 -0
- package/build/src/core/attachment_options.js +24 -0
- package/build/src/core/attachment_options.js.map +1 -0
- package/build/src/core/attachment_service.d.ts +7 -1
- package/build/src/core/attachment_service.d.ts.map +1 -1
- package/build/src/core/attachment_service.js +50 -4
- package/build/src/core/attachment_service.js.map +1 -1
- package/build/src/core/index.d.ts +2 -1
- package/build/src/core/index.d.ts.map +1 -1
- package/build/src/core/index.js +2 -1
- package/build/src/core/index.js.map +1 -1
- package/build/src/define_config.d.ts +4 -0
- package/build/src/define_config.d.ts.map +1 -1
- package/build/src/define_config.js +1 -0
- package/build/src/define_config.js.map +1 -1
- package/build/src/integrations/lucid/attachment_column.d.ts +8 -1
- package/build/src/integrations/lucid/attachment_column.d.ts.map +1 -1
- package/build/src/integrations/lucid/attachment_column.js +25 -12
- package/build/src/integrations/lucid/attachment_column.js.map +1 -1
- package/build/src/integrations/lucid/attachment_model.d.ts +1 -0
- package/build/src/integrations/lucid/attachment_model.d.ts.map +1 -1
- package/build/src/integrations/lucid/attachment_model.js +3 -0
- package/build/src/integrations/lucid/attachment_model.js.map +1 -1
- package/build/src/integrations/lucid/attachment_owner.d.ts +2 -1
- package/build/src/integrations/lucid/attachment_owner.d.ts.map +1 -1
- package/build/src/integrations/lucid/attachment_owner.js.map +1 -1
- package/build/src/integrations/lucid/attachment_relation.d.ts +60 -0
- package/build/src/integrations/lucid/attachment_relation.d.ts.map +1 -0
- package/build/src/integrations/lucid/attachment_relation.js +163 -0
- package/build/src/integrations/lucid/attachment_relation.js.map +1 -0
- package/build/src/integrations/lucid/index.d.ts +13 -12
- package/build/src/integrations/lucid/index.d.ts.map +1 -1
- package/build/src/integrations/lucid/index.js +13 -12
- package/build/src/integrations/lucid/index.js.map +1 -1
- package/build/src/integrations/lucid/lucid_attachment_lifecycle_service.d.ts +14 -5
- package/build/src/integrations/lucid/lucid_attachment_lifecycle_service.d.ts.map +1 -1
- package/build/src/integrations/lucid/lucid_attachment_lifecycle_service.js +130 -10
- package/build/src/integrations/lucid/lucid_attachment_lifecycle_service.js.map +1 -1
- package/build/src/integrations/lucid/lucid_attachment_store.d.ts +10 -1
- package/build/src/integrations/lucid/lucid_attachment_store.d.ts.map +1 -1
- package/build/src/integrations/lucid/lucid_attachment_store.js +102 -7
- package/build/src/integrations/lucid/lucid_attachment_store.js.map +1 -1
- package/build/src/integrations/lucid/migrate_legacy_attachment.d.ts +9 -2
- package/build/src/integrations/lucid/migrate_legacy_attachment.d.ts.map +1 -1
- package/build/src/integrations/lucid/migrate_legacy_attachment.js +25 -3
- package/build/src/integrations/lucid/migrate_legacy_attachment.js.map +1 -1
- package/build/src/sources/attachment_manager.d.ts +14 -12
- package/build/src/sources/attachment_manager.d.ts.map +1 -1
- package/build/src/sources/attachment_manager.js +14 -6
- package/build/src/sources/attachment_manager.js.map +1 -1
- package/build/stubs/migrations/attachments_table.stub +1 -0
- package/build/tests/attachment_manager.spec.js +21 -18
- package/build/tests/attachment_manager.spec.js.map +1 -1
- package/build/tests/attachment_manager_service.spec.js +2 -2
- package/build/tests/attachment_manager_service.spec.js.map +1 -1
- package/build/tests/attachment_options.spec.d.ts +2 -0
- package/build/tests/attachment_options.spec.d.ts.map +1 -0
- package/build/tests/attachment_options.spec.js +31 -0
- package/build/tests/attachment_options.spec.js.map +1 -0
- package/build/tests/attachment_service.spec.js +55 -0
- package/build/tests/attachment_service.spec.js.map +1 -1
- package/build/tests/attachments_table_stub.spec.js +1 -0
- package/build/tests/attachments_table_stub.spec.js.map +1 -1
- package/build/tests/define_config.spec.js +12 -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 +1 -0
- package/build/tests/helpers/lucid_test_database.js.map +1 -1
- package/build/tests/lucid_attachment_collection_store.spec.d.ts +2 -0
- package/build/tests/lucid_attachment_collection_store.spec.d.ts.map +1 -0
- package/build/tests/lucid_attachment_collection_store.spec.js +52 -0
- package/build/tests/lucid_attachment_collection_store.spec.js.map +1 -0
- package/build/tests/lucid_attachment_column.spec.js +57 -1
- package/build/tests/lucid_attachment_column.spec.js.map +1 -1
- package/build/tests/lucid_attachment_lifecycle_service.spec.js +172 -0
- package/build/tests/lucid_attachment_lifecycle_service.spec.js.map +1 -1
- package/build/tests/lucid_attachment_relation.spec.d.ts +8 -0
- package/build/tests/lucid_attachment_relation.spec.d.ts.map +1 -0
- package/build/tests/lucid_attachment_relation.spec.js +216 -0
- package/build/tests/lucid_attachment_relation.spec.js.map +1 -0
- package/build/tests/lucid_attachment_store.spec.js +2 -0
- package/build/tests/lucid_attachment_store.spec.js.map +1 -1
- package/build/tests/migrate_legacy_attachment.spec.js +96 -54
- package/build/tests/migrate_legacy_attachment.spec.js.map +1 -1
- package/package.json +4 -2
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* @license MIT
|
|
5
5
|
* @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
|
|
6
6
|
*/
|
|
7
|
+
import { isAttachmentDraft, } from '../../core/attachment.js';
|
|
7
8
|
export class LucidAttachmentLifecycleService {
|
|
8
9
|
#attachments;
|
|
9
10
|
#store;
|
|
@@ -11,22 +12,28 @@ export class LucidAttachmentLifecycleService {
|
|
|
11
12
|
this.#attachments = attachments;
|
|
12
13
|
this.#store = store;
|
|
13
14
|
}
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
get(owner) {
|
|
16
|
+
return this.#store.findOriginal(owner);
|
|
17
|
+
}
|
|
18
|
+
async attach(owner, input, options) {
|
|
19
|
+
const attachment = await this.#persist(owner, input, options);
|
|
16
20
|
try {
|
|
17
|
-
|
|
21
|
+
const original = await this.#store.createOriginal(owner, attachment);
|
|
22
|
+
this.#removeOnRollback(owner, [attachment]);
|
|
23
|
+
return original;
|
|
18
24
|
}
|
|
19
25
|
catch (error) {
|
|
20
26
|
await this.#removeStoredFile(attachment);
|
|
21
27
|
throw error;
|
|
22
28
|
}
|
|
23
29
|
}
|
|
24
|
-
async replace(owner, input) {
|
|
30
|
+
async replace(owner, input, options) {
|
|
25
31
|
const previous = await this.#store.findOriginal(owner);
|
|
26
32
|
if (!previous) {
|
|
27
|
-
return this.attach(owner, input);
|
|
33
|
+
return this.attach(owner, input, options);
|
|
28
34
|
}
|
|
29
|
-
const
|
|
35
|
+
const previousVariants = await this.#store.listVariants(previous.id);
|
|
36
|
+
const attachment = await this.#persist(owner, input, options);
|
|
30
37
|
let current;
|
|
31
38
|
try {
|
|
32
39
|
await this.#store.releaseOwner(previous);
|
|
@@ -46,7 +53,11 @@ export class LucidAttachmentLifecycleService {
|
|
|
46
53
|
await this.#removeStoredFile(current.toAttachment());
|
|
47
54
|
throw error;
|
|
48
55
|
}
|
|
49
|
-
await this.#
|
|
56
|
+
await this.#removeOnCommit(owner, [
|
|
57
|
+
previous.toAttachment(),
|
|
58
|
+
...previousVariants.map((variant) => variant.toAttachment()),
|
|
59
|
+
]);
|
|
60
|
+
this.#removeOnRollback(owner, [current.toAttachment()]);
|
|
50
61
|
return current;
|
|
51
62
|
}
|
|
52
63
|
async detach(owner) {
|
|
@@ -56,13 +67,122 @@ export class LucidAttachmentLifecycleService {
|
|
|
56
67
|
}
|
|
57
68
|
const variants = await this.#store.listVariants(original.id);
|
|
58
69
|
await this.#store.remove(original);
|
|
59
|
-
await
|
|
60
|
-
|
|
61
|
-
...variants.map((variant) =>
|
|
70
|
+
await this.#removeOnCommit(owner, [
|
|
71
|
+
original.toAttachment(),
|
|
72
|
+
...variants.map((variant) => variant.toAttachment()),
|
|
62
73
|
]);
|
|
63
74
|
}
|
|
75
|
+
async listVariants(owner) {
|
|
76
|
+
const original = await this.#store.findOriginal(owner);
|
|
77
|
+
return original ? this.#store.listVariants(original.id) : [];
|
|
78
|
+
}
|
|
79
|
+
async add(owner, input, position, options) {
|
|
80
|
+
const attachment = await this.#persist(owner, input, options);
|
|
81
|
+
try {
|
|
82
|
+
const item = await this.#collectionStore().createCollectionItem(owner, attachment, position);
|
|
83
|
+
this.#removeOnRollback(owner, [attachment]);
|
|
84
|
+
return item;
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
await this.#removeStoredFile(attachment);
|
|
88
|
+
throw error;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
listCollection(owner) {
|
|
92
|
+
return this.#collectionStore().listCollection(owner);
|
|
93
|
+
}
|
|
94
|
+
async removeCollectionItem(owner, id) {
|
|
95
|
+
const item = await this.#collectionStore().findCollectionItem(owner, id);
|
|
96
|
+
if (!item) {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
await this.#detachCollectionItem(owner, item);
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
async clearCollection(owner) {
|
|
103
|
+
for (const item of await this.#collectionStore().listCollection(owner)) {
|
|
104
|
+
await this.#detachCollectionItem(owner, item);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
async replaceCollection(owner, inputs, options) {
|
|
108
|
+
const previous = await this.#collectionStore().listCollection(owner);
|
|
109
|
+
const created = [];
|
|
110
|
+
try {
|
|
111
|
+
for (const input of inputs) {
|
|
112
|
+
created.push(await this.add(owner, input, undefined, options));
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
await Promise.all(created.map((item) => this.#detachCollectionItem(owner, item)));
|
|
117
|
+
throw error;
|
|
118
|
+
}
|
|
119
|
+
for (const item of previous) {
|
|
120
|
+
await this.#detachCollectionItem(owner, item);
|
|
121
|
+
}
|
|
122
|
+
return this.#collectionStore().listCollection(owner);
|
|
123
|
+
}
|
|
124
|
+
moveCollectionItem(owner, id, position) {
|
|
125
|
+
return this.#collectionStore().moveCollectionItem(owner, id, position);
|
|
126
|
+
}
|
|
64
127
|
async #removeStoredFile(attachment) {
|
|
65
128
|
await this.#attachments.remove(attachment);
|
|
66
129
|
}
|
|
130
|
+
async #removeOnCommit(owner, attachments) {
|
|
131
|
+
const transaction = getOwnerTransaction(owner);
|
|
132
|
+
if (transaction) {
|
|
133
|
+
transaction.after('commit', () => this.#removeStoredFiles(attachments));
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
await this.#removeStoredFiles(attachments);
|
|
137
|
+
}
|
|
138
|
+
#removeOnRollback(owner, attachments) {
|
|
139
|
+
const transaction = getOwnerTransaction(owner);
|
|
140
|
+
if (transaction) {
|
|
141
|
+
transaction.after('rollback', () => this.#removeStoredFiles(attachments));
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
#removeStoredFiles(attachments) {
|
|
145
|
+
return Promise.all(attachments.map((attachment) => this.#removeStoredFile(attachment))).then(() => undefined);
|
|
146
|
+
}
|
|
147
|
+
async #detachCollectionItem(owner, item) {
|
|
148
|
+
const variants = await this.#store.listVariants(item.id);
|
|
149
|
+
await this.#collectionStore().removeCollectionItem(owner, item);
|
|
150
|
+
await this.#removeOnCommit(owner, [
|
|
151
|
+
item.toAttachment(),
|
|
152
|
+
...variants.map((variant) => variant.toAttachment()),
|
|
153
|
+
]);
|
|
154
|
+
}
|
|
155
|
+
#collectionStore() {
|
|
156
|
+
const store = this.#store;
|
|
157
|
+
if (!store.createCollectionItem ||
|
|
158
|
+
!store.findCollectionItem ||
|
|
159
|
+
!store.listCollection ||
|
|
160
|
+
!store.moveCollectionItem ||
|
|
161
|
+
!store.removeCollectionItem) {
|
|
162
|
+
throw new Error('Lucid attachment collection operations require a collection-capable store');
|
|
163
|
+
}
|
|
164
|
+
return store;
|
|
165
|
+
}
|
|
166
|
+
async #persist(owner, input, options) {
|
|
167
|
+
if (isAttachmentDraft(input)) {
|
|
168
|
+
return input.persist({
|
|
169
|
+
...(options ? { options } : {}),
|
|
170
|
+
context: { model: owner.model, field: owner.field },
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
if (this.#attachments.createDraft) {
|
|
174
|
+
return this.#attachments
|
|
175
|
+
.createDraft(input)
|
|
176
|
+
.persist({
|
|
177
|
+
...(options ? { options } : {}),
|
|
178
|
+
context: { model: owner.model, field: owner.field },
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
return this.#attachments.create(input);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
function getOwnerTransaction(owner) {
|
|
185
|
+
const model = owner.model;
|
|
186
|
+
return model?.$trx ?? null;
|
|
67
187
|
}
|
|
68
188
|
//# sourceMappingURL=lucid_attachment_lifecycle_service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lucid_attachment_lifecycle_service.js","sourceRoot":"","sources":["../../../../src/integrations/lucid/lucid_attachment_lifecycle_service.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"lucid_attachment_lifecycle_service.js","sourceRoot":"","sources":["../../../../src/integrations/lucid/lucid_attachment_lifecycle_service.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,iBAAiB,GAIlB,MAAM,0BAA0B,CAAA;AAwBjC,MAAM,OAAO,+BAA+B;IACjC,YAAY,CAAuB;IACnC,MAAM,CAA4B;IAE3C,YAAY,WAAkC,EAAE,KAAiC;QAC/E,IAAI,CAAC,YAAY,GAAG,WAAW,CAAA;QAC/B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAA;IACrB,CAAC;IAED,GAAG,CAAC,KAAsB;QACxB,OAAO,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,CAAA;I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,EAAE;aACpD,CAAC,CAAA;QACJ,CAAC;QAED,IAAI,IAAI,CAAC,YAAY,CAAC,WAAW,EAAE,CAAC;YAClC,OAAO,IAAI,CAAC,YAAY;iBACrB,WAAW,CAAC,KAAK,CAAC;iBAClB,OAAO,CAAC;gBACP,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBAC/B,OAAO,EAAE,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE;aACpD,CAAC,CAAA;QACN,CAAC;QAED,OAAO,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IACxC,CAAC;CACF;AAED,SAAS,mBAAmB,CAAC,KAAsB;IAGjD,MAAM,KAAK,GAAG,KAAK,CAAC,KAMP,CAAA;IAEb,OAAO,KAAK,EAAE,IAAI,IAAI,IAAI,CAAA;AAC5B,CAAC"}
|
|
@@ -5,20 +5,29 @@
|
|
|
5
5
|
* @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
|
|
6
6
|
*/
|
|
7
7
|
import type { Attachment } from '../../core/attachment.js';
|
|
8
|
+
import type { TransactionClientContract } from '@adonisjs/lucid/types/database';
|
|
8
9
|
import { type AttachmentOwner } from './attachment_owner.js';
|
|
9
10
|
import { AttachmentModel } from './attachment_model.js';
|
|
10
11
|
export type LucidAttachmentWithVariants = {
|
|
11
12
|
original: AttachmentModel;
|
|
12
13
|
variants: AttachmentModel[];
|
|
13
14
|
};
|
|
15
|
+
export type LucidAttachmentStoreOptions = {
|
|
16
|
+
client?: TransactionClientContract;
|
|
17
|
+
};
|
|
14
18
|
export declare class LucidAttachmentStore {
|
|
15
19
|
#private;
|
|
16
|
-
constructor(model?: typeof AttachmentModel);
|
|
20
|
+
constructor(model?: typeof AttachmentModel, options?: LucidAttachmentStoreOptions);
|
|
17
21
|
createOriginal(owner: AttachmentOwner, attachment: Attachment): Promise<AttachmentModel>;
|
|
22
|
+
createCollectionItem(owner: AttachmentOwner, attachment: Attachment, position?: number): Promise<AttachmentModel>;
|
|
18
23
|
createVariant(original: AttachmentModel, key: string, attachment: Attachment): Promise<AttachmentModel>;
|
|
19
24
|
releaseOwner(original: AttachmentModel): Promise<void>;
|
|
20
25
|
restoreOwner(original: AttachmentModel): Promise<void>;
|
|
21
26
|
findOriginal(owner: AttachmentOwner): Promise<AttachmentModel | null>;
|
|
27
|
+
listCollection(owner: AttachmentOwner): Promise<AttachmentModel[]>;
|
|
28
|
+
findCollectionItem(owner: AttachmentOwner, id: string): Promise<AttachmentModel | null>;
|
|
29
|
+
removeCollectionItem(owner: AttachmentOwner, item: AttachmentModel): Promise<void>;
|
|
30
|
+
moveCollectionItem(owner: AttachmentOwner, id: string, position: number): Promise<AttachmentModel[]>;
|
|
22
31
|
findById(id: string): Promise<AttachmentModel | null>;
|
|
23
32
|
findByOwner(owner: AttachmentOwner): Promise<LucidAttachmentWithVariants | null>;
|
|
24
33
|
listVariants(originalId: string): Promise<AttachmentModel[]>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lucid_attachment_store.d.ts","sourceRoot":"","sources":["../../../../src/integrations/lucid/lucid_attachment_store.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;
|
|
1
|
+
{"version":3,"file":"lucid_attachment_store.d.ts","sourceRoot":"","sources":["../../../../src/integrations/lucid/lucid_attachment_store.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAC1D,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAA;AAE/E,OAAO,EAA4B,KAAK,eAAe,EAAE,MAAM,uBAAuB,CAAA;AACtF,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAEvD,MAAM,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AAC,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;IAItD,MAAM,CAAC,QAAQ,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;CAwCvD"}
|
|
@@ -9,8 +9,10 @@ import { createAttachmentOwnerKey } from './attachment_owner.js';
|
|
|
9
9
|
import { AttachmentModel } from './attachment_model.js';
|
|
10
10
|
export class LucidAttachmentStore {
|
|
11
11
|
#model;
|
|
12
|
-
|
|
12
|
+
#client;
|
|
13
|
+
constructor(model = AttachmentModel, options = {}) {
|
|
13
14
|
this.#model = model;
|
|
15
|
+
this.#client = options.client;
|
|
14
16
|
}
|
|
15
17
|
async createOriginal(owner, attachment) {
|
|
16
18
|
const row = await this.#model.create({
|
|
@@ -19,10 +21,29 @@ export class LucidAttachmentStore {
|
|
|
19
21
|
attachableId: owner.id,
|
|
20
22
|
field: owner.field,
|
|
21
23
|
ownerKey: createAttachmentOwnerKey(owner),
|
|
24
|
+
position: null,
|
|
22
25
|
parentId: null,
|
|
23
26
|
variantKey: null,
|
|
24
27
|
metadata: attachment.metadata ?? null,
|
|
25
|
-
});
|
|
28
|
+
}, this.#client ? { client: this.#client } : undefined);
|
|
29
|
+
markAttachmentPersisted(attachment);
|
|
30
|
+
return row;
|
|
31
|
+
}
|
|
32
|
+
async createCollectionItem(owner, attachment, position) {
|
|
33
|
+
const items = await this.listCollection(owner);
|
|
34
|
+
const target = normalizePosition(position, items.length);
|
|
35
|
+
await this.#shiftCollection(items, target, 1);
|
|
36
|
+
const row = await this.#model.create({
|
|
37
|
+
...attachment,
|
|
38
|
+
attachableType: owner.type,
|
|
39
|
+
attachableId: owner.id,
|
|
40
|
+
field: owner.field,
|
|
41
|
+
ownerKey: null,
|
|
42
|
+
position: target,
|
|
43
|
+
parentId: null,
|
|
44
|
+
variantKey: null,
|
|
45
|
+
metadata: attachment.metadata ?? null,
|
|
46
|
+
}, this.#client ? { client: this.#client } : undefined);
|
|
26
47
|
markAttachmentPersisted(attachment);
|
|
27
48
|
return row;
|
|
28
49
|
}
|
|
@@ -33,10 +54,11 @@ export class LucidAttachmentStore {
|
|
|
33
54
|
attachableId: original.attachableId,
|
|
34
55
|
field: original.field,
|
|
35
56
|
ownerKey: null,
|
|
57
|
+
position: null,
|
|
36
58
|
parentId: original.id,
|
|
37
59
|
variantKey: key,
|
|
38
60
|
metadata: attachment.metadata ?? null,
|
|
39
|
-
});
|
|
61
|
+
}, this.#client ? { client: this.#client } : undefined);
|
|
40
62
|
markAttachmentPersisted(attachment);
|
|
41
63
|
return row;
|
|
42
64
|
}
|
|
@@ -53,16 +75,54 @@ export class LucidAttachmentStore {
|
|
|
53
75
|
await original.save();
|
|
54
76
|
}
|
|
55
77
|
findOriginal(owner) {
|
|
56
|
-
return this.#
|
|
57
|
-
.query()
|
|
78
|
+
return this.#query()
|
|
58
79
|
.where('attachable_type', owner.type)
|
|
59
80
|
.where('attachable_id', owner.id)
|
|
60
81
|
.where('field', owner.field)
|
|
82
|
+
.whereNotNull('owner_key')
|
|
61
83
|
.whereNull('parent_id')
|
|
62
84
|
.first();
|
|
63
85
|
}
|
|
86
|
+
listCollection(owner) {
|
|
87
|
+
return this.#query()
|
|
88
|
+
.where('attachable_type', owner.type)
|
|
89
|
+
.where('attachable_id', owner.id)
|
|
90
|
+
.where('field', owner.field)
|
|
91
|
+
.whereNull('owner_key')
|
|
92
|
+
.whereNull('parent_id')
|
|
93
|
+
.orderBy('position', 'asc');
|
|
94
|
+
}
|
|
95
|
+
findCollectionItem(owner, id) {
|
|
96
|
+
return this.#query()
|
|
97
|
+
.where('id', id)
|
|
98
|
+
.where('attachable_type', owner.type)
|
|
99
|
+
.where('attachable_id', owner.id)
|
|
100
|
+
.where('field', owner.field)
|
|
101
|
+
.whereNull('owner_key')
|
|
102
|
+
.whereNull('parent_id')
|
|
103
|
+
.first();
|
|
104
|
+
}
|
|
105
|
+
async removeCollectionItem(owner, item) {
|
|
106
|
+
await this.remove(item);
|
|
107
|
+
await this.#normalizeCollection(owner);
|
|
108
|
+
}
|
|
109
|
+
async moveCollectionItem(owner, id, position) {
|
|
110
|
+
const items = await this.listCollection(owner);
|
|
111
|
+
const source = items.findIndex((item) => item.id === id);
|
|
112
|
+
if (source === -1) {
|
|
113
|
+
throw new Error(`Attachment "${id}" does not belong to this collection`);
|
|
114
|
+
}
|
|
115
|
+
const target = normalizePosition(position, items.length - 1);
|
|
116
|
+
if (source === target) {
|
|
117
|
+
return items;
|
|
118
|
+
}
|
|
119
|
+
const [item] = items.splice(source, 1);
|
|
120
|
+
items.splice(target, 0, item);
|
|
121
|
+
await this.#reorderCollection(items);
|
|
122
|
+
return items;
|
|
123
|
+
}
|
|
64
124
|
findById(id) {
|
|
65
|
-
return this.#
|
|
125
|
+
return this.#query().where('id', id).first();
|
|
66
126
|
}
|
|
67
127
|
async findByOwner(owner) {
|
|
68
128
|
const original = await this.findOriginal(owner);
|
|
@@ -75,10 +135,45 @@ export class LucidAttachmentStore {
|
|
|
75
135
|
};
|
|
76
136
|
}
|
|
77
137
|
listVariants(originalId) {
|
|
78
|
-
return this.#
|
|
138
|
+
return this.#query().where('parent_id', originalId);
|
|
79
139
|
}
|
|
80
140
|
async remove(original) {
|
|
81
141
|
await original.delete();
|
|
82
142
|
}
|
|
143
|
+
async #normalizeCollection(owner) {
|
|
144
|
+
await this.#reorderCollection(await this.listCollection(owner));
|
|
145
|
+
}
|
|
146
|
+
#query() {
|
|
147
|
+
return this.#model.query(this.#client ? { client: this.#client } : undefined);
|
|
148
|
+
}
|
|
149
|
+
async #shiftCollection(items, from, amount) {
|
|
150
|
+
for (const item of [...items].reverse()) {
|
|
151
|
+
if ((item.position ?? 0) < from) {
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
item.position = (item.position ?? 0) + amount;
|
|
155
|
+
await item.save();
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
async #reorderCollection(items) {
|
|
159
|
+
const offset = items.length + 1;
|
|
160
|
+
for (const item of items) {
|
|
161
|
+
item.position = (item.position ?? 0) + offset;
|
|
162
|
+
await item.save();
|
|
163
|
+
}
|
|
164
|
+
for (const [position, item] of items.entries()) {
|
|
165
|
+
item.position = position;
|
|
166
|
+
await item.save();
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
function normalizePosition(position, maximum) {
|
|
171
|
+
if (position === undefined) {
|
|
172
|
+
return maximum;
|
|
173
|
+
}
|
|
174
|
+
if (!Number.isSafeInteger(position) || position < 0) {
|
|
175
|
+
throw new Error('Attachment collection positions must be non-negative integers');
|
|
176
|
+
}
|
|
177
|
+
return Math.min(position, maximum);
|
|
83
178
|
}
|
|
84
179
|
//# sourceMappingURL=lucid_attachment_store.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lucid_attachment_store.js","sourceRoot":"","sources":["../../../../src/integrations/lucid/lucid_attachment_store.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"lucid_attachment_store.js","sourceRoot":"","sources":["../../../../src/integrations/lucid/lucid_attachment_store.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAA;AACxE,OAAO,EAAE,wBAAwB,EAAwB,MAAM,uBAAuB,CAAA;AACtF,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAWvD,MAAM,OAAO,oBAAoB;IACtB,MAAM,CAAwB;IAC9B,OAAO,CAAuC;IAEvD,YACE,QAAgC,eAAe,EAC/C,UAAuC,EAAE;QAEzC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAA;QACnB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,MAA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AAM,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"}
|
|
@@ -25,8 +25,9 @@ export type LegacyVariant = {
|
|
|
25
25
|
path?: string;
|
|
26
26
|
meta?: Record<string, unknown>;
|
|
27
27
|
};
|
|
28
|
-
import { type AttachmentOwner } from
|
|
29
|
-
|
|
28
|
+
import { type AttachmentOwner } from "./attachment_owner.js";
|
|
29
|
+
import type { Attachment } from "../../core/attachment.js";
|
|
30
|
+
export type { AttachmentOwner } from "./attachment_owner.js";
|
|
30
31
|
export type MigratedAttachmentRow = {
|
|
31
32
|
id: string;
|
|
32
33
|
attachableType: string;
|
|
@@ -49,9 +50,15 @@ export type MigrateLegacyAttachmentOptions = {
|
|
|
49
50
|
defaultDisk: string;
|
|
50
51
|
createId: () => string;
|
|
51
52
|
};
|
|
53
|
+
export type MigrateLegacyAttachmentColumnOptions = Omit<MigrateLegacyAttachmentOptions, "owner">;
|
|
52
54
|
/**
|
|
53
55
|
* Converts one v5 JSON attachment document into rows for the polymorphic table.
|
|
54
56
|
* Callers can run it from an Ace command, another ORM migration, or a one-off script.
|
|
55
57
|
*/
|
|
56
58
|
export declare function migrateLegacyAttachment(value: LegacyAttachment | string, options: MigrateLegacyAttachmentOptions): MigratedAttachmentRow[];
|
|
59
|
+
/**
|
|
60
|
+
* Converts one v5 JSON value for a retained single attachment column. Legacy
|
|
61
|
+
* variants require the polymorphic table and therefore cannot be kept here.
|
|
62
|
+
*/
|
|
63
|
+
export declare function migrateLegacyAttachmentColumn(value: LegacyAttachment | string, options: MigrateLegacyAttachmentColumnOptions): Attachment;
|
|
57
64
|
//# sourceMappingURL=migrate_legacy_attachment.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrate_legacy_attachment.d.ts","sourceRoot":"","sources":["../../../../src/integrations/lucid/migrate_legacy_attachment.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"migrate_legacy_attachment.d.ts","sourceRoot":"","sources":["../../../../src/integrations/lucid/migrate_legacy_attachment.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,QAAQ,CAAC,EAAE,aAAa,EAAE,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAA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ChC,OAAO,EAAE,8BAA8B,GACtC,qBAAqB,EAAE,CA+BzB;AAED;;;GAGG;AACH,wBAAgB,6BAA6B,CAC3C,KAAK,EAAE,gBAAgB,GAAG,MAAM,EAChC,OAAO,EAAE,oCAAoC,GAC5C,UAAU,CAuBZ"}
|
|
@@ -4,13 +4,13 @@
|
|
|
4
4
|
* @license MIT
|
|
5
5
|
* @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
|
|
6
6
|
*/
|
|
7
|
-
import { createAttachmentOwnerKey } from
|
|
7
|
+
import { createAttachmentOwnerKey, } from "./attachment_owner.js";
|
|
8
8
|
/**
|
|
9
9
|
* Converts one v5 JSON attachment document into rows for the polymorphic table.
|
|
10
10
|
* Callers can run it from an Ace command, another ORM migration, or a one-off script.
|
|
11
11
|
*/
|
|
12
12
|
export function migrateLegacyAttachment(value, options) {
|
|
13
|
-
const attachment = typeof value ===
|
|
13
|
+
const attachment = typeof value === "string" ? parseLegacyAttachment(value) : value;
|
|
14
14
|
const id = options.createId();
|
|
15
15
|
const originalName = attachment.originalName ?? attachment.name;
|
|
16
16
|
const original = toRow({
|
|
@@ -37,12 +37,34 @@ export function migrateLegacyAttachment(value, options) {
|
|
|
37
37
|
})),
|
|
38
38
|
];
|
|
39
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Converts one v5 JSON value for a retained single attachment column. Legacy
|
|
42
|
+
* variants require the polymorphic table and therefore cannot be kept here.
|
|
43
|
+
*/
|
|
44
|
+
export function migrateLegacyAttachmentColumn(value, options) {
|
|
45
|
+
const attachment = typeof value === "string" ? parseLegacyAttachment(value) : value;
|
|
46
|
+
if (attachment.variants?.length) {
|
|
47
|
+
throw new Error("Legacy attachments with variants must migrate to the polymorphic table");
|
|
48
|
+
}
|
|
49
|
+
const originalName = attachment.originalName ?? attachment.name;
|
|
50
|
+
return {
|
|
51
|
+
id: options.createId(),
|
|
52
|
+
disk: attachment.disk ?? options.defaultDisk,
|
|
53
|
+
path: attachment.path ?? attachment.name,
|
|
54
|
+
name: attachment.name,
|
|
55
|
+
originalName,
|
|
56
|
+
mimeType: attachment.mimeType,
|
|
57
|
+
extname: attachment.extname,
|
|
58
|
+
size: attachment.size,
|
|
59
|
+
...(attachment.meta ? { metadata: attachment.meta } : {}),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
40
62
|
function parseLegacyAttachment(value) {
|
|
41
63
|
try {
|
|
42
64
|
return JSON.parse(value);
|
|
43
65
|
}
|
|
44
66
|
catch {
|
|
45
|
-
throw new Error(
|
|
67
|
+
throw new Error("Legacy attachment value must be valid JSON");
|
|
46
68
|
}
|
|
47
69
|
}
|
|
48
70
|
function toRow({ id, attachment, owner, ownerKey, parentId, variantKey, originalName, defaultDisk, }) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrate_legacy_attachment.js","sourceRoot":"","sources":["../../../../src/integrations/lucid/migrate_legacy_attachment.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAyBH,OAAO,
|
|
1
|
+
{"version":3,"file":"migrate_legacy_attachment.js","sourceRoot":"","sources":["../../../../src/integrations/lucid/migrate_legacy_attachment.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAyBH,OAAO,EACL,wBAAwB,GAEzB,MAAM,uBAAuB,CAAC;AAkC/B;;;GAGG;AACH,MAAM,UAAU,uBAAuB,CACrC,KAAgC,EAChC,OAAuC;IAEvC,MAAM,UAAU,GACd,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,qBAAqB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IACnE,MAAM,EAAE,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;IAC9B,MAAM,YAAY,GAAG,UAAU,CAAC,YAAY,IAAI,UAAU,CAAC,IAAI,CAAC;IAChE,MAAM,QAAQ,GAAG,KAAK,CAAC;QACrB,EAAE;QACF,UAAU;QACV,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,QAAQ,EAAE,wBAAwB,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C,OAAO;QAC3B,IAAI,EAAE,UAAU,CAAC,IAAI;QACrB,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC1D,CAAC;AACJ,CAAC;AAED,SAAS,qBAAqB,CAAC,KAAa;IAC1C,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAqB,CAAC;IAC/C,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAChE,CAAC;AACH,CAAC;AAED,SAAS,KAAK,CAAC,EACb,EAAE,EACF,UAAU,EACV,KAAK,EACL,QAAQ,EACR,QAAQ,EACR,UAAU,EACV,YAAY,EACZ,WAAW,GAUZ;IACC,OAAO;QACL,EAAE;QACF,cAAc,EAAE,KAAK,CAAC,IAAI;QAC1B,YAAY,EAAE,KAAK,CAAC,EAAE;QACtB,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,QAAQ;QACR,QAAQ;QACR,UAAU;QACV,IAAI,EAAE,UAAU,CAAC,IAAI,IAAI,WAAW;QACpC,IAAI,EAAE,UAAU,CAAC,IAAI,IAAI,UAAU,CAAC,IAAI;QACxC,IAAI,EAAE,UAAU,CAAC,IAAI;QACrB,YAAY;QACZ,QAAQ,EAAE,UAAU,CAAC,QAAQ;QAC7B,OAAO,EAAE,UAAU,CAAC,OAAO;QAC3B,IAAI,EAAE,UAAU,CAAC,IAAI;QACrB,QAAQ,EAAE,UAAU,CAAC,IAAI,IAAI,IAAI;KAClC,CAAC;AACJ,CAAC"}
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
* @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
|
|
6
6
|
*/
|
|
7
7
|
import type { Readable } from 'node:stream';
|
|
8
|
-
import type {
|
|
8
|
+
import type { AttachmentDraft, CreateAttachmentInput } from '../core/attachment.js';
|
|
9
|
+
import type { AttachmentPersistenceOptions } from '../core/attachment_options.js';
|
|
9
10
|
import type { AttachmentService } from '../core/attachment_service.js';
|
|
10
11
|
export type MultipartAttachmentFile = {
|
|
11
12
|
tmpPath?: string;
|
|
@@ -13,9 +14,10 @@ export type MultipartAttachmentFile = {
|
|
|
13
14
|
type?: string;
|
|
14
15
|
subtype?: string;
|
|
15
16
|
};
|
|
16
|
-
export type AttachmentSourceOptions =
|
|
17
|
+
export type AttachmentSourceOptions = AttachmentPersistenceOptions & {
|
|
17
18
|
originalName?: string;
|
|
18
19
|
mimeType?: string;
|
|
20
|
+
metadata?: CreateAttachmentInput['metadata'];
|
|
19
21
|
maxBytes?: number;
|
|
20
22
|
};
|
|
21
23
|
export type AttachmentSourceResponse = {
|
|
@@ -31,19 +33,19 @@ export type AttachmentManagerOptions = {
|
|
|
31
33
|
fetch?: AttachmentSourceFetch;
|
|
32
34
|
};
|
|
33
35
|
/**
|
|
34
|
-
* Normalizes common input sources
|
|
35
|
-
*
|
|
36
|
+
* Normalizes common input sources into drafts. The file is written only when the
|
|
37
|
+
* caller invokes `draft.persist()` or an integration persists it automatically.
|
|
36
38
|
*/
|
|
37
39
|
export declare class AttachmentManager {
|
|
38
40
|
#private;
|
|
39
|
-
constructor(attachments: Pick<AttachmentService, '
|
|
40
|
-
createFromBuffer(input: Uint8Array, options?: AttachmentSourceOptions): Promise<
|
|
41
|
-
createFromBase64(input: string, options?: AttachmentSourceOptions): Promise<
|
|
42
|
-
createFromPath(input: string, options?: AttachmentSourceOptions): Promise<
|
|
43
|
-
createFromStream(input: Readable, options?: AttachmentSourceOptions): Promise<
|
|
44
|
-
createFromUrl(input: URL | string, options?: AttachmentSourceOptions): Promise<
|
|
45
|
-
createFromFile(input: MultipartAttachmentFile, options?: AttachmentSourceOptions): Promise<
|
|
46
|
-
createFromFiles(inputs: readonly MultipartAttachmentFile[], options?: AttachmentSourceOptions): Promise<
|
|
41
|
+
constructor(attachments: Pick<AttachmentService, 'createDraft'>, options?: AttachmentManagerOptions);
|
|
42
|
+
createFromBuffer(input: Uint8Array, options?: AttachmentSourceOptions): Promise<AttachmentDraft>;
|
|
43
|
+
createFromBase64(input: string, options?: AttachmentSourceOptions): Promise<AttachmentDraft>;
|
|
44
|
+
createFromPath(input: string, options?: AttachmentSourceOptions): Promise<AttachmentDraft>;
|
|
45
|
+
createFromStream(input: Readable, options?: AttachmentSourceOptions): Promise<AttachmentDraft>;
|
|
46
|
+
createFromUrl(input: URL | string, options?: AttachmentSourceOptions): Promise<AttachmentDraft>;
|
|
47
|
+
createFromFile(input: MultipartAttachmentFile, options?: AttachmentSourceOptions): Promise<AttachmentDraft>;
|
|
48
|
+
createFromFiles(inputs: readonly MultipartAttachmentFile[], options?: AttachmentSourceOptions): Promise<AttachmentDraft[]>;
|
|
47
49
|
}
|
|
48
50
|
export declare class AttachmentSourceError extends Error {
|
|
49
51
|
constructor(message: string);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attachment_manager.d.ts","sourceRoot":"","sources":["../../../src/sources/attachment_manager.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAE3C,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"attachment_manager.d.ts","sourceRoot":"","sources":["../../../src/sources/attachment_manager.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAE3C,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAA;AACnF,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,+BAA+B,CAAA;AACjF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAA;AAEtE,MAAM,MAAM,uBAAuB,GAAG;IACpC,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,UAAU,EAAE,MAAM,CAA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