UNPKG

@graphql-hive/pubsub

Version:
37 lines (34 loc) 1.64 kB
import { NatsConnection } from '@nats-io/nats-core'; import { DisposableSymbols } from '@whatwg-node/disposablestack'; import { MaybePromise } from '@whatwg-node/promise-helpers'; import { T as TopicDataMap, P as PubSub, a as PubSubListener } from './pubsub-VtDb_TZC.js'; interface NATSPubSubOptions { /** * Prefix for NATS publish subhects to avoid conflicts. * Intentionally no default because we don't want to accidentally share channels between different services. */ subjectPrefix: string; /** * By default, when the pub/sub instance is disposed, it will call * `close` on the NATS connection. Set this to `true` if you * want to keep the connection alive after disposal. * * This might be useful if you want to manage the NATS connection's lifecycle * outside of the pub/sub instance. * * @default false */ noCloseOnDispose?: boolean; } /** {@link PubSub Hive PubSub} implementation of the [NATS message broker](https://nats.io/). */ declare class NATSPubSub<M extends TopicDataMap = TopicDataMap> implements PubSub<M> { #private; constructor(nats: NatsConnection, options: NATSPubSubOptions); subscribedTopics(): Promise<(keyof M)[]>; publish<Topic extends keyof M>(topic: Topic, data: M[Topic]): void; subscribe<Topic extends keyof M>(topic: Topic): AsyncIterable<M[Topic]>; subscribe<Topic extends keyof M>(topic: Topic, listener: PubSubListener<M, Topic>): MaybePromise<() => MaybePromise<void>>; dispose(): Promise<void>; [DisposableSymbols.asyncDispose](): Promise<void>; } export { NATSPubSub, type NATSPubSubOptions };