{"_id":"@atlaschain/rpc-subscriptions-spec","name":"@atlaschain/rpc-subscriptions-spec","dist-tags":{"latest":"3.0.0"},"versions":{"3.0.0":{"name":"@atlaschain/rpc-subscriptions-spec","version":"3.0.0","description":"A generic implementation of JSON RPC Subscriptions using proxies","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"],"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":"3.0.0","@atlaschain/rpc-spec-types":"3.0.0","@atlaschain/promises":"3.0.0","@atlaschain/subscribable":"3.0.0"},"peerDependencies":{"typescript":">=5.3.3"},"engines":{"node":">=20.18.0"},"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/@atlaschain/test-config/jest-dev.config.ts --rootDir . --watch","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/@atlaschain/test-config/jest-lint.config.ts --rootDir . --silent","test:prettier":"TERM_OVERRIDE=\"${TURBO_HASH:+dumb}\" TERM=${TERM_OVERRIDE:-$TERM} jest -c ../../node_modules/@atlaschain/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/@atlaschain/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/@atlaschain/test-config/jest-unit.config.node.ts --rootDir . --silent"},"_id":"@atlaschain/rpc-subscriptions-spec@3.0.0","homepage":"https://github.com/anza-xyz/kit#readme","_integrity":"sha512-2Xzh6EXXiSndKOKHV/t2JtVjC20WXVL40pRMvbpNRPMgaHB2JSaWRNiloUuEwqcih6p8ixiFu5askOxQC1nKqw==","_resolved":"/private/var/folders/q8/nr55p0wd491c6fjmbky17kd00000gn/T/22e29a801a05d1be0c10bc79de778453/atlaschain-rpc-subscriptions-spec-3.0.0.tgz","_from":"file:atlaschain-rpc-subscriptions-spec-3.0.0.tgz","_nodeVersion":"22.12.0","_npmVersion":"10.9.0","dist":{"integrity":"sha512-2Xzh6EXXiSndKOKHV/t2JtVjC20WXVL40pRMvbpNRPMgaHB2JSaWRNiloUuEwqcih6p8ixiFu5askOxQC1nKqw==","shasum":"fe1f4329de1eadbba944b06cfa0e865afaea3e4c","tarball":"https://registry.npmjs.org/@atlaschain/rpc-subscriptions-spec/-/rpc-subscriptions-spec-3.0.0.tgz","fileCount":5,"unpackedSize":13733,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDp/NKT96TlERMy2a/6HyZCLi4q2oWtdrtNVEM0/MUznwIhAIbzljS0EmGNx7Lx7cjWhw08juFtyky59X94RfNZZZnF"}]},"_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-subscriptions-spec_3.0.0_1764611552341_0.05098072346841609"},"_hasShrinkwrap":false}},"time":{"created":"2025-12-01T17:52:32.261Z","3.0.0":"2025-12-01T17:52:32.547Z","modified":"2025-12-01T17:52:32.807Z"},"maintainers":[{"name":"atlaschain","email":"jq@atlaschain.org"}],"description":"A generic implementation of JSON RPC Subscriptions using proxies","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-subscriptions-spec?style=flat\n[npm-image]: https://img.shields.io/npm/v/@atlas/rpc-subscriptions-spec?style=flat\n[npm-url]: https://www.npmjs.com/package/@atlas/rpc-subscriptions-spec\n\n# @atlas/rpc-subscriptions-spec\n\nThis 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 [`@atlas/kit`](https://github.com/anza-xyz/kit/tree/main/packages/kit).\n\nThis API is designed to be used as follows:\n\n```ts\nconst rpcSubscriptions =\n    // Step 1 - Create a `RpcSubscriptions` instance. This may be stateful.\n    createAtlasRpcSubscriptions(mainnet('wss://api.mainnet-beta.atlas.com'));\nconst response = await rpcSubscriptions\n    // Step 2 - Call supported methods on it to produce `PendingRpcSubscriptionsRequest` objects.\n    .slotNotifications({ commitment: 'confirmed' })\n    // Step 3 - Call the `subscribe()` method on those pending requests to trigger them.\n    .subscribe({ abortSignal: AbortSignal.timeout(10_000) });\n// Step 4 - Iterate over the result.\ntry {\n    for await (const slotNotification of slotNotifications) {\n        console.log('Got a slot notification', slotNotification);\n    }\n} catch (e) {\n    console.error('The subscription closed unexpectedly', e);\n} finally {\n    console.log('We have stopped listening for notifications');\n}\n```\n\n## Types\n\n### `RpcSubscriptionsChannel<TOutboundMessage, TInboundMessage>`\n\nA 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.\n\n### `RpcSubscriptionsChannelCreator<TOutboundMessage, TInboundMessage>`\n\nA channel creator is a function that accepts an `AbortSignal`, returns a new `RpcSubscriptionsChannel`, and tears down the channel when the abort signal fires.\n\n### `RpcSubscriptionChannelEvents<TInboundMessage>`\n\nSubscription channels publish events on two channel names:\n\n- `error`: Fires when the channel closes unexpectedly\n- `message`: Fires on every message received from the remote end\n\n## Functions\n\n### `executeRpcPubSubSubscriptionPlan({ channel, responseTransformer, signal, subscribeRequest, unsubscribeMethodName })`\n\nGiven a channel, this function executes the particular subscription plan required by the Atlas JSON RPC Subscriptions API.\n\n1. Calls the `subscribeRequest` on the remote RPC\n2. Waits for a response containing the subscription id\n3. Returns a `DataPublisher` that publishes notifications related to that subscriptions id, filtering out all others\n4. Calls the `unsubscribeMethodName` on the remote RPC when the abort signal is fired.\n\n### `transformChannelInboundMessages(channel, transform)`\n\nGiven 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.\n\nFor instance, it can be used to parse incoming JSON messages:\n\n```ts\nconst transformedChannel = transformChannelInboundMessages(channel, JSON.parse);\n```\n\n### `transformChannelOutboundMessages(channel, transform)`\n\nGiven 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`.\n\nFor instance, it can be used to stringify JSON messages before sending them over the wire:\n\n```ts\nconst transformedChannel = transformChannelOutboundMessages(channel, JSON.stringify);\n```\n","readmeFilename":"README.md","_rev":"1-b9dc2694eb45c5175da0cf033a0831f0"}