Warning
This project is currently under development and is not yet ready for production use.
The Fuel Streams TypeScript SDK provides a simple and robust way to interact with a NATS server, enabling seamless integration of pub/sub patterns, message streaming, and typed data structures. This SDK extends the capabilities of NATS by supporting type-safe interactions and convenient utilities for developers.
- Typed Pub/Sub: Publish and subscribe to NATS subjects with strong typing support
- Wildcard Filtering: Consume messages from subjects with wildcards for flexible subscription patterns
- Stream Management: Efficiently handle streaming data with utilities like
BlockStream
- Ease of Use: Intuitive APIs for initializing clients and managing subjects
- Type Safety: Full TypeScript support with typed data structures
- Multiple Stream Types: Support for blocks, transactions, receipts, inputs, outputs, and logs
Install the SDK using npm, yarn, or pnpm:
npm install @fuels/streams
# or
yarn add @fuels/streams
# or
pnpm add @fuels/streams
Here are some examples to get you started with the Fuel Streams TypeScript SDK:
import { Client, ClientOpts } from '@fuels/streams';
async function main() {
const opts = new ClientOpts();
const client = await Client.connect(opts);
console.log('Connected to NATS');
}
main().catch(console.error);
import { Client, ClientOpts, BlocksSubject, BlockStream } from '@fuels/streams';
async function main() {
const opts = new ClientOpts();
const client = await Client.connect(opts);
const stream = await BlockStream.init(client);
const subscription = await stream.subscribe(BlocksSubject.all());
for await (const msg of subscription) {
console.log(`Received block message: ${msg.key}`);
}
await stream.flushAwait();
}
main().catch(console.error);
import { BlockStream, BlocksSubject, Client, ClientOpts } from '@fuels/streams';
async function main() {
const opts = new ClientOpts();
const client = await Client.connect(opts);
const stream = await BlockStream.init(client);
// Create a filtered subject for blocks at height 1000
const filteredSubject = new BlocksSubject().withHeight(1000);
const consumer = await stream.subscribeConsumer({
filterSubjects: [filteredSubject],
});
const iter = await consumer.consume({ max_messages: 10 });
for await (const msg of iter) {
console.log(`Received filtered block message: ${msg.subject}`);
}
await stream.flushAwait();
}
main().catch(console.error);
Contributions are welcome! Please feel free to submit a Pull Request. For more information on contributing, please see our Contributing Guidelines.
This project is licensed under the MIT License - see the LICENSE file for details.