mqtt-ingest draft
This commit is contained in:
18
app/src/registry.ts
Normal file
18
app/src/registry.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import type { TopicHandler } from './types.js'
|
||||
|
||||
const handlers = new Map<string, TopicHandler>()
|
||||
|
||||
export function register(topic: string, handler: TopicHandler): void {
|
||||
if (handlers.has(topic)) {
|
||||
throw new Error(`Handler already registered for topic: ${topic}`)
|
||||
}
|
||||
handlers.set(topic, handler)
|
||||
}
|
||||
|
||||
export function getHandler(topic: string): TopicHandler | undefined {
|
||||
return handlers.get(topic)
|
||||
}
|
||||
|
||||
export function getRegisteredTopics(): string[] {
|
||||
return [...handlers.keys()]
|
||||
}
|
||||
Reference in New Issue
Block a user