All files / src/storage types.ts

100% Statements 3/3
100% Branches 0/0
100% Functions 0/0
100% Lines 3/3

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123                                                                                                                                                                                          2x         2x                         2x                      
/**
 * Storage configuration and types for Rebase backend
 */
 
import { StorageSource, UploadFileProps, UploadFileResult, DownloadConfig, StorageListResult, StorageReference } from "@rebasepro/types";
 
/**
 * Local filesystem storage configuration
 */
export interface LocalStorageConfig {
    type: 'local';
    /** Base directory for file storage (e.g., './uploads') */
    basePath: string;
    /** Maximum file size in bytes (default: 50MB) */
    maxFileSize?: number;
    /** Allowed MIME types (if not set, all types allowed) */
    allowedMimeTypes?: string[];
    /** Base URL for generating download URLs (default: auto-detected from request) */
    baseUrl?: string;
}
 
/**
 * S3-compatible storage configuration (works with AWS S3 and MinIO)
 */
export interface S3StorageConfig {
    type: 's3';
    /** S3 bucket name */
    bucket: string;
    /** AWS region (e.g., 'us-east-1') */
    region?: string;
    /** Custom endpoint URL (required for MinIO) */
    endpoint?: string;
    /** AWS access key ID */
    accessKeyId: string;
    /** AWS secret access key */
    secretAccessKey: string;
    /** Use path-style URLs (required for MinIO) */
    forcePathStyle?: boolean;
    /** Maximum file size in bytes (default: 50MB) */
    maxFileSize?: number;
    /** Allowed MIME types (if not set, all types allowed) */
    allowedMimeTypes?: string[];
    /** URL expiration time in seconds for signed URLs (default: 3600) */
    signedUrlExpiration?: number;
}
 
/**
 * Storage configuration - either local filesystem or S3-compatible
 */
export type BackendStorageConfig = LocalStorageConfig | S3StorageConfig;
 
/**
 * Storage controller interface for backend implementations
 */
export interface StorageController {
    /**
     * Upload a file
     */
    uploadFile(props: UploadFileProps): Promise<UploadFileResult>;
 
    /**
     * Get a download URL for a file
     */
    getDownloadURL(path: string, bucket?: string): Promise<DownloadConfig>;
 
    /**
     * Get file as a File object
     */
    getFile(path: string, bucket?: string): Promise<File | null>;
 
    /**
     * Delete a file
     */
    deleteFile(path: string, bucket?: string): Promise<void>;
 
    /**
     * List files in a path
     */
    list(path: string, options?: {
        bucket?: string;
        maxResults?: number;
        pageToken?: string;
    }): Promise<StorageListResult>;
 
    /**
     * Get the storage configuration type
     */
    getType(): 'local' | 's3';
}
 
/**
 * Default maximum file size (50MB)
 */
export const DEFAULT_MAX_FILE_SIZE = 50 * 1024 * 1024;
 
/**
 * Common image MIME types
 */
export const IMAGE_MIME_TYPES = [
    'image/jpeg',
    'image/png',
    'image/gif',
    'image/webp',
    'image/svg+xml',
    'image/bmp',
    'image/tiff'
];
 
/**
 * Common document MIME types
 */
export const DOCUMENT_MIME_TYPES = [
    'application/pdf',
    'application/msword',
    'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
    'application/vnd.ms-excel',
    'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
    'application/vnd.ms-powerpoint',
    'application/vnd.openxmlformats-officedocument.presentationml.presentation',
    'text/plain',
    'text/csv'
];