alepha@docs:~/docs/packages/alepha$
cat bucket.md
2 min read
Last commit:

#Alepha - Bucket

#Installation

Part of the alepha package. Import from alepha/bucket.

npm install alepha

#Overview

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.

#API Reference

#Primitives

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.

#$bucket()

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

  • Multi-provider support (filesystem, cloud storage, in-memory)
  • Automatic MIME type and file size validation
  • Event integration for file operations monitoring
  • Flexible per-bucket and per-operation configuration
  • Smart file type and size detection

Common Use Cases

  • User profile pictures and document uploads
  • Product images and media management
  • Document storage and retrieval systems
ts
 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}
On This Page
No headings found...
ready
mainTypeScript
UTF-8packages_alepha_bucket.md