Open History to see the last commit
1export const THREAD_LIMIT = 500;
2export const WATCH_SECONDS = 30;
3export interface Comment {
4 story_id: number;
5 item_id: number;
6 parent_id: number;
7 path: string;
8 depth: number;
9 author: string | null;
10 created: number;
11 text: string;
12 deleted: boolean;
13 dead: boolean;
14 committed_at: string;
15}
16export interface ThreadHealth {
17 state: "starting" | "healthy" | "reconnecting" | "degraded";
18 checkedAt: string | null;
19 committedAt: string | null;
20 truncated?: boolean;
21}
22export function sortComments(rows: readonly Comment[]): Comment[] {
23 return [...rows].sort((a, b) =>
24 a.path < b.path ? -1 : a.path > b.path ? 1 : a.item_id - b.item_id,
25 );
26}
27export function parseStoryId(value: unknown): number {
28 if (typeof value !== "string" || !/^[1-9][0-9]{0,9}$/.test(value))
29 throw new Error("Invalid story ID");
30 const id = Number(value);
31 if (id > 2147483647) throw new Error("Invalid story ID");
32 return id;
33}
34export function discussionLink(id: number) {
35 return `/item?id=${id}`;
36}