* Add a snapshot and prune entries older than the history window.
(snapshot: T, now: Date = snapshot.createdAt)
| 62 | * Add a snapshot and prune entries older than the history window. |
| 63 | */ |
| 64 | push(snapshot: T, now: Date = snapshot.createdAt): void { |
| 65 | // Inline pruning to avoid private-method transpilation issues |
| 66 | let oldCount = 0; |
| 67 | for (let i = 0; i < this.snapshots.length; i++) { |
| 68 | const { createdAt } = this.snapshots[i]; |
| 69 | if (now.getTime() - new Date(createdAt).getTime() > this.historyMillis) oldCount++; |
| 70 | else break; |
| 71 | } |
| 72 | if (oldCount) this.snapshots.splice(0, oldCount); |
| 73 | |
| 74 | this.snapshots.push(snapshot); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Return all snapshots, or only those within the given time window. |
no outgoing calls