{"_id":"@atlaschain/rpc-transformers","name":"@atlaschain/rpc-transformers","dist-tags":{"latest":"3.0.0"},"versions":{"3.0.0":{"name":"@atlaschain/rpc-transformers","version":"3.0.0","description":"Reusable transformers for patching RPC inputs and outputs","exports":{"edge-light":{"import":"./dist/index.node.mjs","require":"./dist/index.node.cjs"},"workerd":{"import":"./dist/index.node.mjs","require":"./dist/index.node.cjs"},"browser":{"import":"./dist/index.browser.mjs","require":"./dist/index.browser.cjs"},"node":{"import":"./dist/index.node.mjs","require":"./dist/index.node.cjs"},"react-native":"./dist/index.native.mjs","types":"./dist/types/index.d.ts"},"browser":{"./dist/index.node.cjs":"./dist/index.browser.cjs","./dist/index.node.mjs":"./dist/index.browser.mjs"},"main":"./dist/index.node.cjs","module":"./dist/index.node.mjs","react-native":"./dist/index.native.mjs","types":"./dist/types/index.d.ts","type":"commonjs","sideEffects":false,"keywords":["blockchain","atlas","web3"],"scripts":{"compile:docs":"typedoc","compile:js":"tsup --config build-scripts/tsup.config.package.ts","compile:typedefs":"tsc -p ./tsconfig.declarations.json","dev":"jest -c ../../node_modules/@atlas/test-config/jest-dev.config.ts --rootDir . --watch","prepublishOnly":"pnpm pkg delete devDependencies","publish-impl":"npm view $npm_package_name@$npm_package_version > /dev/null 2>&1 || (pnpm publish --tag ${PUBLISH_TAG:-canary} --access public --no-git-checks && (([ -n \"${GITHUB_OUTPUT:-}\" ] && echo 'published=true' >> \"$GITHUB_OUTPUT\") || true) && (([ \"$PUBLISH_TAG\" != \"canary\" ] && ../build-scripts/maybe-tag-latest.ts $npm_package_name@$npm_package_version) || true))","publish-packages":"pnpm prepublishOnly && pnpm publish-impl","style:fix":"pnpm eslint --fix src && pnpm prettier --log-level warn --ignore-unknown --write ./*","test:lint":"TERM_OVERRIDE=\"${TURBO_HASH:+dumb}\" TERM=${TERM_OVERRIDE:-$TERM} jest -c ../../node_modules/@atlas/test-config/jest-lint.config.ts --rootDir . --silent","test:prettier":"TERM_OVERRIDE=\"${TURBO_HASH:+dumb}\" TERM=${TERM_OVERRIDE:-$TERM} jest -c ../../node_modules/@atlas/test-config/jest-prettier.config.ts --rootDir . --silent","test:treeshakability:browser":"agadoo dist/index.browser.mjs","test:treeshakability:native":"agadoo dist/index.native.mjs","test:treeshakability:node":"agadoo dist/index.node.mjs","test:typecheck":"tsc --noEmit","test:unit:browser":"TERM_OVERRIDE=\"${TURBO_HASH:+dumb}\" TERM=${TERM_OVERRIDE:-$TERM} jest -c ../../node_modules/@atlas/test-config/jest-unit.config.browser.ts --rootDir . --silent","test:unit:node":"TERM_OVERRIDE=\"${TURBO_HASH:+dumb}\" TERM=${TERM_OVERRIDE:-$TERM} jest -c ../../node_modules/@atlas/test-config/jest-unit.config.node.ts --rootDir . --silent"},"author":{"name":"Atlas Chain Foundation"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/anza-xyz/kit.git"},"bugs":{"url":"https://github.com/anza-xyz/kit/issues"},"browserslist":["supports bigint and not dead","maintained node versions"],"dependencies":{"@atlaschain/errors":"workspace:*","@atlaschain/functional":"workspace:*","@atlaschain/nominal-types":"workspace:*","@atlaschain/rpc-spec-types":"workspace:*","@atlaschain/rpc-types":"workspace:*"},"peerDependencies":{"typescript":">=5.3.3"},"engines":{"node":">=20.18.0"},"_id":"@atlaschain/rpc-transformers@3.0.0","homepage":"https://github.com/anza-xyz/kit#readme","_nodeVersion":"22.12.0","_npmVersion":"10.9.0","dist":{"integrity":"sha512-6osVDvRvCXXDZWA9Ajc1wF5f0ytowo2edKVJkt/AOl1I+BM3YHq3+H2QTXhoxXjp4ZllFhrMt75nBvefxBJE4A==","shasum":"9d4c729744a8ade30df015855f69fd63460a0b77","tarball":"https://registry.npmjs.org/@atlaschain/rpc-transformers/-/rpc-transformers-3.0.0.tgz","fileCount":5,"unpackedSize":18174,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDKEsXbju4tWv3HvnDUYW1rIZtCF7iqNnFpfQEZFVDTpAIhAPygUQflsUUO3TSpdhYUDN25QMuAK+RIaXPXFgtegB9n"}]},"_npmUser":{"name":"atlaschain","email":"jq@atlaschain.org"},"directories":{},"maintainers":[{"name":"atlaschain","email":"jq@atlaschain.org"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/rpc-transformers_3.0.0_1756885284987_0.3639914803440025"},"_hasShrinkwrap":false}},"time":{"created":"2025-09-03T07:41:24.894Z","3.0.0":"2025-09-03T07:41:25.161Z","modified":"2025-09-03T07:41:25.420Z"},"maintainers":[{"name":"atlaschain","email":"jq@atlaschain.org"}],"description":"Reusable transformers for patching RPC inputs and outputs","homepage":"https://github.com/anza-xyz/kit#readme","keywords":["blockchain","atlas","web3"],"repository":{"type":"git","url":"git+https://github.com/anza-xyz/kit.git"},"author":{"name":"Atlas Chain Foundation"},"bugs":{"url":"https://github.com/anza-xyz/kit/issues"},"license":"MIT","readme":"[![npm][npm-image]][npm-url]\n[![npm-downloads][npm-downloads-image]][npm-url]\n<br />\n[![code-style-prettier][code-style-prettier-image]][code-style-prettier-url]\n\n[code-style-prettier-image]: https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square\n[code-style-prettier-url]: https://github.com/prettier/prettier\n[npm-downloads-image]: https://img.shields.io/npm/dm/@atlas/rpc-transformers?style=flat\n[npm-image]: https://img.shields.io/npm/v/@atlas/rpc-transformers?style=flat\n[npm-url]: https://www.npmjs.com/package/@atlas/rpc-transformers\n\n# @atlas/rpc-transformers\n\nThis package contains helpers for transforming Atlas JSON RPC and RPC Subscriptions requests, responses, and notifications in various ways appropriate for use in a JavaScript application.\n\n## Request Transformers\n\n### `getDefaultRequestTransformerForAtlasRpc(config)`\n\nReturns the default request transformer for the Atlas RPC API. Under the hood, this function composes multiple `RpcRequestTransformers` together such as the `getDefaultCommitmentTransformer`, the `getIntegerOverflowRequestTransformer` and the `getBigIntDowncastRequestTransformer`.\n\n```ts\nimport { getDefaultRequestTransformerForAtlasRpc } from '@atlas/rpc-transformers';\n\nconst requestTransformer = getDefaultRequestTransformerForAtlasRpc({\n    defaultCommitment: 'confirmed',\n    onIntegerOverflow: (request, keyPath, value) => {\n        throw new Error(`Integer overflow at ${keyPath.join('.')}: ${value}`);\n    },\n});\n```\n\n### `getDefaultCommitmentRequestTransformer(config)`\n\nCreates a transformer that adds the provided default commitment to the configuration object of the request when applicable.\n\n```ts\nimport { getDefaultCommitmentRequestTransformer, OPTIONS_OBJECT_POSITION_BY_METHOD } from '@atlas/rpc-transformers';\n\nconst requestTransformer = getDefaultCommitmentRequestTransformer({\n    defaultCommitment: 'confirmed',\n    optionsObjectPositionByMethod: OPTIONS_OBJECT_POSITION_BY_METHOD,\n});\n```\n\n### `getIntegerOverflowRequestTransformer(handler)`\n\nCreates a transformer that traverses the request parameters and executes the provided handler when an integer overflow is detected.\n\n```ts\nimport { getIntegerOverflowRequestTransformer } from '@atlas/rpc-transformers';\n\nconst requestTransformer = getIntegerOverflowRequestTransformer((request, keyPath, value) => {\n    throw new Error(`Integer overflow at ${keyPath.join('.')}: ${value}`);\n});\n```\n\n### `getBigIntDowncastRequestTransformer()`\n\nCreates a transformer that downcasts all `BigInt` values to `Number`.\n\n```ts\nimport { getBigIntDowncastRequestTransformer } from '@atlas/rpc-transformers';\n\nconst requestTransformer = getBigIntDowncastRequestTransformer();\n```\n\n### `getTreeWalkerRequestTransformer(visitors, initialState)`\n\nCreates 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: [] }`.\n\n```ts\nimport { getTreeWalkerRequestTransformer } from '@atlas/rpc-transformers';\n\nconst requestTransformer = getTreeWalkerRequestTransformer(\n    [\n        // Replaces foo.bar with \"baz\".\n        (node, state) => (state.keyPath === ['foo', 'bar'] ? 'baz' : node),\n        // Increments all numbers by 1.\n        node => (typeof node === number ? node + 1 : node),\n    ],\n    { keyPath: [] },\n);\n```\n\n## Response Transformers\n\n### `getDefaultResponseTransformerForAtlasRpc(config)`\n\nReturns the default response transformer for the Atlas RPC API. Under the hood, this function composes multiple `RpcResponseTransformers` together such as the `getThrowAtlasErrorResponseTransformer`, the `getResultResponseTransformer` and the `getBigIntUpcastResponseTransformer`.\n\n```ts\nimport { getDefaultResponseTransformerForAtlasRpc } from '@atlas/rpc-transformers';\n\nconst responseTransformer = getDefaultResponseTransformerForAtlasRpc({\n    allowedNumericKeyPaths: getAllowedNumericKeypaths(),\n});\n```\n\n### `getThrowAtlasErrorResponseTransformer()`\n\nReturns a transformer that throws a `AtlasError` with the appropriate RPC error code if the body of the RPC response contains an error.\n\n```ts\nimport { getThrowAtlasErrorResponseTransformer } from '@atlas/rpc-transformers';\n\nconst responseTransformer = getThrowAtlasErrorResponseTransformer();\n```\n\n### `getResultResponseTransformer()`\n\nReturns 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'`.\n\n```ts\nimport { getResultResponseTransformer } from '@atlas/rpc-transformers';\n\nconst responseTransformer = getResultResponseTransformer();\n```\n\n### `getBigIntUpcastResponseTransformer(allowedNumericKeyPaths)`\n\nReturns 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`.\n\n```ts\nimport { getBigIntUpcastResponseTransformer } from '@atlas/rpc-transformers';\n\nconst responseTransformer = getBigIntUpcastResponseTransformer([\n    ['index'],\n    ['instructions', KEYPATH_WILDCARD, 'accounts', KEYPATH_WILDCARD],\n    ['instructions', KEYPATH_WILDCARD, 'programIdIndex'],\n    ['instructions', KEYPATH_WILDCARD, 'stackHeight'],\n]);\n```\n\n### `getTreeWalkerResponseTransformer(visitors, initialState)`\n\nCreates 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: [] }`.\n\n```ts\nimport { getTreeWalkerResponseTransformer } from '@atlas/rpc-transformers';\n\nconst responseTransformer = getTreeWalkerResponseTransformer(\n    [\n        // Replaces foo.bar with \"baz\".\n        (node, state) => (state.keyPath === ['foo', 'bar'] ? 'baz' : node),\n        // Increments all numbers by 1.\n        node => (typeof node === number ? node + 1 : node),\n    ],\n    { keyPath: [] },\n);\n```\n","readmeFilename":"README.md","_rev":"1-9fbc5f1e13c9325ceab0bcc903c1a1fd"}