Skip to content

@studnicky/topic-router

TopicRouter registers subscriptions and invokes every selected handler. A caller supplies a structural matcher, candidate source, selection policy, or any composition of those toolkit primitives.

Install

bash
pnpm add @studnicky/topic-router

Exports

SymbolPurposeImport path
TopicRouterRegisters subscriptions, resolves selected IDs, and fans out an event envelope.@studnicky/topic-router
TopicCandidateSourceInterfaceContract for materializing candidate subscription identifiers.@studnicky/topic-router
TopicEnvelopeInterfaceImmutable delivery envelope contract.@studnicky/topic-router
TopicHandlerInterfaceContract for a subscription delivery handler.@studnicky/topic-router
TopicMatcherInterfaceContract for structural topic-to-pattern matching.@studnicky/topic-router
TopicPublishOptionsInterfaceOptional metadata attached to every envelope from one publish operation.@studnicky/topic-router
TopicRegistrationOptionsInterfaceOptional registration identifier and subscription attributes.@studnicky/topic-router
TopicRouterOptionsInterfaceRouter construction options.@studnicky/topic-router
TopicSelectionInterfaceSelected subscription identifier and evidence contract.@studnicky/topic-router
TopicSubscriptionInterfaceRegistered subscription contract.@studnicky/topic-router

The interface contracts are also available from @studnicky/topic-router/interfaces.

Observability hooks

Subclass TopicRouter to observe routing without adding a logger or selection policy to the base class. onMatch(topic, ids) fires after registered IDs resolve, onNoMatch(topic) fires after an empty structural match, onPoolExhausted(topic) fires after a candidate source has no registered IDs, and onSelection(topic, selection) fires before a selected handler receives its envelope. Hook failures are isolated from routing.

Source on GitHub