{"version":3,"file":"InMemoryRunEventBusRegistry-DO0WM9Lw.cjs","names":["onClose: () => void"],"sources":["../src/events/InMemoryRunEventSubscription.ts","../src/events/InMemoryRunEventBusRegistry.ts"],"sourcesContent":["import type { RunEventSubscription } from \"./runEvents\";\n\nexport class InMemoryRunEventSubscription implements RunEventSubscription {\n  constructor(private readonly onClose: () => void) {}\n\n  async close(): Promise<void> {\n    this.onClose();\n  }\n}\n","import type { WorkflowId } from \"../types\";\n\nimport type { RunEvent, RunEventBus, RunEventSubscription } from \"./runEvents\";\n\nimport { InMemoryRunEventSubscription } from \"./InMemoryRunEventSubscription\";\n\nexport class InMemoryRunEventBus implements RunEventBus {\n  private readonly globalListeners = new Set<(event: RunEvent) => void>();\n  private readonly listenersByWorkflowId = new Map<WorkflowId, Set<(event: RunEvent) => void>>();\n\n  async publish(event: RunEvent): Promise<void> {\n    for (const listener of this.globalListeners) listener(event);\n    for (const listener of this.listenersByWorkflowId.get(event.workflowId) ?? []) listener(event);\n  }\n\n  async subscribe(onEvent: (event: RunEvent) => void): Promise<RunEventSubscription> {\n    this.globalListeners.add(onEvent);\n    return new InMemoryRunEventSubscription(() => {\n      this.globalListeners.delete(onEvent);\n    });\n  }\n\n  async subscribeToWorkflow(workflowId: WorkflowId, onEvent: (event: RunEvent) => void): Promise<RunEventSubscription> {\n    const existing = this.listenersByWorkflowId.get(workflowId) ?? new Set<(event: RunEvent) => void>();\n    existing.add(onEvent);\n    this.listenersByWorkflowId.set(workflowId, existing);\n\n    return new InMemoryRunEventSubscription(() => {\n      const listeners = this.listenersByWorkflowId.get(workflowId);\n      if (!listeners) return;\n      listeners.delete(onEvent);\n      if (listeners.size === 0) this.listenersByWorkflowId.delete(workflowId);\n    });\n  }\n}\n\nexport { InMemoryRunEventSubscription } from \"./InMemoryRunEventSubscription\";\n"],"mappings":";;AAEA,IAAa,+BAAb,MAA0E;CACxE,YAAY,AAAiBA,SAAqB;EAArB;;CAE7B,MAAM,QAAuB;AAC3B,OAAK,SAAS;;;;;;ACAlB,IAAa,sBAAb,MAAwD;CACtD,AAAiB,kCAAkB,IAAI,KAAgC;CACvE,AAAiB,wCAAwB,IAAI,KAAiD;CAE9F,MAAM,QAAQ,OAAgC;AAC5C,OAAK,MAAM,YAAY,KAAK,gBAAiB,UAAS,MAAM;AAC5D,OAAK,MAAM,YAAY,KAAK,sBAAsB,IAAI,MAAM,WAAW,IAAI,EAAE,CAAE,UAAS,MAAM;;CAGhG,MAAM,UAAU,SAAmE;AACjF,OAAK,gBAAgB,IAAI,QAAQ;AACjC,SAAO,IAAI,mCAAmC;AAC5C,QAAK,gBAAgB,OAAO,QAAQ;IACpC;;CAGJ,MAAM,oBAAoB,YAAwB,SAAmE;EACnH,MAAM,WAAW,KAAK,sBAAsB,IAAI,WAAW,oBAAI,IAAI,KAAgC;AACnG,WAAS,IAAI,QAAQ;AACrB,OAAK,sBAAsB,IAAI,YAAY,SAAS;AAEpD,SAAO,IAAI,mCAAmC;GAC5C,MAAM,YAAY,KAAK,sBAAsB,IAAI,WAAW;AAC5D,OAAI,CAAC,UAAW;AAChB,aAAU,OAAO,QAAQ;AACzB,OAAI,UAAU,SAAS,EAAG,MAAK,sBAAsB,OAAO,WAAW;IACvE"}