Refacor electron app and add migrations

This commit is contained in:
2026-03-04 01:38:43 +01:00
parent 4e95ae77c5
commit be91b6dfe8
70 changed files with 1824 additions and 923 deletions

39
electron/ipc/cqrs.ts Normal file
View File

@@ -0,0 +1,39 @@
import { ipcMain } from 'electron';
import { buildCommandHandlers } from '../cqrs/commands';
import { buildQueryHandlers } from '../cqrs/queries';
import {
Command,
Query,
CommandTypeKey,
QueryTypeKey
} from '../cqrs/types';
import { getDataSource } from '../db/database';
export function setupCqrsHandlers(): void {
const dataSource = getDataSource();
if (!dataSource) {
throw new Error('DataSource not initialised');
}
const commandHandlerMap = buildCommandHandlers(dataSource) as Record<CommandTypeKey, (command: Command) => unknown>;
const queryHandlerMap = buildQueryHandlers(dataSource) as Record<QueryTypeKey, (query: Query) => unknown>;
ipcMain.handle('cqrs:command', async (_evt, command: Command) => {
const handler = commandHandlerMap[command.type as CommandTypeKey];
if (!handler)
throw new Error(`No command handler for type: ${command.type}`);
return handler(command);
});
ipcMain.handle('cqrs:query', async (_evt, query: Query) => {
const handler = queryHandlerMap[query.type as QueryTypeKey];
if (!handler)
throw new Error(`No query handler for type: ${query.type}`);
return handler(query);
});
}