npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@trezoa/rpc-subscriptions-spec

v5.1.0

Published

A generic implementation of JSON RPC Subscriptions using proxies

Downloads

189

Readme

npm npm-downloads code-style-prettier

@trezoa/rpc-subscriptions-spec

This package contains types that describe the implementation of the JSON RPC Subscriptions API, as well as methods to create one. It can be used standalone, but it is also exported as part of Kit @trezoa/kit.

This API is designed to be used as follows:

const rpcSubscriptions =
    // Step 1 - Create a `RpcSubscriptions` instance. This may be stateful.
    createTrezoaRpcSubscriptions(mainnet('wss://api.mainnet-beta.trezoa.com'));
const response = await rpcSubscriptions
    // Step 2 - Call supported methods on it to produce `PendingRpcSubscriptionsRequest` objects.
    .slotNotifications({ commitment: 'confirmed' })
    // Step 3 - Call the `subscribe()` method on those pending requests to trigger them.
    .subscribe({ abortSignal: AbortSignal.timeout(10_000) });
// Step 4 - Iterate over the result.
try {
    for await (const slotNotification of slotNotifications) {
        console.log('Got a slot notification', slotNotification);
    }
} catch (e) {
    console.error('The subscription closed unexpectedly', e);
} finally {
    console.log('We have stopped listening for notifications');
}

Types

RpcSubscriptionsChannel<TOutboundMessage, TInboundMessage>

A channel is a DataPublisher on which you can subscribe to events of type RpcSubscriptionChannelEvents<TInboundMessage>. Additionally, you can use this object to send messages of type TOutboundMessage back to the remote end by calling its send(message) method.

RpcSubscriptionsChannelCreator<TOutboundMessage, TInboundMessage>

A channel creator is a function that accepts an AbortSignal, returns a new RpcSubscriptionsChannel, and tears down the channel when the abort signal fires.

RpcSubscriptionChannelEvents<TInboundMessage>

Subscription channels publish events on two channel names:

  • error: Fires when the channel closes unexpectedly
  • message: Fires on every message received from the remote end

Functions

executeRpcPubSubSubscriptionPlan({ channel, responseTransformer, signal, subscribeRequest, unsubscribeMethodName })

Given a channel, this function executes the particular subscription plan required by the Trezoa JSON RPC Subscriptions API.

  1. Calls the subscribeRequest on the remote RPC
  2. Waits for a response containing the subscription id
  3. Returns a DataPublisher that publishes notifications related to that subscriptions id, filtering out all others
  4. Calls the unsubscribeMethodName on the remote RPC when the abort signal is fired.

transformChannelInboundMessages(channel, transform)

Given a channel with inbound messages of type T and a function of type T => U, returns a new channel with inbound messages of type U. Note that this only affects messages of type "message" and thus, does not affect incoming error messages.

For instance, it can be used to parse incoming JSON messages:

const transformedChannel = transformChannelInboundMessages(channel, JSON.parse);

transformChannelOutboundMessages(channel, transform)

Given a channel with outbound messages of type T and a function of type U => T, returns a new channel with outbound messages of type U.

For instance, it can be used to stringify JSON messages before sending them over the wire:

const transformedChannel = transformChannelOutboundMessages(channel, JSON.stringify);