@iobroker/db-base
Version:
This Library contains base classes that are used by the database classes for ioBroker
129 lines • 4.07 kB
TypeScript
/**
* States DB in memory - Server
*
* Copyright 2013-2024 bluefox <dogafox@gmail.com>
*
* 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<string, any>;
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<string, Subscription[]>;
}
/**
* 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<string, any>;
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<void>;
/**
* Loads a dataset file
*
* @param datasetName Filename of the file to load
* @returns obj read data, normally as object
*/
loadDatasetFile(datasetName: string): Promise<Record<string, any>>;
/**
* 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<Record<string, any>>;
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<void>;
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<void>;
/**
* 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<string>;
/**
* 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<string, any>;
publishAll(type: string, id: string, obj: any): number;
destroy(): Promise<void>;
}
export {};
//# sourceMappingURL=inMemFileDB.d.ts.map