najm-storage
v1.1.13
Published
File storage plugin for najm framework — local filesystem and database backends
Readme
najm-storage
Storage plugin for Najm with local and database providers.
Installation
bun add najm-storagezod is a peer dependency and should be installed in the consuming app.
Core Exports
storage(config)plugin factoryStorageService,StorageValidator- File helpers:
resolveStorageMimeType,analyzeFile,getReadableFileSize - Path helpers:
normalizeStoragePath,isSafeStoragePath,assertSafeStoragePath - Upload validation:
validateUploadInput - Schemas:
storageNamespaceSchema,storagePathSchema,storageUploadSchema - DTO mapper:
toStorageFileDto
StorageService Convenience Methods
getInfoOrThrow(namespace, filePath, message?)deleteOrThrow(namespace, filePath, message?)saveBase64(namespace, filePath, base64, mimeType?)
Example
import {
resolveStorageMimeType,
normalizeStoragePath,
validateUploadInput,
} from 'najm-storage';
const path = normalizeStoragePath('icons%2Flogo.png');
const mimeType = resolveStorageMimeType(undefined, path);
const result = validateUploadInput({ filePath: path, mimeType, size: 2048 });
if (!result.valid) {
throw new Error(result.error);
}