digitaltwin-core
Version:
Minimalist framework to collect and handle data in a Digital Twin project
88 lines • 3.07 kB
TypeScript
/**
* Abstract base class for storage service implementations.
*
* Defines the contract for persisting and retrieving binary data in the Digital Twin framework.
* Concrete implementations provide storage backends like local filesystem, AWS S3, Azure Blob, etc.
*
* @abstract
* @class StorageService
*
* @example
* ```typescript
* // Implement for specific storage backend
* class S3StorageService extends StorageService {
* async save(buffer: Buffer, collectorName: string, extension?: string): Promise<string> {
* // Upload to S3 bucket
* return 's3://bucket/path/to/file'
* }
*
* async retrieve(path: string): Promise<Buffer> {
* // Download from S3
* return buffer
* }
*
* async delete(path: string): Promise<void> {
* // Delete from S3
* }
* }
* ```
*/
export declare abstract class StorageService {
/**
* Persists binary data and returns a unique identifier for retrieval.
*
* The storage implementation should ensure the returned path/URL is unique
* and can be used later to retrieve the exact same data.
*
* @abstract
* @param {Buffer} buffer - Binary data to store
* @param {string} collectorName - Component name for organizing storage (used as folder/prefix)
* @param {string} extension - Optional file extension for proper content handling
* @returns {Promise<string>} Unique storage identifier (path, URL, or key)
* @throws {Error} When storage operation fails
*
* @example
* ```typescript
* const buffer = Buffer.from('{"temperature": 23.5}')
* const path = await storage.save(buffer, 'weather-sensor', 'json')
* // Returns: '/storage/weather-sensor/2024-01-15_14-30-00.json'
* ```
*/
abstract save(buffer: Buffer, collectorName: string, extension?: string): Promise<string>;
/**
* Retrieves previously stored binary data.
*
* Uses the identifier returned by save() to fetch the original data.
*
* @abstract
* @param {string} path - Storage identifier from save() operation
* @returns {Promise<Buffer>} The original binary data
* @throws {Error} When file doesn't exist or retrieval fails
*
* @example
* ```typescript
* const path = '/storage/weather-sensor/2024-01-15_14-30-00.json'
* const data = await storage.retrieve(path)
* const json = JSON.parse(data.toString())
* ```
*/
abstract retrieve(path: string): Promise<Buffer>;
/**
* Removes stored data permanently.
*
* Deletes the data associated with the given storage identifier.
*
* @abstract
* @param {string} path - Storage identifier from save() operation
* @returns {Promise<void>}
* @throws {Error} When deletion fails or path doesn't exist
*
* @example
* ```typescript
* const path = '/storage/weather-sensor/old-data.json'
* await storage.delete(path)
* ```
*/
abstract delete(path: string): Promise<void>;
}
//# sourceMappingURL=storage_service.d.ts.map