{
...Configuration.objectHasOwnProperty(Configuration.getConfig().performanceStorage, 'enabled') ? { enabled: Configuration.getConfig().performanceStorage.enabled } : { enabled: false },
...Configuration.objectHasOwnProperty(Configuration.getConfig().performanceStorage, 'type') ? { type: Configuration.getConfig().performanceStorage.type } : { type: StorageType.JSON_FILE },
- ...Configuration.objectHasOwnProperty(Configuration.getConfig().performanceStorage, 'URI') ? { URI: Configuration.getConfig().performanceStorage.URI } : { URI: 'file:///performanceMeasurements.json' }
+ ...Configuration.objectHasOwnProperty(Configuration.getConfig().performanceStorage, 'URI')
+ ? { URI: Configuration.getConfig().performanceStorage.URI }
+ : { URI: this.getDefaultPerformanceStorageURI(Configuration.getConfig()?.performanceStorage?.type ?? StorageType.JSON_FILE) }
};
} else {
storageConfiguration =
{
enabled: false,
type: StorageType.JSON_FILE,
- URI: 'file:///performanceMeasurements.json'
+ URI: this.getDefaultPerformanceStorageURI(StorageType.JSON_FILE)
};
}
return storageConfiguration;
private static getConfigurationFileWatcher(): fs.FSWatcher {
try {
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
- return fs.watch(Configuration.configurationFilePath).on('change', async (): Promise<void> => {
- // Nullify to force configuration file reading
- Configuration.configuration = null;
- if (!Configuration.isUndefined(Configuration.configurationChangeCallback)) {
- await Configuration.configurationChangeCallback();
+ return fs.watch(Configuration.configurationFilePath, async (event, filename): Promise<void> => {
+ if (filename && event === 'change') {
+ // Nullify to force configuration file reading
+ Configuration.configuration = null;
+ if (!Configuration.isUndefined(Configuration.configurationChangeCallback)) {
+ await Configuration.configurationChangeCallback();
+ }
}
});
} catch (error) {
}
}
- private static objectHasOwnProperty(object: any, property: string): boolean {
+ private static getDefaultPerformanceStorageURI(storageType: StorageType) {
+ const SQLiteFileName = `${Constants.DEFAULT_PERFORMANCE_RECORDS_DB_NAME}.db`;
+ switch (storageType) {
+ case StorageType.JSON_FILE:
+ return `file://${path.join(path.resolve(__dirname, '../../'), Constants.DEFAULT_PERFORMANCE_RECORDS_FILENAME)}`;
+ case StorageType.SQLITE:
+ return `file://${path.join(path.resolve(__dirname, '../../'), SQLiteFileName)}`;
+ default:
+ throw new Error(`Performance storage URI is mandatory with storage type '${storageType}'`);
+ }
+ }
+
+ private static objectHasOwnProperty(object: unknown, property: string): boolean {
return Object.prototype.hasOwnProperty.call(object, property) as boolean;
}
- private static isUndefined(obj: any): boolean {
+ private static isUndefined(obj: unknown): boolean {
return typeof obj === 'undefined';
}