refactor(main): normalize runtime composer contracts

This commit is contained in:
2026-02-21 02:21:04 -08:00
parent 5805d774ca
commit 69474c9642
18 changed files with 415 additions and 106 deletions

View File

@@ -3,48 +3,43 @@ import {
createBuildMpvCommandFromIpcRuntimeMainDepsHandler,
createIpcRuntimeHandlers,
} from '../domains/ipc';
import type { ComposerInputs, ComposerOutputs } from './contracts';
type MpvCommand = (string | number)[];
type IpcMainDepsWithoutHandlers = Omit<
RegisterIpcRuntimeServicesParams['mainDeps'],
'handleMpvCommand' | 'runSubsyncManual'
>;
type IpcMainDeps = RegisterIpcRuntimeServicesParams['mainDeps'];
type IpcMainDepsWithoutHandlers = Omit<IpcMainDeps, 'handleMpvCommand' | 'runSubsyncManual'>;
type RunSubsyncManual = IpcMainDeps['runSubsyncManual'];
type IpcRuntimeDeps<TRequest, TResult> = Parameters<
typeof createIpcRuntimeHandlers<TRequest, TResult>
>[0];
type IpcRuntimeDeps = Parameters<typeof createIpcRuntimeHandlers<unknown, unknown>>[0];
export type IpcRuntimeComposerOptions<TRequest, TResult> = {
export type IpcRuntimeComposerOptions = ComposerInputs<{
mpvCommandMainDeps: Parameters<typeof createBuildMpvCommandFromIpcRuntimeMainDepsHandler>[0];
handleMpvCommandFromIpcRuntime: IpcRuntimeDeps<
TRequest,
TResult
>['handleMpvCommandFromIpcDeps']['handleMpvCommandFromIpcRuntime'];
runSubsyncManualFromIpc: (request: TRequest) => Promise<TResult>;
handleMpvCommandFromIpcRuntime: IpcRuntimeDeps['handleMpvCommandFromIpcDeps']['handleMpvCommandFromIpcRuntime'];
runSubsyncManualFromIpc: RunSubsyncManual;
registration: {
runtimeOptions: RegisterIpcRuntimeServicesParams['runtimeOptions'];
mainDeps: IpcMainDepsWithoutHandlers;
ankiJimakuDeps: RegisterIpcRuntimeServicesParams['ankiJimakuDeps'];
registerIpcRuntimeServices: (params: RegisterIpcRuntimeServicesParams) => void;
};
};
}>;
export type IpcRuntimeComposerResult<TRequest, TResult> = {
export type IpcRuntimeComposerResult = ComposerOutputs<{
handleMpvCommandFromIpc: (command: MpvCommand) => void;
runSubsyncManualFromIpc: (request: TRequest) => Promise<TResult>;
runSubsyncManualFromIpc: RunSubsyncManual;
registerIpcRuntimeHandlers: () => void;
};
}>;
export function composeIpcRuntimeHandlers<TRequest, TResult>(
options: IpcRuntimeComposerOptions<TRequest, TResult>,
): IpcRuntimeComposerResult<TRequest, TResult> {
export function composeIpcRuntimeHandlers(
options: IpcRuntimeComposerOptions,
): IpcRuntimeComposerResult {
const mpvCommandFromIpcRuntimeMainDeps = createBuildMpvCommandFromIpcRuntimeMainDepsHandler(
options.mpvCommandMainDeps,
)();
const { handleMpvCommandFromIpc, runSubsyncManualFromIpc } = createIpcRuntimeHandlers<
TRequest,
TResult
unknown,
unknown
>({
handleMpvCommandFromIpcDeps: {
handleMpvCommandFromIpcRuntime: options.handleMpvCommandFromIpcRuntime,
@@ -61,7 +56,7 @@ export function composeIpcRuntimeHandlers<TRequest, TResult>(
mainDeps: {
...options.registration.mainDeps,
handleMpvCommand: (command) => handleMpvCommandFromIpc(command),
runSubsyncManual: (request) => runSubsyncManualFromIpc(request as TRequest),
runSubsyncManual: (request: unknown) => runSubsyncManualFromIpc(request),
},
ankiJimakuDeps: options.registration.ankiJimakuDeps,
});