Part of the alepha package. Import from alepha/bucket.
npm install alepha
Provides file storage capabilities through declarative bucket primitives with support for multiple storage backends.
The bucket module enables unified file operations across different storage systems using the $bucket primitive
on class properties. It abstracts storage provider differences, offering consistent APIs for local filesystem,
cloud storage, or in-memory storage for testing environments.
Primitives are functions that define and configure various aspects of your application. They follow the convention of starting with $ and return configured primitive instances.
For more details, see the Primitives documentation.
Creates a bucket primitive for file storage and management with configurable validation.
Provides a comprehensive file storage system that handles uploads, downloads, validation, and management across multiple storage backends with MIME type and size limit controls.
Key Features
Common Use Cases
1class MediaService { 2 images = $bucket({ 3 name: "user-images", 4 mimeTypes: ["image/jpeg", "image/png", "image/gif"], 5 maxSize: 5 // 5MB limit 6 }); 7 8 documents = $bucket({ 9 name: "documents",10 mimeTypes: ["application/pdf", "text/plain"],11 maxSize: 50 // 50MB limit12 });13 14 async uploadProfileImage(file: FileLike, userId: string): Promise<string> {15 const fileId = await this.images.upload(file);16 await this.userService.updateProfileImage(userId, fileId);17 return fileId;18 }19 20 async downloadDocument(documentId: string): Promise<FileLike> {21 return await this.documents.download(documentId);22 }23 24 async deleteDocument(documentId: string): Promise<void> {25 await this.documents.delete(documentId);26 }27}