Rebasely Beta: data may be purged

justintypescript-ultra-strict Public

TypeScript · 20 lines · 1.2 KiB · at 83c2f03

// The pilot (TSUS v1): the rules compiled from ops/oncall/src/rules.tsus at Rebasely c5a11d4f// (v1/rules.js and its runtime, copied unchanged), with the .ts adapter lib/watcher.ts uses.import type { ApiEvent, HandledEntry, Job, WatchConfig } from "./types.ts";// @ts-expect-error -- compiled JS without declarationsimport { classify, isDuplicate as isDuplicateRule } from "./v1/rules.js";// @ts-expect-error -- compiled JS without declarationsimport { fromNullable } from "./v1/_runtime/boundary.js";type V1Option<T> = { isSome(): boolean; value: T; unwrapOr(f: T | null): T | null };const orNull = <T>(o: V1Option<T>): T | null => o.unwrapOr(null);export function jobFor(e: ApiEvent, cfg: WatchConfig, now: number): Job | null {  const c = classify(e, cfg.environments);  if (!c.isSome()) return null;  const v = c.value;  return { id: `e${e.id}`, kind: "incident", key: v.key, alertKey: orNull(v.alertKey), incident: orNull(v.incident), rank: v.rank, event: { ...e, data: v.data }, queuedAt: now };}export const isDuplicate = (handled: Record<string, HandledEntry>, j: Job, now: number, dedupeHours: number): boolean =>  isDuplicateRule(fromNullable(handled[j.key]), fromNullable(j.incident), now, dedupeHours);