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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@hisorange/circuit

v0.4.2

Published

Versatile messaging library with support for multiple transport medium.

Downloads

6

Readme

Circuit Logo

Circuit - Versatile Messaging Solution written in Typescript

Version Build Coverage Status GitHub license

Easy to use package to manage asynchronous messaging through multiple medium. Supports the most common publish / subscribe, and RPC (Remote Procedure Call) methodologies.

Why should you use it? Because it's built for progression!

It's written for projects where the transporting medium will change overtime; There are solutions with support a single medium and all of it's advantages.

But as far as we aware, most of the project starts small and hopefully they grow requirements over time, so it would be utmost wasteful to start your micro application on a high throughput messaging medium like kafka.

Out of the box the package starts with a simple in-memory transport, with this you can kickstart your project without external requirements. And as time goes you can easily upgrade to better transports like redis, amqp, etc... with just a single line of code, so no need for refactoring!

Getting Started


npm i @hisorange/circuit
# or
yarn add @hisorange/circuit

Example: Remote Procedure Call


// Initialize your transport driver
const transport = new IoRedisTransport();

// Initialize the nodes (different machines IRL)
const node1 = new Circuit('node1', transport);
const node2 = new Circuit('node2', transport);

// Estabilize the connections
await node1.connect();
await node2.connect();

// Create a responder
await node1.respond<SumAction>('sum' (msg) => msg.content.a + msg.content.b);

// Request the responder to execute the call
assert(await node2.request<SumAction>('sum', { a: 2, b: 2}) === 4);

Request options

| Key | Default | Description | | ------- | ------- | ----------------------------------------------- | | ttl | 60000 | Maximum wait time before the message is ignored |

Response options

| Key | Default | Description | | --------------- | -------- | ---------------------------- | | concurrency | Infinity | Maximum concurrent execution |

Example: Publish / Subscribe


const node = new Circuit();

// Simply publish the event you want to broadcast
node.publish<UserCreatedEvent>('user.created', user);

// And receive it on every listening node ^.^
node.subscribe<UserCreatedEvent>('user.created', sendWelcomeEmailToUser);

Technicalities


TypeScript: Everything is written in typescript from the get go, so You can have the best DX possible :)

Response Routing: When You are using the RPC request/respond model, the package manages the responses on a single channel to reduce the load on the messaging queue, with this small solution the queue does not have to open and close channels on every single RPC call.

Network Mapping: Before You send a request the circuit checks if there is anyone to serve it, this helps to prevent hanging requests. Each circuits on the network communicates their services to every other circuit, so the requests can be routed to specific actors.

Supported Transport Mediums

| Transport | Dependency | Support | Notes | | :----------- | ------------------------------------------------ | :---------: | ------------------------------------- | | InMemory | - | ✓ | Emulates an external queue's behavior | | Redis | ioredis | ✓ | Excellent for smaller installations | | RabbitMQ | amqplib | Coming Soon | Purpose designed messaging platform | | NATS | - | Coming Soon | Fast and small messaging platform | | Kafka | - | - | High throughput scalable solution |

Links


What's with the weird name?


This package is part of a theme where I am trying to reuse the hardware namings in code and let the programers build on familiar known solutions. The circuit represents the circuit board similar to what we have on a PCB the listeners connect to lines and the board is simply handling the connections between them.

Changelog


Track changes in the Changelog