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

@@ -376,9 +376,14 @@ type AllowFromStoreEntryUpdateParams = {
env?: NodeJS.ProcessEnv;
};
type ChannelAllowFromStoreEntryMutation = (
current: string[],
normalized: string,
) => string[] | null;
async function updateChannelAllowFromStore(
params: {
apply: (current: string[], normalized: string) => string[] | null;
apply: ChannelAllowFromStoreEntryMutation;
} & AllowFromStoreEntryUpdateParams,
): Promise<{ changed: boolean; allowFrom: string[] }> {
return await updateAllowFromStoreEntry({
@@ -390,38 +395,36 @@ async function updateChannelAllowFromStore(
});
}
export async function addChannelAllowFromStoreEntry(params: {
channel: PairingChannel;
entry: string | number;
accountId?: string;
env?: NodeJS.ProcessEnv;
}): Promise<{ changed: boolean; allowFrom: string[] }> {
async function mutateChannelAllowFromStoreEntry(
params: AllowFromStoreEntryUpdateParams,
apply: ChannelAllowFromStoreEntryMutation,
): Promise<{ changed: boolean; allowFrom: string[] }> {
return await updateChannelAllowFromStore({
...params,
apply: (current, normalized) => {
if (current.includes(normalized)) {
return null;
}
return [...current, normalized];
},
apply,
});
}
export async function removeChannelAllowFromStoreEntry(params: {
channel: PairingChannel;
entry: string | number;
accountId?: string;
env?: NodeJS.ProcessEnv;
}): Promise<{ changed: boolean; allowFrom: string[] }> {
return await updateChannelAllowFromStore({
...params,
apply: (current, normalized) => {
const next = current.filter((entry) => entry !== normalized);
if (next.length === current.length) {
return null;
}
return next;
},
export async function addChannelAllowFromStoreEntry(
params: AllowFromStoreEntryUpdateParams,
): Promise<{ changed: boolean; allowFrom: string[] }> {
return await mutateChannelAllowFromStoreEntry(params, (current, normalized) => {
if (current.includes(normalized)) {
return null;
}
return [...current, normalized];
});
}
export async function removeChannelAllowFromStoreEntry(
params: AllowFromStoreEntryUpdateParams,
): Promise<{ changed: boolean; allowFrom: string[] }> {
return await mutateChannelAllowFromStoreEntry(params, (current, normalized) => {
const next = current.filter((entry) => entry !== normalized);
if (next.length === current.length) {
return null;
}
return next;
});
}