Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

autoSettleSettingsSync.ts

31 lines1.2 KB

1import type { EnvironmentId, ServerSettings } from "@t3tools/contracts";
2​
3export type AutoSettleSettings = Pick<
4 ServerSettings,
5 "sidebarAutoSettleAfterDays" | "sidebarAutoSettleOnMerge"
6>;
7​
8interface AutoSettleSyncTarget {
9 readonly environmentId: EnvironmentId;
10 readonly label: string;
11 readonly settings: AutoSettleSettings | null;
13​
14/** Receives connected, capable targets. Applying these defaults must preserve other settings. */
15export function planAutoSettleSettingsSync(
16 reference: { readonly environmentId: EnvironmentId; readonly settings: AutoSettleSettings },
17 targets: readonly AutoSettleSyncTarget[],
18) {
19 const patch: AutoSettleSettings = {
20 sidebarAutoSettleAfterDays: reference.settings.sidebarAutoSettleAfterDays,
21 sidebarAutoSettleOnMerge: reference.settings.sidebarAutoSettleOnMerge,
22 };
23 const mismatches = targets.filter(
24 (target) =>
25 target.environmentId !== reference.environmentId &&
26 target.settings !== null &&
27 (target.settings.sidebarAutoSettleAfterDays !== patch.sidebarAutoSettleAfterDays ||
28 target.settings.sidebarAutoSettleOnMerge !== patch.sidebarAutoSettleOnMerge),
29 );
30 return { patch, mismatches };