import type { PageSection, ReadingSignoff } from "#types/writing.types"; import { SIGNOFF_CHANGED, SIGNOFF_MISSING } from "#configuration/strings/derivation.strings"; import type { Finding } from "#types/derivation.types"; import { SIGNOFF_SEPARATOR } from "#configuration/constants/writing.constants"; const signoffKey = function signoffKey(key: string, fingerprint: string): string { return key + SIGNOFF_SEPARATOR + fingerprint; }; export const unsignedSections = function unsignedSections( scope: readonly string[], signoffs: readonly ReadingSignoff[], sections: readonly PageSection[], ): Finding[] { const inScope = new Set(scope); const signed = new Set(signoffs.map((signoff) => signoffKey(signoff.key, signoff.fingerprint))); const everSigned = new Set(signoffs.map((signoff) => signoff.key)); return sections .filter((section) => inScope.has(section.page)) .filter((section) => !signed.has(signoffKey(section.key, section.fingerprint))) .map((section) => ({ file: section.key, message: `${everSigned.has(section.key) ? SIGNOFF_CHANGED : SIGNOFF_MISSING}${section.fingerprint}`, })); }; export const unreadCount = function unreadCount(scope: readonly string[], sections: readonly PageSection[]): number { const inScope = new Set(scope); return sections.filter((section) => !inScope.has(section.page)).length; };