refactor: dev label

This commit is contained in:
Carlos Valente
2024-07-16 19:48:03 +02:00
committed by Carlos Valente
parent 3056b75960
commit 2f65711078
5 changed files with 34 additions and 23 deletions
@@ -13,24 +13,19 @@ import {
import type { Low } from 'lowdb';
import { JSONFilePreset } from 'lowdb/node';
import { isProduction, isTest } from '../../setup/index.js';
import { isTest } from '../../setup/index.js';
import { isPath } from '../../utils/fileManagement.js';
import { consoleError } from '../../utils/console.js';
import { safeMerge } from './DataProvider.utils.js';
import { shouldCrashDev } from '../../utils/development.js';
type ReadonlyPromise<T> = Promise<Readonly<T>>;
let db = {} as Low<DatabaseModel>;
export async function initPersistence(filePath: string, fallbackData: DatabaseModel) {
if (!isProduction) {
if (!isPath(filePath)) {
consoleError(filePath);
consoleError(new Error('initPersistence should be called with a path').stack);
process.exit(0);
}
}
// eslint-disable-next-line no-unused-labels -- dev code path
DEV: shouldCrashDev(!isPath(filePath), 'initPersistence should be called with a path');
const newDb = await JSONFilePreset<DatabaseModel>(filePath, fallbackData);
// Read the database to initialize it