digitaltwin-core
Version:
Minimalist framework to collect and handle data in a Digital Twin project
99 lines • 4.61 kB
TypeScript
import type { DataRecord } from '../types/data_record.js';
/**
* Structure used to store metadata about a data blob in the database.
*
* Extended to support asset-specific fields for AssetsManager components.
* These fields are optional and only used by AssetsManager instances.
*/
export interface MetadataRow {
/** Unique identifier of the data row */
id?: number;
/** Logical name of the data source (usually the collector name) */
name: string;
/** MIME type of the associated blob (e.g. 'application/json') */
type: string;
/** Path or URL where the blob is stored (resolved by the StorageService) */
url: string;
/** Timestamp indicating when the data was collected */
date: Date;
/** Human-readable description of the asset (AssetsManager only) */
description?: string;
/** Source URL for data provenance (AssetsManager only) */
source?: string;
/** ID of the user who owns this asset (AssetsManager only) */
owner_id?: string | null;
/** Original filename provided by the user (AssetsManager only) */
filename?: string;
}
/**
* Extended abstraction for the database layer with advanced querying capabilities.
*/
export declare abstract class DatabaseAdapter {
abstract save(meta: MetadataRow): Promise<DataRecord>;
abstract delete(id: string, name: string): Promise<void>;
abstract getById(id: string, name: string): Promise<DataRecord | undefined>;
abstract getLatestByName(name: string): Promise<DataRecord | undefined>;
abstract doesTableExists(name: string): Promise<boolean>;
abstract createTable(name: string): Promise<void>;
/**
* Get the first (oldest) record for a given component name.
* @param name - The component name
* @returns The oldest DataRecord or undefined if none found
*/
abstract getFirstByName(name: string): Promise<DataRecord | undefined>;
/**
* Get records between two dates for a given component.
* @param name - The component name
* @param startDate - Start date (inclusive)
* @param endDate - End date (exclusive), optional
* @param limit - Maximum number of records to return, optional
* @returns Array of DataRecords matching the criteria
*/
abstract getByDateRange(name: string, startDate: Date, endDate?: Date, limit?: number): Promise<DataRecord[]>;
/**
* Get records after a specific date for a given component.
* @param name - The component name
* @param afterDate - Date to search after (exclusive)
* @param limit - Maximum number of records to return
* @returns Array of DataRecords after the specified date
*/
abstract getAfterDate(name: string, afterDate: Date, limit?: number): Promise<DataRecord[]>;
/**
* Get the latest record before a specific date for a given component.
* @param name - The component name
* @param beforeDate - Date to search before (exclusive)
* @returns The latest DataRecord before the date, or undefined if none found
*/
abstract getLatestBefore(name: string, beforeDate: Date): Promise<DataRecord | undefined>;
/**
* Get the latest N records before a specific date for a given component.
* @param name - The component name
* @param beforeDate - Date to search before (exclusive)
* @param limit - Number of records to return
* @returns Array of the latest DataRecords before the date
*/
abstract getLatestRecordsBefore(name: string, beforeDate: Date, limit: number): Promise<DataRecord[]>;
/**
* Check if any records exist after a specific date for a given component.
* @param name - The component name
* @param afterDate - Date to check after (exclusive)
* @returns True if records exist after the date, false otherwise
*/
abstract hasRecordsAfterDate(name: string, afterDate: Date): Promise<boolean>;
/**
* Count records for a given component within a date range.
* @param name - The component name
* @param startDate - Start date (inclusive)
* @param endDate - End date (exclusive), optional
* @returns Number of records in the range
*/
abstract countByDateRange(name: string, startDate: Date, endDate?: Date): Promise<number>;
/**
* Closes all database connections gracefully.
* This method should be called when shutting down the application
* to ensure proper cleanup of connection pools.
* @returns Promise that resolves when all connections are closed
*/
abstract close(): Promise<void>;
}
//# sourceMappingURL=database_adapter.d.ts.map