@baeta/subscriptions-pubsub
Interfaces
PubSubEngineV2
Properties
Property | Type |
---|---|
|
< |
|
( |
|
( |
|
( |
PubSubEngineV3
Properties
Property | Type |
---|---|
|
< |
|
( |
|
( |
|
( |
TypedPubSubOptions
Configuration options for TypedPubSub
Properties
Property | Type | Description |
---|---|---|
|
|
Optional prefix for channel names |
Type Aliases
TypedPubSub<Engine, Map>
TypedPubSub<
Engine
,Map
>:Engine
extendsPubSubEngineV3
?TypedPubSubV3
<Engine
,Map
> :Engine
extendsPubSubEngineV2
?TypedPubSubV2
<Engine
,Map
> :never
Type Parameters
Type Parameter |
---|
|
|
Functions
createTypedPubSub()
createTypedPubSub<
Engine
,Map
>(pubsub
,options
?):TypedPubSub
<Engine
,Map
>
Creates a type-safe wrapper around a PubSub implementation.
This utility ensures that your subscription channels and their payloads are properly typed, helping catch potential errors at compile time.
Type Parameters
Type Parameter |
---|
|
|
Parameters
Parameter | Type | Description |
---|---|---|
|
|
The PubSub engine instance (e.g., PubSub, RedisPubSub) |
|
Configuration options |
Returns
TypedPubSub
<Engine
, Map
>
Example
// Define your event map
type PubSubMap = {
"user-updated": User;
[c: `user-updated-${string}`]: User;
};
// Create typed PubSub instance
const pubsub = createTypedPubSub<PubSub, PubSubMap>(new PubSub());
// Usage with Redis
const pubsub = createTypedPubSub<RedisPubSub, PubSubMap>(
new RedisPubSub({
publisher: new Redis(options),
subscriber: new Redis(options),
}),
{
prefix: "feature-1:",
},
);