refactor: factor out performance records JSON file path building
authorJérôme Benoit <jerome.benoit@sap.com>
Fri, 12 May 2023 13:50:53 +0000 (15:50 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Fri, 12 May 2023 13:50:53 +0000 (15:50 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/utils/Configuration.ts

index cf4d2bca6df9c412b63999cd8e8e9cd4e2c09cdd..6423e34c3dc76303f7f785e43d3b772dbf954abd 100644 (file)
@@ -94,10 +94,9 @@ export class Configuration {
         ...Configuration.getConfig()?.performanceStorage,
         ...(Configuration.getConfig()?.performanceStorage?.type === StorageType.JSON_FILE &&
           Configuration.getConfig()?.performanceStorage?.uri && {
-            uri: `file://${path.join(
-              path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../'),
+            uri: Configuration.buildPerformanceUriFilePath(
               new URL(Configuration.getConfig()?.performanceStorage?.uri).pathname
-            )}`,
+            ),
           }),
       };
     }
@@ -393,17 +392,22 @@ export class Configuration {
   private static getDefaultPerformanceStorageUri(storageType: StorageType) {
     switch (storageType) {
       case StorageType.JSON_FILE:
-        return `file://${path.join(
-          path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../'),
+        return Configuration.buildPerformanceUriFilePath(
           Constants.DEFAULT_PERFORMANCE_RECORDS_FILENAME
-        )}`;
+        );
       case StorageType.SQLITE:
-        return `file://${path.join(
-          path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../'),
+        return Configuration.buildPerformanceUriFilePath(
           `${Constants.DEFAULT_PERFORMANCE_RECORDS_DB_NAME}.db`
-        )}`;
+        );
       default:
         throw new Error(`Performance storage URI is mandatory with storage type '${storageType}'`);
     }
   }
+
+  private static buildPerformanceUriFilePath(file: string) {
+    return `file://${path.join(
+      path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../'),
+      file
+    )}`;
+  }
 }