JSPM

@solana/rpc-transformers

2.0.0-canary-20240901184654
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 246133
  • Score
    100M100P100Q187224F
  • License MIT

Reusable transformers for patching RPC inputs and outputs

Package Exports

  • @solana/rpc-transformers

Readme

npm npm-downloads semantic-release
code-style-prettier

@solana/rpc-transformers

Request Transformers

getDefaultRequestTransformerForSolanaRpc(config)

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

import { getDefaultRequestTransformerForSolanaRpc } from '@solana/rpc-transformers';

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

getDefaultCommitmentTransformer(config)

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

import { getDefaultCommitmentTransformer, OPTIONS_OBJECT_POSITION_BY_METHOD } from '@solana/rpc-transformers';

const requestTransformer = getDefaultCommitmentTransformer({
    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 '@solana/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 '@solana/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 '@solana/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: [] },
);