prorm API Reference
    Preparing search index...

    Class NatsStore

    NatsStore wraps a nats NatsConnection and exposes NATS's core publish/subscribe and request/reply operations plus JetStream KV (kvPut/kvGet/kvDelete) as a typed, promise-based API.

    Implements

    Index
    name: "nats" = 'nats'

    The name of the store (e.g. 'mongodb', 'redis', 'dynamodb')

    library: "nats" = 'nats'

    The client library being used

    • Publish data to subject. The payload is encoded per the module's encoding rules (string → UTF-8, Uint8Array → as-is).

      Parameters

      • subject: string
      • data: NatsPayload

      Returns void

    • Subscribe to subject, invoking handler for each message via the driver's callback option (subscribe(subject, { callback })). Returns the driver's Subscription (call .unsubscribe() / .drain() on it to stop). The callback style is chosen over the async-iterator style so a handler can be registered without spawning a consuming loop.

      Parameters

      • subject: string
      • handler: NatsMessageHandler

      Returns unknown

    • Send a request to subject and await a single reply. opts is passed straight through to the driver (e.g. { timeout }). Resolves with the driver's reply Msg; read .data / .string() / .json() off it.

      Parameters

      • subject: string
      • data: NatsPayload
      • Optionalopts: unknown

      Returns Promise<unknown>

    • Lazily resolve (and cache) the JetStream KV bucket view for bucket via connection.jetstream().views.kv(bucket). Subsequent calls for the same bucket return the cached view.

      Parameters

      • bucket: string

      Returns Promise<NatsKvLike>

    • Put value at key in bucket's KV store (encoded per the module's encoding rules). Returns the revision number assigned by JetStream.

      Parameters

      • bucket: string
      • key: string
      • value: NatsPayload

      Returns Promise<number>

    • Get the raw value stored at key in bucket, or null if the key is absent (or holds a deleted/purged entry). Returns the entry's Uint8Array value; decode with TextDecoder as needed.

      Parameters

      • bucket: string
      • key: string

      Returns Promise<Uint8Array<ArrayBufferLike> | null>

    • Delete key from bucket's KV store.

      Parameters

      • bucket: string
      • key: string

      Returns Promise<void>