refactor(daemon): share runtime and service probe helpers

This commit is contained in:
Peter Steinberger
2026-02-22 21:18:30 +00:00
parent e029f78447
commit 06b0a60bef
12 changed files with 241 additions and 107 deletions

View File

@@ -0,0 +1,27 @@
type PendingState<TPending> = {
pendingById: Record<string, TPending>;
};
export async function rejectPendingPairingRequest<
TPending,
TState extends PendingState<TPending>,
TIdKey extends string,
>(params: {
requestId: string;
idKey: TIdKey;
loadState: () => Promise<TState>;
persistState: (state: TState) => Promise<void>;
getId: (pending: TPending) => string;
}): Promise<({ requestId: string } & Record<TIdKey, string>) | null> {
const state = await params.loadState();
const pending = state.pendingById[params.requestId];
if (!pending) {
return null;
}
delete state.pendingById[params.requestId];
await params.persistState(state);
return {
requestId: params.requestId,
[params.idKey]: params.getId(pending),
} as { requestId: string } & Record<TIdKey, string>;
}