mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-02-28 06:22:45 -08:00
refactor(main): normalize runtime composer contracts
This commit is contained in:
@@ -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,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user