{"version":3,"file":"heartbeat.mjs","sources":["../../src/migrations/heartbeat.ts"],"sourcesContent":["export interface HeartbeatLoggerOptions {\n  /** Minimum time between heartbeat log lines. Defaults to 60s. */\n  intervalMs?: number;\n  /** Injectable clock for tests. */\n  now?: () => number;\n}\n\nexport interface HeartbeatLogger {\n  /**\n   * Emit `buildMessage(elapsedSeconds)` at most once per interval.\n   * Safe to call on every batch — no-ops until the interval elapses.\n   */\n  tick(buildMessage: (elapsedSeconds: number) => string): void;\n}\n\n/**\n * Append-only, time-throttled progress logger for long-running migrations.\n * Never rewrites terminal lines — one complete Winston info line per tick.\n */\nexport const createHeartbeatLogger = (\n  log: (message: string) => void,\n  { intervalMs = 60_000, now = () => Date.now() }: HeartbeatLoggerOptions = {}\n): HeartbeatLogger => {\n  const startedAt = now();\n  let lastEmittedAt = startedAt;\n\n  return {\n    tick(buildMessage) {\n      const current = now();\n      if (current - lastEmittedAt < intervalMs) {\n        return;\n      }\n\n      const elapsedSeconds = Math.floor((current - startedAt) / 1000);\n      log(buildMessage(elapsedSeconds));\n      lastEmittedAt = current;\n    },\n  };\n};\n"],"names":["createHeartbeatLogger","log","intervalMs","now","Date","startedAt","lastEmittedAt","tick","buildMessage","current","elapsedSeconds","Math","floor"],"mappings":"AAeA;;;AAGC,IACM,MAAMA,qBAAAA,GAAwB,CACnCC,GAAAA,EACA,EAAEC,UAAAA,GAAa,KAAM,EAAEC,GAAAA,GAAM,IAAMC,IAAAA,CAAKD,GAAG,EAAE,EAA0B,GAAG,EAAE,GAAA;AAE5E,IAAA,MAAME,SAAAA,GAAYF,GAAAA,EAAAA;AAClB,IAAA,IAAIG,aAAAA,GAAgBD,SAAAA;IAEpB,OAAO;AACLE,QAAAA,IAAAA,CAAAA,CAAKC,YAAY,EAAA;AACf,YAAA,MAAMC,OAAAA,GAAUN,GAAAA,EAAAA;YAChB,IAAIM,OAAAA,GAAUH,gBAAgBJ,UAAAA,EAAY;AACxC,gBAAA;AACF,YAAA;YAEA,MAAMQ,cAAAA,GAAiBC,KAAKC,KAAK,CAAC,CAACH,OAAAA,GAAUJ,SAAQ,IAAK,IAAA,CAAA;AAC1DJ,YAAAA,GAAAA,CAAIO,YAAAA,CAAaE,cAAAA,CAAAA,CAAAA;YACjBJ,aAAAA,GAAgBG,OAAAA;AAClB,QAAA;AACF,KAAA;AACF;;;;"}