export type ChartLibrarySessionBranch = "clear" | "hydrate-then-persist" | "persist-self"; export function chartLibrarySessionBranch( accountId: string | null | undefined, loadedAccount: string, ): ChartLibrarySessionBranch { if (!accountId) return "clear"; if (loadedAccount !== accountId) return "hydrate-then-persist"; return "persist-self"; } export function chartLibraryFromCloudOthers( cloudLibrary: readonly T[], profile: P, upsertSelfChart: (library: T[], profile: P) => T[], ): T[] { return upsertSelfChart(cloudLibrary.filter((record) => record.role !== "self"), profile); } export function chartLibraryOnCloudFailure( profile: P, upsertSelfChart: (library: T[], profile: P) => T[], ): T[] { return upsertSelfChart([], profile); }