@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
package/build/index.d.ts
CHANGED
|
@@ -1,27 +1,28 @@
|
|
|
1
|
-
import type { AttachmentService } from
|
|
2
|
-
import type { AttachmentRepository } from
|
|
3
|
-
import type { AttachmentManager } from
|
|
4
|
-
import attachmentManager from
|
|
5
|
-
declare module
|
|
1
|
+
import type { AttachmentService } from "./src/core/attachment_service.js";
|
|
2
|
+
import type { AttachmentRepository } from "./src/core/attachment_repository.js";
|
|
3
|
+
import type { AttachmentManager } from "./src/sources/attachment_manager.js";
|
|
4
|
+
import attachmentManager from "./services/main.js";
|
|
5
|
+
declare module "@adonisjs/core/types" {
|
|
6
6
|
interface ContainerBindings {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
"jrmc.attachment": AttachmentService;
|
|
8
|
+
"jrmc.attachment.manager": AttachmentManager;
|
|
9
|
+
"jrmc.attachment.repository": AttachmentRepository;
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
|
-
export * from
|
|
13
|
-
export { configure } from
|
|
12
|
+
export * from "./src/core/index.js";
|
|
13
|
+
export { configure } from "./configure.js";
|
|
14
14
|
export { attachmentManager };
|
|
15
|
-
export { defineConfig, type AttachmentConfig, type ResolvedAttachmentConfig } from
|
|
16
|
-
export { AdonisDriveStorage } from
|
|
17
|
-
export { LocalFileStorage, type LocalFileStorageOptions } from
|
|
18
|
-
export { attachment } from
|
|
19
|
-
export {
|
|
20
|
-
export {
|
|
21
|
-
export {
|
|
22
|
-
export {
|
|
23
|
-
export {
|
|
24
|
-
export {
|
|
25
|
-
export {
|
|
26
|
-
export {
|
|
15
|
+
export { defineConfig, type AttachmentConfig, type ResolvedAttachmentConfig, } from "./src/define_config.js";
|
|
16
|
+
export { AdonisDriveStorage } from "./src/adapters/adonis_drive_storage.js";
|
|
17
|
+
export { LocalFileStorage, type LocalFileStorageOptions, } from "./src/adapters/local_file_storage.js";
|
|
18
|
+
export { attachment, type LucidAttachmentOptions, } from "./src/integrations/lucid/attachment_column.js";
|
|
19
|
+
export { attachmentRelation, attachmentsRelation, AttachmentRelation, AttachmentCollectionRelation, type AttachmentRelationOptions, } from "./src/integrations/lucid/attachment_relation.js";
|
|
20
|
+
export { VariantGenerationService, UnknownVariantConverterError, type GeneratedVariant, type VariantGenerationServiceOptions, } from "./src/variants/variant_generation_service.js";
|
|
21
|
+
export { type VariantConverter, type VariantConversionInput, type VariantConversionOutput, } from "./src/variants/variant_converter.js";
|
|
22
|
+
export { MemoryAttachmentQueue } from "./src/queues/memory_queue.js";
|
|
23
|
+
export { AttachmentManager, AttachmentSourceError, type AttachmentManagerOptions, type AttachmentSourceFetch, type AttachmentSourceOptions, type AttachmentSourceResponse, type MultipartAttachmentFile, } from "./src/sources/attachment_manager.js";
|
|
24
|
+
export { AdonisAttachmentQueue, type AdonisAttachmentJob, type AdonisAttachmentQueueOptions, type AdonisQueueDispatcher, } from "./src/queues/adonis_queue.js";
|
|
25
|
+
export { migrateLegacyAttachment, migrateLegacyAttachmentColumn, type AttachmentOwner, type LegacyAttachment, type LegacyVariant, type MigrateLegacyAttachmentColumnOptions, type MigratedAttachmentRow, } from "./src/integrations/lucid/migrate_legacy_attachment.js";
|
|
26
|
+
export { createAttachmentOwnerKey } from "./src/integrations/lucid/attachment_owner.js";
|
|
27
|
+
export { createAttachmentsTableStubState } from "./src/integrations/lucid/attachments_table_stub.js";
|
|
27
28
|
//# sourceMappingURL=index.d.ts.map
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAC1E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAC;AAChF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AAE7E,OAAO,iBAAiB,MAAM,oBAAoB,CAAC;AAEnD,OAAO,QAAQ,sBAAsB,CAAC;IACpC,UAAiB,iBAAiB;QAChC,iBAAiB,EAAE,iBAAiB,CAAC;QACrC,yBAAyB,EAAE,iBAAiB,CAAC;QAC7C,4BAA4B,EAAE,oBAAoB,CAAC;KACpD;CACF;AAED,cAAc,qBAAqB,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,CAAC;AAC7B,OAAO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/index.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import attachmentManager from
|
|
2
|
-
export * from
|
|
3
|
-
export { configure } from
|
|
1
|
+
import attachmentManager from "./services/main.js";
|
|
2
|
+
export * from "./src/core/index.js";
|
|
3
|
+
export { configure } from "./configure.js";
|
|
4
4
|
export { attachmentManager };
|
|
5
|
-
export { defineConfig } from
|
|
6
|
-
export { AdonisDriveStorage } from
|
|
7
|
-
export { LocalFileStorage } from
|
|
8
|
-
export { attachment } from
|
|
9
|
-
export {
|
|
10
|
-
export {
|
|
11
|
-
export {
|
|
12
|
-
export {
|
|
13
|
-
export {
|
|
14
|
-
export {
|
|
15
|
-
export {
|
|
5
|
+
export { defineConfig, } from "./src/define_config.js";
|
|
6
|
+
export { AdonisDriveStorage } from "./src/adapters/adonis_drive_storage.js";
|
|
7
|
+
export { LocalFileStorage, } from "./src/adapters/local_file_storage.js";
|
|
8
|
+
export { attachment, } from "./src/integrations/lucid/attachment_column.js";
|
|
9
|
+
export { attachmentRelation, attachmentsRelation, AttachmentRelation, AttachmentCollectionRelation, } from "./src/integrations/lucid/attachment_relation.js";
|
|
10
|
+
export { VariantGenerationService, UnknownVariantConverterError, } from "./src/variants/variant_generation_service.js";
|
|
11
|
+
export { MemoryAttachmentQueue } from "./src/queues/memory_queue.js";
|
|
12
|
+
export { AttachmentManager, AttachmentSourceError, } from "./src/sources/attachment_manager.js";
|
|
13
|
+
export { AdonisAttachmentQueue, } from "./src/queues/adonis_queue.js";
|
|
14
|
+
export { migrateLegacyAttachment, migrateLegacyAttachmentColumn, } from "./src/integrations/lucid/migrate_legacy_attachment.js";
|
|
15
|
+
export { createAttachmentOwnerKey } from "./src/integrations/lucid/attachment_owner.js";
|
|
16
|
+
export { createAttachmentsTableStubState } from "./src/integrations/lucid/attachments_table_stub.js";
|
|
16
17
|
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAIA,OAAO,iBAAiB,MAAM,oBAAoB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAIA,OAAO,iBAAiB,MAAM,oBAAoB,CAAC;AAUnD,cAAc,qBAAqB,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,CAAC;AAC7B,OAAO,EACL,YAAY,GAGb,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,kBAAkB,EAAE,MAAM,wCAAwC,CAAC;AAC5E,OAAO,EACL,gBAAgB,GAEjB,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EACL,UAAU,GAEX,MAAM,+CAA+C,CAAC;AACvD,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB,EAClB,4BAA4B,GAE7B,MAAM,iDAAiD,CAAC;AACzD,OAAO,EACL,wBAAwB,EACxB,4BAA4B,GAG7B,MAAM,8CAA8C,CAAC;AAMtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EACL,iBAAiB,EACjB,qBAAqB,GAMtB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EACL,qBAAqB,GAItB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,uBAAuB,EACvB,6BAA6B,GAM9B,MAAM,uDAAuD,CAAC;AAC/D,OAAO,EAAE,wBAAwB,EAAE,MAAM,8CAA8C,CAAC;AACxF,OAAO,EAAE,+BAA+B,EAAE,MAAM,oDAAoD,CAAC"}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* @license MIT
|
|
5
5
|
* @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
|
|
6
6
|
*/
|
|
7
|
+
import type { AttachmentPersistenceContext, AttachmentPersistenceOptions } from './attachment_options.js';
|
|
7
8
|
export type Attachment = Readonly<{
|
|
8
9
|
id: string;
|
|
9
10
|
disk: string;
|
|
@@ -13,8 +14,13 @@ export type Attachment = Readonly<{
|
|
|
13
14
|
size: number;
|
|
14
15
|
extname: string;
|
|
15
16
|
mimeType: string;
|
|
16
|
-
metadata?: Record<string, unknown
|
|
17
|
+
metadata?: Record<string, unknown> | undefined;
|
|
17
18
|
}>;
|
|
19
|
+
export type AttachmentPersistRequest<Model = any> = {
|
|
20
|
+
options?: AttachmentPersistenceOptions<Model>;
|
|
21
|
+
context?: Omit<AttachmentPersistenceContext<Model>, 'originalName'>;
|
|
22
|
+
};
|
|
23
|
+
export type AttachmentDraftPersistence = (draft: AttachmentDraft, request?: AttachmentPersistRequest<any>) => Promise<Attachment>;
|
|
18
24
|
export type CreateAttachmentInput = {
|
|
19
25
|
body: Uint8Array;
|
|
20
26
|
originalName: string;
|
|
@@ -23,6 +29,30 @@ export type CreateAttachmentInput = {
|
|
|
23
29
|
folder?: string;
|
|
24
30
|
metadata?: Record<string, unknown>;
|
|
25
31
|
};
|
|
32
|
+
/**
|
|
33
|
+
* A source-backed attachment that has not been written to storage yet.
|
|
34
|
+
* Its public properties become final after `persist()` resolves.
|
|
35
|
+
*/
|
|
36
|
+
export declare class AttachmentDraft implements Attachment {
|
|
37
|
+
#private;
|
|
38
|
+
readonly id: string;
|
|
39
|
+
disk: string;
|
|
40
|
+
name: string;
|
|
41
|
+
originalName: string;
|
|
42
|
+
path: string;
|
|
43
|
+
size: number;
|
|
44
|
+
extname: string;
|
|
45
|
+
mimeType: string;
|
|
46
|
+
metadata?: Record<string, unknown> | undefined;
|
|
47
|
+
constructor(source: CreateAttachmentInput, provisional: Attachment, options: AttachmentPersistenceOptions, persistence: AttachmentDraftPersistence);
|
|
48
|
+
get isPersisted(): boolean;
|
|
49
|
+
get source(): Readonly<CreateAttachmentInput>;
|
|
50
|
+
get options(): Readonly<AttachmentPersistenceOptions>;
|
|
51
|
+
persist(request?: AttachmentPersistRequest<any>): Promise<Attachment>;
|
|
52
|
+
toJSON(): Attachment;
|
|
53
|
+
toAttachment(): Attachment;
|
|
54
|
+
}
|
|
55
|
+
export declare function isAttachmentDraft(value: unknown): value is AttachmentDraft;
|
|
26
56
|
export type AttachmentFactoryOptions = {
|
|
27
57
|
defaultDisk: string;
|
|
28
58
|
createId?: () => string;
|
|
@@ -30,6 +60,11 @@ export type AttachmentFactoryOptions = {
|
|
|
30
60
|
export declare class AttachmentFactory {
|
|
31
61
|
#private;
|
|
32
62
|
constructor(options: AttachmentFactoryOptions);
|
|
33
|
-
create(input: CreateAttachmentInput
|
|
63
|
+
create(input: CreateAttachmentInput, options?: {
|
|
64
|
+
id?: string;
|
|
65
|
+
name?: string;
|
|
66
|
+
disk?: string;
|
|
67
|
+
folder?: string;
|
|
68
|
+
}): Attachment;
|
|
34
69
|
}
|
|
35
70
|
//# sourceMappingURL=attachment.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attachment.d.ts","sourceRoot":"","sources":["../../../src/core/attachment.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,MAAM,MAAM,UAAU,GAAG,QAAQ,CAAC;IAChC,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,YAAY,EAAE,MAAM,CAAA;IACpB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"attachment.d.ts","sourceRoot":"","sources":["../../../src/core/attachment.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EACV,4BAA4B,EAC5B,4BAA4B,EAC7B,MAAM,yBAAyB,CAAA;AAEhC,MAAM,MAAM,UAAU,GAAG,QAAQ,CAAC;IAChC,EAAE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ACf,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAA;gBAS5C,MAAM,EAAE,qBAAqB,EAC7B,WAAW,EAAE,UAAU,EACvB,OAAO,EAAE,4BAA4B,EACrC,WAAW,EAAE,0BAA0B;IAkBzC,IAAI,WAAW,IAAI,OAAO,CAEzB;IAED,IAAI,MAAM,IAAI,QAAQ,CAAC,qBAAqB,CAAC,CAM5C;IAED,IAAI,OAAO,IAAI,QAAQ,CAAC,4BAA4B,CAAC,CAEpD;IAED,OAAO,CAAC,OAAO,CAAC,EAAE,wBAAwB,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC;IAgCrE,MAAM,IAAI,UAAU;IAQpB,YAAY,IAAI,UAAU;CAa3B;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,eAAe,CAE1E;AAED,MAAM,MAAM,wBAAwB,GAAG;IACrC,WAAW,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,EAAE,MAAM,MAAM,CAAA;CACxB,CAAA;AAED,qBAAa,iBAAiB;;gBAIhB,OAAO,EAAE,wBAAwB;IAK7C,MAAM,CACJ,KAAK,EAAE,qBAAqB,EAC5B,OAAO,GAAE;QAAE,EAAE,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAO,GAC3E,UAAU;CAkBd"}
|
|
@@ -6,6 +6,106 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { randomUUID } from 'node:crypto';
|
|
8
8
|
import { extname } from 'node:path';
|
|
9
|
+
/**
|
|
10
|
+
* A source-backed attachment that has not been written to storage yet.
|
|
11
|
+
* Its public properties become final after `persist()` resolves.
|
|
12
|
+
*/
|
|
13
|
+
export class AttachmentDraft {
|
|
14
|
+
id;
|
|
15
|
+
disk;
|
|
16
|
+
name;
|
|
17
|
+
originalName;
|
|
18
|
+
path;
|
|
19
|
+
size;
|
|
20
|
+
extname;
|
|
21
|
+
mimeType;
|
|
22
|
+
metadata;
|
|
23
|
+
#options;
|
|
24
|
+
#source;
|
|
25
|
+
#persisted = false;
|
|
26
|
+
#persisting;
|
|
27
|
+
#persistence;
|
|
28
|
+
constructor(source, provisional, options, persistence) {
|
|
29
|
+
this.id = provisional.id;
|
|
30
|
+
this.disk = provisional.disk;
|
|
31
|
+
this.name = provisional.name;
|
|
32
|
+
this.originalName = provisional.originalName;
|
|
33
|
+
this.path = provisional.path;
|
|
34
|
+
this.size = provisional.size;
|
|
35
|
+
this.extname = provisional.extname;
|
|
36
|
+
this.mimeType = provisional.mimeType;
|
|
37
|
+
if (provisional.metadata) {
|
|
38
|
+
this.metadata = provisional.metadata;
|
|
39
|
+
}
|
|
40
|
+
this.#source = source;
|
|
41
|
+
this.#options = options;
|
|
42
|
+
this.#persistence = persistence;
|
|
43
|
+
}
|
|
44
|
+
get isPersisted() {
|
|
45
|
+
return this.#persisted;
|
|
46
|
+
}
|
|
47
|
+
get source() {
|
|
48
|
+
if (!this.#source) {
|
|
49
|
+
throw new Error('Attachment draft source is no longer available after persistence');
|
|
50
|
+
}
|
|
51
|
+
return this.#source;
|
|
52
|
+
}
|
|
53
|
+
get options() {
|
|
54
|
+
return this.#options;
|
|
55
|
+
}
|
|
56
|
+
persist(request) {
|
|
57
|
+
if (this.#persisted) {
|
|
58
|
+
return Promise.resolve(this);
|
|
59
|
+
}
|
|
60
|
+
if (!this.#persisting) {
|
|
61
|
+
this.#persisting = this.#persistence(this, request)
|
|
62
|
+
.then((attachment) => {
|
|
63
|
+
this.disk = attachment.disk;
|
|
64
|
+
this.name = attachment.name;
|
|
65
|
+
this.path = attachment.path;
|
|
66
|
+
this.size = attachment.size;
|
|
67
|
+
this.extname = attachment.extname;
|
|
68
|
+
this.mimeType = attachment.mimeType;
|
|
69
|
+
if (attachment.metadata) {
|
|
70
|
+
this.metadata = attachment.metadata;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
delete this.metadata;
|
|
74
|
+
}
|
|
75
|
+
this.#source = undefined;
|
|
76
|
+
this.#persisted = true;
|
|
77
|
+
return this;
|
|
78
|
+
})
|
|
79
|
+
.catch((error) => {
|
|
80
|
+
this.#persisting = undefined;
|
|
81
|
+
throw error;
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
return this.#persisting;
|
|
85
|
+
}
|
|
86
|
+
toJSON() {
|
|
87
|
+
if (!this.#persisted) {
|
|
88
|
+
throw new Error('Attachment drafts must be persisted before serialization');
|
|
89
|
+
}
|
|
90
|
+
return this.toAttachment();
|
|
91
|
+
}
|
|
92
|
+
toAttachment() {
|
|
93
|
+
return {
|
|
94
|
+
id: this.id,
|
|
95
|
+
disk: this.disk,
|
|
96
|
+
name: this.name,
|
|
97
|
+
originalName: this.originalName,
|
|
98
|
+
path: this.path,
|
|
99
|
+
size: this.size,
|
|
100
|
+
extname: this.extname,
|
|
101
|
+
mimeType: this.mimeType,
|
|
102
|
+
...(this.metadata ? { metadata: this.metadata } : {}),
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
export function isAttachmentDraft(value) {
|
|
107
|
+
return value instanceof AttachmentDraft;
|
|
108
|
+
}
|
|
9
109
|
export class AttachmentFactory {
|
|
10
110
|
#defaultDisk;
|
|
11
111
|
#createId;
|
|
@@ -13,14 +113,14 @@ export class AttachmentFactory {
|
|
|
13
113
|
this.#defaultDisk = options.defaultDisk;
|
|
14
114
|
this.#createId = options.createId ?? randomUUID;
|
|
15
115
|
}
|
|
16
|
-
create(input) {
|
|
17
|
-
const id = this.#createId();
|
|
116
|
+
create(input, options = {}) {
|
|
117
|
+
const id = options.id ?? this.#createId();
|
|
18
118
|
const extension = getExtension(input.originalName);
|
|
19
|
-
const name = extension ? `${id}.${extension}` : id;
|
|
20
|
-
const path = joinPath(input.folder, name);
|
|
119
|
+
const name = options.name ?? (extension ? `${id}.${extension}` : id);
|
|
120
|
+
const path = joinPath(options.folder ?? input.folder, name);
|
|
21
121
|
return {
|
|
22
122
|
id,
|
|
23
|
-
disk: input.disk ?? this.#defaultDisk,
|
|
123
|
+
disk: options.disk ?? input.disk ?? this.#defaultDisk,
|
|
24
124
|
name,
|
|
25
125
|
originalName: input.originalName,
|
|
26
126
|
path,
|
|
@@ -35,6 +135,9 @@ function getExtension(fileName) {
|
|
|
35
135
|
return extname(fileName).slice(1).toLowerCase();
|
|
36
136
|
}
|
|
37
137
|
function joinPath(folder, name) {
|
|
138
|
+
if (name.includes('/') || name.includes('\\') || name === '.' || name === '..') {
|
|
139
|
+
throw new Error('Attachment names must not contain path separators');
|
|
140
|
+
}
|
|
38
141
|
if (!folder) {
|
|
39
142
|
return name;
|
|
40
143
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attachment.js","sourceRoot":"","sources":["../../../src/core/attachment.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"attachment.js","sourceRoot":"","sources":["../../../src/core/attachment.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAsCnC;;;GAGG;AACH,MAAM,OAAO,eAAe;IACjB,EAAE,CAAQ;IACnB,IAAI,CAAQ;IACZ,IAAI,CAAQ;IACZ,YAAY,CAAQ;IACpB,IAAI,CAAQ;IACZ,IAAI,CAAQ;IACZ,OAAO,CAAQ;IACf,QAAQ,CAAQ;IAChB,QAAQ,CAAsC;IAErC,QAAQ,CAA8B;IAC/C,OAAO,CAAmC;IAC1C,UAAU,GAAG,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,32 @@
|
|
|
1
|
+
export type AttachmentPersistenceContext<Model = unknown> = {
|
|
2
|
+
model?: Model;
|
|
3
|
+
field?: string;
|
|
4
|
+
originalName: string;
|
|
5
|
+
};
|
|
6
|
+
export type AttachmentFolder<Model = unknown> = string | ((context: AttachmentPersistenceContext<Model>) => string | Promise<string>);
|
|
7
|
+
export type AttachmentRename<Model = unknown> = boolean | ((context: AttachmentPersistenceContext<Model>) => string | Promise<string>);
|
|
8
|
+
/**
|
|
9
|
+
* File-persistence settings. `null` explicitly disables an inherited setting.
|
|
10
|
+
*/
|
|
11
|
+
export type AttachmentPersistenceOptions<Model = unknown> = {
|
|
12
|
+
disk?: string | null;
|
|
13
|
+
folder?: AttachmentFolder<Model> | null;
|
|
14
|
+
rename?: AttachmentRename<Model> | null;
|
|
15
|
+
meta?: boolean | null;
|
|
16
|
+
preComputeUrl?: boolean | null;
|
|
17
|
+
variants?: readonly string[] | null;
|
|
18
|
+
};
|
|
19
|
+
export type ResolvedAttachmentPersistenceOptions<Model = unknown> = {
|
|
20
|
+
disk?: string;
|
|
21
|
+
folder?: AttachmentFolder<Model>;
|
|
22
|
+
rename?: AttachmentRename<Model>;
|
|
23
|
+
meta?: boolean;
|
|
24
|
+
preComputeUrl?: boolean;
|
|
25
|
+
variants?: readonly string[];
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Resolves options from lowest to highest priority. An explicit `null` clears
|
|
29
|
+
* the inherited value for one setting.
|
|
30
|
+
*/
|
|
31
|
+
export declare function resolveAttachmentPersistenceOptions<Model = unknown>(...layers: ReadonlyArray<AttachmentPersistenceOptions<Model> | undefined>): ResolvedAttachmentPersistenceOptions<Model>;
|
|
32
|
+
//# sourceMappingURL=attachment_options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attachment_options.d.ts","sourceRoot":"","sources":["../../../src/core/attachment_options.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,4BAA4B,CAAC,KAAK,GAA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AA;AAED;;;GAGG;AACH,wBAAgB,mCAAmC,CAAC,KAAK,GAAG,OAAO,EACjE,GAAG,MAAM,EAAE,aAAa,CAAC,4BAA4B,CAAC,KAAK,CAAC,GAAG,SAAS,CAAC,GACxE,oCAAoC,CAAC,KAAK,CAAC,CAS7C"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolves options from lowest to highest priority. An explicit `null` clears
|
|
3
|
+
* the inherited value for one setting.
|
|
4
|
+
*/
|
|
5
|
+
export function resolveAttachmentPersistenceOptions(...layers) {
|
|
6
|
+
return {
|
|
7
|
+
...resolveOption('disk', layers),
|
|
8
|
+
...resolveOption('folder', layers),
|
|
9
|
+
...resolveOption('rename', layers),
|
|
10
|
+
...resolveOption('meta', layers),
|
|
11
|
+
...resolveOption('preComputeUrl', layers),
|
|
12
|
+
...resolveOption('variants', layers),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function resolveOption(key, layers) {
|
|
16
|
+
for (const layer of [...layers].reverse()) {
|
|
17
|
+
const value = layer?.[key];
|
|
18
|
+
if (value !== undefined) {
|
|
19
|
+
return value === null ? {} : { [key]: value };
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return {};
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=attachment_options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attachment_options.js","sourceRoot":"","sources":["../../../src/core/attachment_options.ts"],"names":[],"mappings":"AAmCA;;;GAGG;AACH,MAAM,UAAU,mCAAmC,CACjD,GAAG,MAAsE;IAEzE,OAAO;QACL,GAAG,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC;QAChC,GAAG,aAAa,CAAC,QAAQ,EAAE,MAAM,CAAC;QAClC,GAAG,aAAa,CAAC,QAAQ,EAAE,MAAM,CAAC;QAClC,GAAG,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC;QAChC,GAAG,aAAa,CAAC,eAAe,EAAE,MAAM,CAAC;QACzC,GAAG,aAAa,CAAC,UAAU,EAAE,MAAM,CAAC;KACrC,CAAA;AACH,CAAC;AAED,SAAS,aAAa,CACpB,GAAQ,EACR,MAAsE;IAEtE,KAAK,MAAM,KAAK,IAAI,CAAC,GAAG,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC;QAC1C,MAAM,KAAK,GAAG,KAAK,EAAE,CAAC,GAAG,CAAC,CAAA;QAE1B,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,OAAO,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,CAAA;QAC/C,CAAC;IACH,CAAC;IAED,OAAO,EAAE,CAAA;AACX,CAAC"}
|
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
* @license MIT
|
|
5
5
|
* @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
|
|
6
6
|
*/
|
|
7
|
-
import { type Attachment, type CreateAttachmentInput } from './attachment.js';
|
|
7
|
+
import { AttachmentDraft, type Attachment, type CreateAttachmentInput } from './attachment.js';
|
|
8
|
+
import { type AttachmentPersistenceOptions } from './attachment_options.js';
|
|
8
9
|
import type { AttachmentQueue } from './queue.js';
|
|
9
10
|
import type { AttachmentStorage } from './storage.js';
|
|
10
11
|
export type AttachmentServiceOptions = {
|
|
@@ -12,6 +13,7 @@ export type AttachmentServiceOptions = {
|
|
|
12
13
|
queue: AttachmentQueue;
|
|
13
14
|
defaultDisk: string;
|
|
14
15
|
createId?: () => string;
|
|
16
|
+
defaults?: AttachmentPersistenceOptions;
|
|
15
17
|
};
|
|
16
18
|
/**
|
|
17
19
|
* Creates files and delegates persistence to the configured storage backend.
|
|
@@ -20,6 +22,10 @@ export type AttachmentServiceOptions = {
|
|
|
20
22
|
export declare class AttachmentService {
|
|
21
23
|
#private;
|
|
22
24
|
constructor(options: AttachmentServiceOptions);
|
|
25
|
+
createDraft(input: CreateAttachmentInput, options?: AttachmentPersistenceOptions): AttachmentDraft;
|
|
26
|
+
/**
|
|
27
|
+
* Backward-compatible immediate persistence for direct service consumers.
|
|
28
|
+
*/
|
|
23
29
|
create(input: CreateAttachmentInput): Promise<Attachment>;
|
|
24
30
|
remove(attachment: Attachment): Promise<void>;
|
|
25
31
|
read(attachment: Attachment): Promise<Uint8Array>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attachment_service.d.ts","sourceRoot":"","sources":["../../../src/core/attachment_service.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"attachment_service.d.ts","sourceRoot":"","sources":["../../../src/core/attachment_service.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,eAAe,EAEf,KAAK,UAAU,EAEf,KAAK,qBAAqB,EAC3B,MAAM,iBAAiB,CAAA;AAExB,OAAO,EAIL,KAAK,4BAA4B,EAElC,MAAM,yBAAyB,CAAA;AAChC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AACjD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAErD,MAAM,MAAM,wBAAwB,GAAG;IACrC,OAAO,EAAE,iBAAiB,CAAA;IAC1B,KAAK,EAAE,eAAe,CAAA;IACtB,WAAW,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,EAAE,MAAM,MAAM,CAAA;IACvB,QAAQ,CAAC,EAAE,4BAA4B,CAAA;CACxC,CAAA;AAED;;;GAGG;AACH,qBAAa,iBAAiB;;gBAMhB,OAAO,EAAE,wBAAwB;IAO7C,WAAW,CACT,KAAK,EAAE,qBAAqB,EAC5B,OAAO,GAAE,4BAAiC,GACzC,eAAe;IAgBlB;;OAEG;IACG,MAAM,CAAC,KAAK,EAAE,qBAAqB,GAAG,OAAO,CAAC,UAAU,CAAC;IAmC/D,MAAM,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAI7C,IAAI,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IAIjD,yBAAyB,CACvB,UAAU,EAAE,UAAU,EACtB,WAAW,CAAC,EAAE,SAAS,MAAM,EAAE,GAC9B,OAAO,CAAC,IAAI,CAAC;CAOjB"}
|
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
* @license MIT
|
|
5
5
|
* @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
|
|
6
6
|
*/
|
|
7
|
-
import { AttachmentFactory, } from './attachment.js';
|
|
7
|
+
import { AttachmentDraft, AttachmentFactory, } from './attachment.js';
|
|
8
8
|
import { markAttachmentPending } from './attachment_state.js';
|
|
9
|
+
import { resolveAttachmentPersistenceOptions, } from './attachment_options.js';
|
|
9
10
|
/**
|
|
10
11
|
* Creates files and delegates persistence to the configured storage backend.
|
|
11
12
|
* Database persistence deliberately remains the responsibility of the caller.
|
|
@@ -14,20 +15,53 @@ export class AttachmentService {
|
|
|
14
15
|
#storage;
|
|
15
16
|
#queue;
|
|
16
17
|
#factory;
|
|
18
|
+
#defaults;
|
|
17
19
|
constructor(options) {
|
|
18
20
|
this.#storage = options.storage;
|
|
19
21
|
this.#queue = options.queue;
|
|
20
22
|
this.#factory = new AttachmentFactory(options);
|
|
23
|
+
this.#defaults = options.defaults ?? {};
|
|
21
24
|
}
|
|
25
|
+
createDraft(input, options = {}) {
|
|
26
|
+
const draftOptions = {
|
|
27
|
+
...(input.disk !== undefined ? { disk: input.disk } : {}),
|
|
28
|
+
...(input.folder !== undefined ? { folder: input.folder } : {}),
|
|
29
|
+
...options,
|
|
30
|
+
};
|
|
31
|
+
const provisional = this.#factory.create(input, {
|
|
32
|
+
...(typeof draftOptions.disk === 'string' ? { disk: draftOptions.disk } : {}),
|
|
33
|
+
...(typeof draftOptions.folder === 'string' ? { folder: draftOptions.folder } : {}),
|
|
34
|
+
});
|
|
35
|
+
return new AttachmentDraft(input, provisional, draftOptions, (draft, request) => this.#persistDraft(draft, request));
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Backward-compatible immediate persistence for direct service consumers.
|
|
39
|
+
*/
|
|
22
40
|
async create(input) {
|
|
23
|
-
|
|
41
|
+
return this.createDraft(input).persist();
|
|
42
|
+
}
|
|
43
|
+
async #persistDraft(draft, request) {
|
|
44
|
+
const source = draft.source;
|
|
45
|
+
const context = {
|
|
46
|
+
...request?.context,
|
|
47
|
+
originalName: source.originalName,
|
|
48
|
+
};
|
|
49
|
+
const options = resolveAttachmentPersistenceOptions(this.#defaults, request?.options, draft.options);
|
|
50
|
+
const folder = await resolveFolder(options.folder, context);
|
|
51
|
+
const name = await resolveName(options.rename, context);
|
|
52
|
+
const attachment = this.#factory.create(source, {
|
|
53
|
+
id: draft.id,
|
|
54
|
+
...(options.disk ? { disk: options.disk } : {}),
|
|
55
|
+
...(folder ? { folder } : {}),
|
|
56
|
+
...(name ? { name } : {}),
|
|
57
|
+
});
|
|
24
58
|
await this.#storage.write({
|
|
25
59
|
disk: attachment.disk,
|
|
26
60
|
path: attachment.path,
|
|
27
|
-
body:
|
|
61
|
+
body: source.body,
|
|
28
62
|
mimeType: attachment.mimeType,
|
|
29
63
|
});
|
|
30
|
-
markAttachmentPending(
|
|
64
|
+
markAttachmentPending(draft);
|
|
31
65
|
return attachment;
|
|
32
66
|
}
|
|
33
67
|
remove(attachment) {
|
|
@@ -44,4 +78,16 @@ export class AttachmentService {
|
|
|
44
78
|
});
|
|
45
79
|
}
|
|
46
80
|
}
|
|
81
|
+
async function resolveFolder(folder, context) {
|
|
82
|
+
if (typeof folder === 'function') {
|
|
83
|
+
return folder(context);
|
|
84
|
+
}
|
|
85
|
+
return folder;
|
|
86
|
+
}
|
|
87
|
+
async function resolveName(rename, context) {
|
|
88
|
+
if (typeof rename === 'function') {
|
|
89
|
+
return rename(context);
|
|
90
|
+
}
|
|
91
|
+
return rename === false ? context.originalName : undefined;
|
|
92
|
+
}
|
|
47
93
|
//# sourceMappingURL=attachment_service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attachment_service.js","sourceRoot":"","sources":["../../../src/core/attachment_service.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,iBAAiB,
|
|
1
|
+
{"version":3,"file":"attachment_service.js","sourceRoot":"","sources":["../../../src/core/attachment_service.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,eAAe,EACf,iBAAiB,GAIlB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAA;AAC7D,OAAO,EACL,mCAAmC,GAKpC,MAAM,yBAAyB,CAAA;AAYhC;;;GAGG;AACH,MAAM,OAAO,iBAAiB;IACnB,QAAQ,CAAmB;IAC3B,MAAM,CAAiB;IACvB,QAAQ,CAAmB;IAC3B,SAAS,CAA8B;IAEhD,YAAY,OAAiC;QAC3C,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAA;QAC/B,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,KAAK,CAAA;QAC3B,IAAI,CAAC,QAAQ,GAAG,IAAI,iBAAiB,CAAC,OAAO,CAAC,CAAA;QAC9C,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,QAAQ,IAAI,EAAE,CAAA;IACzC,CAAC;IAED,WAAW,CACT,KAA4B,EAC5B,UAAwC,EAAE;QAE1C,MAAM,YAAY,GAAG;YACnB,GAAG,CAAC,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACzD,GAAG,CAAC,KAAK,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAC/D,GAAG,OAAO;SACX,CAAA;QAC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;CACF;AAED,KAAK,UAAU,aAAa,CAC1B,MAAoC,EACpC,OAAqC;IAErC,IAAI,OAAO,MAAM,KAAK,UAAU,EAAE,CAAC;QACjC,OAAO,MAAM,CAAC,OAAO,CAAC,CAAA;IACxB,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC;AAED,KAAK,UAAU,WAAW,CACxB,MAAoC,EACpC,OAAqC;IAErC,IAAI,OAAO,MAAM,KAAK,UAAU,EAAE,CAAC;QACjC,OAAO,MAAM,CAAC,OAAO,CAAC,CAAA;IACxB,CAAC;IAED,OAAO,MAAM,KAAK,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS,CAAA;AAC5D,CAAC"}
|
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
* @license MIT
|
|
5
5
|
* @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
|
|
6
6
|
*/
|
|
7
|
-
export { AttachmentFactory, type Attachment, type AttachmentFactoryOptions, type CreateAttachmentInput, } from './attachment.js';
|
|
7
|
+
export { AttachmentFactory, AttachmentDraft, isAttachmentDraft, type Attachment, type AttachmentDraftPersistence, type AttachmentFactoryOptions, type AttachmentPersistRequest, type CreateAttachmentInput, } from './attachment.js';
|
|
8
|
+
export { resolveAttachmentPersistenceOptions, type AttachmentFolder, type AttachmentPersistenceContext, type AttachmentPersistenceOptions, type AttachmentRename, type ResolvedAttachmentPersistenceOptions, } from './attachment_options.js';
|
|
8
9
|
export { AttachmentService, type AttachmentServiceOptions } from './attachment_service.js';
|
|
9
10
|
export { AttachmentJobProcessor, AttachmentNotFoundError, type AttachmentJobProcessorOptions, type VariantGenerationRequest, type VariantGenerator, type VariantGeneratorFactory, } from './attachment_job_processor.js';
|
|
10
11
|
export { type AttachmentRepository } from './attachment_repository.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/index.ts"],"names":[],"mappings":"AAAA;;;;;GA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uB,GAC7B,MAAM,+BAA+B,CAAA;AACtC,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,4BAA4B,CAAA;AACtE,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACpB,KAAK,mBAAmB,GACzB,MAAM,YAAY,CAAA;AACnB,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,oBAAoB,GAC1B,MAAM,cAAc,CAAA"}
|
package/build/src/core/index.js
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
* @license MIT
|
|
5
5
|
* @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
|
|
6
6
|
*/
|
|
7
|
-
export { AttachmentFactory, } from './attachment.js';
|
|
7
|
+
export { AttachmentFactory, AttachmentDraft, isAttachmentDraft, } from './attachment.js';
|
|
8
|
+
export { resolveAttachmentPersistenceOptions, } from './attachment_options.js';
|
|
8
9
|
export { AttachmentService } from './attachment_service.js';
|
|
9
10
|
export { AttachmentJobProcessor, AttachmentNotFoundError, } from './attachment_job_processor.js';
|
|
10
11
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,iBAAiB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,iBAAiB,GAMlB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EACL,mCAAmC,GAMpC,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,iBAAiB,EAAiC,MAAM,yBAAyB,CAAA;AAC1F,OAAO,EACL,sBAAsB,EACtB,uBAAuB,GAKxB,MAAM,+BAA+B,CAAA"}
|
|
@@ -11,6 +11,7 @@ import type { AttachmentRepository } from './core/attachment_repository.js';
|
|
|
11
11
|
import type { AttachmentJobHandler, AttachmentQueue } from './core/queue.js';
|
|
12
12
|
import type { AttachmentStorage } from './core/storage.js';
|
|
13
13
|
import type { AttachmentManagerOptions } from './sources/attachment_manager.js';
|
|
14
|
+
import type { AttachmentPersistenceOptions } from './core/attachment_options.js';
|
|
14
15
|
type Integration<T> = T | ((app: ApplicationService) => T | Promise<T>);
|
|
15
16
|
export type AttachmentRouteConfig = false | {
|
|
16
17
|
prefix?: string;
|
|
@@ -26,6 +27,8 @@ export type AttachmentConfig = {
|
|
|
26
27
|
jobHandler?: Integration<AttachmentJobHandler>;
|
|
27
28
|
processor?: Integration<AttachmentJobProcessor>;
|
|
28
29
|
repository?: Integration<AttachmentRepository>;
|
|
30
|
+
/** Lowest-priority defaults for file persistence. */
|
|
31
|
+
defaults?: AttachmentPersistenceOptions;
|
|
29
32
|
sources?: AttachmentManagerOptions;
|
|
30
33
|
route?: AttachmentRouteConfig;
|
|
31
34
|
queueConcurrency?: number;
|
|
@@ -33,6 +36,7 @@ export type AttachmentConfig = {
|
|
|
33
36
|
};
|
|
34
37
|
export type ResolvedAttachmentConfig = AttachmentServiceOptions & {
|
|
35
38
|
repository?: AttachmentRepository;
|
|
39
|
+
defaults?: AttachmentPersistenceOptions;
|
|
36
40
|
sources?: AttachmentManagerOptions;
|
|
37
41
|
route: ResolvedAttachmentRouteConfig | false;
|
|
38
42
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define_config.d.ts","sourceRoot":"","sources":["../../src/define_config.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC9E,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAA;AAC5E,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAA;AAChF,OAAO,KAAK,EAAE,oBAAoB,EAA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,iBAAiB,CAAC,CAAA;IACvC,KAAK,CAAC,EAAE,WAAW,CAAC,eAAe,CAAC,CAAA;IACpC,UAAU,CAAC,EAAE,WAAW,CAAC,oBAAoB,CAAC,CAAA;IAC9C,SAAS,CAAC,EAAE,WAAW,CAAC,sBAAsB,CAAC,CAAA;IAC/C,UAAU,CAAC,EAAE,WAAW,CAAC,oBAAoB,CAAC,CAAA;IAC9C,qDAAqD;IACrD,QAAQ,CAAC,EAAE,4BAA4B,CAAA;IACvC,OAAO,CAAC,EAAE,wBAAwB,CAAA;IAClC,KAAK,CAAC,EAAE,qBAAqB,CAAA;IAC7B,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,EAAE,MAAM,MAAM,CAAA;CACxB,CAAA;AAED,MAAM,MAAM,wBAAwB,GAAG,wBAAwB,GAAG;IAChE,UAAU,CAAC,EAAE,oBAAoB,CAAA;IACjC,QAAQ,CAAC,EAAE,4BAA4B,CAAA;IACvC,OAAO,CAAC,EAAE,wBAAwB,CAAA;IAClC,KAAK,EAAE,6BAA6B,GAAG,KAAK,CAAA;CAC7C,CAAA;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,gBAAgB,GAAG,cAAc,CAAC,wBAAwB,CAAC,CA8B/F"}
|
|
@@ -33,6 +33,7 @@ export function defineConfig(config) {
|
|
|
33
33
|
...(config.repository
|
|
34
34
|
? { repository: await resolveIntegration(config.repository, app) }
|
|
35
35
|
: {}),
|
|
36
|
+
...(config.defaults ? { defaults: config.defaults } : {}),
|
|
36
37
|
...(config.sources ? { sources: config.sources } : {}),
|
|
37
38
|
...(config.createId ? { createId: config.createId } : {}),
|
|
38
39
|
};
|