/** * States DB in memory - Server * * Copyright 2013-2024 bluefox * * MIT License * */ import type { InternalLogger } from '@iobroker/js-controller-common-db/tools'; export interface ConnectionOptions { pass?: string; sentinelName?: string; /** array on sentinel */ host: string | string[]; /** array on sentinel */ port: number | number[]; options: Record; enhancedLogging?: boolean; backup?: BackupOptions; /** relative path to the data dir */ dataDir?: string; } type ChangeFunction = (id: string, state: any) => void; export interface DbStatus { type: string; server: boolean; } interface BackupOptions { /** deactivates backup if true */ disabled: boolean; /** minimum number of files */ files: number; hours: number; /** minutes */ period: number; path: string; } export interface DbOptions { backupDirName: string; fileName: string; } interface FileDbSettings { fileDB: DbOptions; jsonlDB: DbOptions; backup: BackupOptions; change?: ChangeFunction; connected: (nameOfServer: string) => void; logger: InternalLogger; connection: ConnectionOptions; /** unused */ auth?: null; secure: boolean; /** as required by createServer TODO: if createServer is typed, add type */ certificates: any; port: number; host: string; /** logging namespace */ namespace?: string; } interface Subscription { pattern: string; regex: RegExp; options: any; } interface SubscriptionClient { _subscribe?: Record; } /** * The parent of the class structure, which provides basic JSON storage * and general subscription and publish functionality */ export declare class InMemoryFileDB { private settings; private readonly change; protected dataset: Record; private readonly namespace; private lastSave; private stateTimer; private callbackSubscriptionClient; private readonly dataDir; private readonly datasetName; private log; private readonly backupDir; constructor(settings: FileDbSettings); open(): Promise; /** * Loads a dataset file * * @param datasetName Filename of the file to load * @returns obj read data, normally as object */ loadDatasetFile(datasetName: string): Promise>; /** * Loads the dataset including pot. Fallback handling * * @param datasetName Filename of the file to load * @returns obj dataset read as object */ loadDataset(datasetName: string): Promise>; initBackupDir(): void; handleSubscribe(client: SubscriptionClient, type: string, pattern: string | string[], cb?: () => void): void; handleSubscribe(client: SubscriptionClient, type: string, pattern: string | string[], options: any, cb?: () => void): void; handleUnsubscribe(client: SubscriptionClient, type: string, pattern: string | string[], cb?: () => void): void | Promise; publishToClients(_client: SubscriptionClient, _type: string, _id: string, _obj: any): number; deleteOldBackupFiles(baseFilename: string): void; getTimeStr(date: number): string; /** * Handle saving the dataset incl. backups */ saveState(): Promise; /** * Saves the dataset into File incl. handling of a fallback backup file * * @returns dataset JSON string of the complete dataset to also be stored into a compressed backup file */ saveDataset(): Promise; /** * Stores a compressed backup of the DB in definable intervals * * @param jsonString JSON string of the complete dataset to also be stored into a compressed backup file */ saveBackup(jsonString: string): void; getStatus(): DbStatus; getClients(): Record; publishAll(type: string, id: string, obj: any): number; destroy(): Promise; } export {}; //# sourceMappingURL=inMemFileDB.d.ts.map