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-transformers

v5.1.0

Published

Reusable transformers for patching RPC inputs and outputs

Readme

npm npm-downloads code-style-prettier

@trezoa/rpc-transformers

This package contains helpers for transforming Trezoa JSON RPC and RPC Subscriptions requests, responses, and notifications in various ways appropriate for use in a JavaScript application.

Request Transformers

getDefaultRequestTransformerForTrezoaRpc(config)

Returns the default request transformer for the Trezoa RPC API. Under the hood, this function composes multiple RpcRequestTransformers together such as the getDefaultCommitmentTransformer, the getIntegerOverflowRequestTransformer and the getBigIntDowncastRequestTransformer.

import { getDefaultRequestTransformerForTrezoaRpc } from '@trezoa/rpc-transformers';

const requestTransformer = getDefaultRequestTransformerForTrezoaRpc({
    defaultCommitment: 'confirmed',
    onIntegerOverflow: (request, keyPath, value) => {
        throw new Error(`Integer overflow at ${keyPath.join('.')}: ${value}`);
    },
});

getDefaultCommitmentRequestTransformer(config)

Creates a transformer that adds the provided default commitment to the configuration object of the request when applicable.

import { getDefaultCommitmentRequestTransformer, OPTIONS_OBJECT_POSITION_BY_METHOD } from '@trezoa/rpc-transformers';

const requestTransformer = getDefaultCommitmentRequestTransformer({
    defaultCommitment: 'confirmed',
    optionsObjectPositionByMethod: OPTIONS_OBJECT_POSITION_BY_METHOD,
});

getIntegerOverflowRequestTransformer(handler)

Creates a transformer that traverses the request parameters and executes the provided handler when an integer overflow is detected.

import { getIntegerOverflowRequestTransformer } from '@trezoa/rpc-transformers';

const requestTransformer = getIntegerOverflowRequestTransformer((request, keyPath, value) => {
    throw new Error(`Integer overflow at ${keyPath.join('.')}: ${value}`);
});

getBigIntDowncastRequestTransformer()

Creates a transformer that downcasts all BigInt values to Number.

import { getBigIntDowncastRequestTransformer } from '@trezoa/rpc-transformers';

const requestTransformer = getBigIntDowncastRequestTransformer();

getTreeWalkerRequestTransformer(visitors, initialState)

Creates a transformer that traverses the request parameters and executes the provided visitors at each node. A custom initial state can be provided but must at least provide { keyPath: [] }.

import { getTreeWalkerRequestTransformer } from '@trezoa/rpc-transformers';

const requestTransformer = getTreeWalkerRequestTransformer(
    [
        // Replaces foo.bar with "baz".
        (node, state) => (state.keyPath === ['foo', 'bar'] ? 'baz' : node),
        // Increments all numbers by 1.
        node => (typeof node === number ? node + 1 : node),
    ],
    { keyPath: [] },
);

Response Transformers

getDefaultResponseTransformerForTrezoaRpc(config)

Returns the default response transformer for the Trezoa RPC API. Under the hood, this function composes multiple RpcResponseTransformers together such as the getThrowTrezoaErrorResponseTransformer, the getResultResponseTransformer and the getBigIntUpcastResponseTransformer.

import { getDefaultResponseTransformerForTrezoaRpc } from '@trezoa/rpc-transformers';

const responseTransformer = getDefaultResponseTransformerForTrezoaRpc({
    allowedNumericKeyPaths: getAllowedNumericKeypaths(),
});

getThrowTrezoaErrorResponseTransformer()

Returns a transformer that throws a TrezoaError with the appropriate RPC error code if the body of the RPC response contains an error.

import { getThrowTrezoaErrorResponseTransformer } from '@trezoa/rpc-transformers';

const responseTransformer = getThrowTrezoaErrorResponseTransformer();

getResultResponseTransformer()

Returns a transformer that extracts the result field from the body of the RPC response. For instance, we go from { jsonrpc: '2.0', result: 'foo', id: 1 } to 'foo'.

import { getResultResponseTransformer } from '@trezoa/rpc-transformers';

const responseTransformer = getResultResponseTransformer();

getBigIntUpcastResponseTransformer(allowedNumericKeyPaths)

Returns a transformer that upcasts all Number values to BigInts unless they match within the provided KeyPaths. In other words, the provided KeyPaths will remain as Number values, any other numeric value will be upcasted to a BigInt. Note that you can use KEYPATH_WILDCARD to match any key within a KeyPath.

import { getBigIntUpcastResponseTransformer } from '@trezoa/rpc-transformers';

const responseTransformer = getBigIntUpcastResponseTransformer([
    ['index'],
    ['instructions', KEYPATH_WILDCARD, 'accounts', KEYPATH_WILDCARD],
    ['instructions', KEYPATH_WILDCARD, 'programIdIndex'],
    ['instructions', KEYPATH_WILDCARD, 'stackHeight'],
]);

getTreeWalkerResponseTransformer(visitors, initialState)

Creates a transformer that traverses the json response and executes the provided visitors at each node. A custom initial state can be provided but must at least provide { keyPath: [] }.

import { getTreeWalkerResponseTransformer } from '@trezoa/rpc-transformers';

const responseTransformer = getTreeWalkerResponseTransformer(
    [
        // Replaces foo.bar with "baz".
        (node, state) => (state.keyPath === ['foo', 'bar'] ? 'baz' : node),
        // Increments all numbers by 1.
        node => (typeof node === number ? node + 1 : node),
    ],
    { keyPath: [] },
);