* fix(app): enforce canonical stream sequencing and init resolution * refactor: extract timeline and stream reducers to pure functions
39 lines
645 B
TypeScript
39 lines
645 B
TypeScript
export type SessionTimelineSeqCursor =
|
|
| {
|
|
epoch: string;
|
|
endSeq: number;
|
|
}
|
|
| null
|
|
| undefined;
|
|
|
|
export type SessionTimelineSeqDecision =
|
|
| "accept"
|
|
| "drop_stale"
|
|
| "drop_epoch"
|
|
| "gap"
|
|
| "init";
|
|
|
|
export function classifySessionTimelineSeq({
|
|
cursor,
|
|
epoch,
|
|
seq,
|
|
}: {
|
|
cursor: SessionTimelineSeqCursor;
|
|
epoch: string;
|
|
seq: number;
|
|
}): SessionTimelineSeqDecision {
|
|
if (!cursor) {
|
|
return "init";
|
|
}
|
|
if (cursor.epoch !== epoch) {
|
|
return "drop_epoch";
|
|
}
|
|
if (seq <= cursor.endSeq) {
|
|
return "drop_stale";
|
|
}
|
|
if (seq === cursor.endSeq + 1) {
|
|
return "accept";
|
|
}
|
|
return "gap";
|
|
}
|