File size: 825 Bytes
499d3d5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import type {
  SessionFormatEvent,
  SessionFormatEventRun,
  SessionFormatMigrationContext,
} from './types.ts'

/** Migration output context that expands compact runs into retained events. */
export class SessionFormatEventCollector implements SessionFormatMigrationContext {
  /** Events retained by this collector in source order. */
  readonly values: SessionFormatEvent[] = []

  /**
   * Retain one settled event.
   * @param event - settled event emitted by the upstream stage.
   */
  emitEvent(event: SessionFormatEvent): void {
    this.values.push(event)
  }

  /**
   * Expand one compact run directly into retained events.
   * @param run - compact event run emitted by the upstream stage.
   */
  emitRun(run: SessionFormatEventRun): void {
    for (const event of run.expand()) this.values.push(event)
  }
}