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

@treats/addons-base

v0.4.3

Published

Treats Addons Base

Downloads

8

Readme

Treats Addons Base

Curated list of basic addons for Treats

Helpers

(@treats/addons-base/helper)

Redis

Redis client helper using redis package

Specify the redis configuration on the runtime config:

{
    ...,
    "helper": {
        ...,
        "redis": {
            "my_redis": {
                "host": "my-redis.host",
                "port": "6379"
            }
        }
    }
}

To use your redis client:

const redisHelper = app.get("redis"),
    myClient = redisHelper.get("my_redis");

//Then you can do any redis command with the said client
myClient.set("my_key", my_val);

Postgre

Postgre client helper using pg-promise package

Specify the postgre configuration on the runtime config:

{
    ...,
    "helper": {
        ...,
        "postgre": {
            "my_db": {
                "host": "my-redis.host",
                "port": "6379"
            }
        }
    }
}

To use your postgre client:

const postgreHelper = app.get("postgre"),
    myClient = postgreHelper.get("my_db");

// Then you can use your pgPromise client normally
myClient.any('SELECT * FROM users WHERE name = $1', 'John')

Datadog

Datadog is a powerful modern monitoring Infrastructure-as-a-Service for cloud applications. This helper provides client for Datadog (or any monitoring services that hot-shots supported).

You HAVE to set the runtime config for the StatsD client or it'll never initialize.

{
    ...,
    "helper": {
        ...,
        "datadog": {
            "host": "localhost"
        }
    }
}

Then you can use your StatsD client with track command:

const datadogHelper = app.get("datadog");

// You can use the helper with track, any arguments after your metric type and metric name would be passed to StatsD clint directly
datadogHelper.track("histogram", "my_metric", argument1, argument2,...)

Track method parameters:

    datadogHelper.track(
        metric_type: String,
        metric_name: String,
        ...metric_arguments
    );
  • metric_type - Metric type, for example: histogram, increment, etc.
  • metric_name - Metric name, any name that you would query on your dashboard.
  • metric_arguments - Metric arguments that would be passed to the StatsD client calls.

CircuitBreaker

Circuit Breaker pattern are useful in microservices world to avoid remote calls hung up indefinitely and blocking your critical resources. In this helper, we use opossum npm package.

You HAVE to set a default config for circuitbreaker instance to make it work.

{
    ...,
    "helper": {
        ...,
        "circuitbreaker": {
            ...,
            "endpoint1": {
                "timeout": 1000,
                "errorThresholdPercentage": 50,
                "resetTimeout": 30000
            },
            "default": {
                "timeout": 3000,
                "errorThresholdPercentage": 50,
                "resetTimeout": 30000
            }
        }
    }
}

You can then use the Circuit Breaker instance with:

const cbHelper = app.get("circuitbreaker");

function asyncFunctionThatCouldFail (x, y) {
  return new Promise((resolve, reject) => {
    // Do something, maybe on the network or a disk
  });
}

// Wrap the call with our CB instance
cbHelper.call(asyncFunctionThatCouldFail, "endpoint1", [1, 2]);

// Endpoint with no runtime configuration will fallback to the default configuration that we specified before
cbHelper.call(asyncFunctionThatCouldFail, "endpoint2", [1, 2]);

Call method parameters:

cbHelper.call(
    promiseCall: Function,
    endpoint: String,
    params: Array<Any>,
    callbacks: { [string]: Function }
)
  • promiseCall - Function that would be wrapped with the circuit breaker.
  • endpoint - Name of the endpoint/index of this call, this would be used to get the circuit breaker instance that would be applied.
  • params - Parameters that would be used to call the wrapped function.
  • callbacks - Callback functions that would be triggered when the circuit breaker instance reached certain conditions.
    • onSuccess - Triggered on every success calls.
    • onFailure - Triggered on failure calls.
    • onOpen - Triggered when circuit breaker instance entered open status.
    • onClose - Triggered when circuit breaker instance entered close status.
    • onHalfOpen - Triggered when circuit breaker instance entered half open status.
    • onReject - Triggered when calls are rejected.
    • onTimeout - Triggered timeout reached.

Generators

(@treats/addons-base/generator)

Opinionated

Generator template to setup opinonated development environment like Eslint and Stylelint.

treats generate @treats/addons-base/generator/opinionated

Docker

Generator template to setup dockerfile and docker compose for Treats

treats generate @treats/addons-base/generator/docker

License

Apache 2.0