1import type { NativeReviewDiffHighlightScheme } from "../diffs/nativeReviewDiffHighlighter";
2
3// Pure key-derivation helpers for the native review diff bridge. Kept free of
4// react-native / hook imports so they stay unit-testable in node.
5
6function hashReviewDiffKey(diff: string | null | undefined): string {
7 if (!diff) {
8 return "empty";
9 }
10
11 let hash = 5381;
12 for (let index = 0; index < diff.length; index += 1) {
13 hash = (hash * 33) ^ diff.charCodeAt(index);
14 }
15
16 return `${diff.length}:${(hash >>> 0).toString(36)}`;
17}
18
19export function buildNativeReviewTokensResetKey(input: {
20 readonly threadKey: string | null;
21 readonly sectionId: string | null;
22 readonly scheme: NativeReviewDiffHighlightScheme;
23 readonly diff: string | null | undefined;
24 readonly fileCount: number;
25 readonly rowCount: number;
26}): string {
27 return [
28 input.threadKey ?? "none",
29 input.sectionId ?? "none",
30 input.scheme,
31 hashReviewDiffKey(input.diff),
32 input.fileCount,
33 input.rowCount,
34 ].join(":");
35}