extending hyper — ->

hyper
2 min readJan 28, 2022

--

TL;DR; Check out our new hyper extension — https://github.com/hyper63/hyper-ext-counter — with this extension you can use the cache service to increment, decrement counters by a key name.

extensibility

hyper is designed with the ability to extend any API without directly affecting the core API design and functionality, the counter module is our first implementation of extending the hyper core API. The counter module leverages the cache API to create a more specialized API that increments, decrements and resets a numeric value in your hyper cache store. This specialization, will enable developers to quickly implement counter functionality in their applications. We plan to continue to provide extensions for the hyper-connect client that compose the primitive services together for more specialized services, while maintaining a general purpose.

hyper-ext-counter

The counter extension gives developers the ability to easily increment and decrement a unique key in the cache store.

Install

npm install hyper-connect hyper-ext-counter

⚡️ create a free hyper account at https://dashboard.hyper.io then get a connection string and create an ENVIRONMENT VARIABLE

HYPER=[CONNECTION STRING]

Initialize

import { connect } from 'hyper-connect'
import { counter } from 'hyper-ext-counter'

const hyper = counter(connect(process.env.HYPER))

Increment

The increment command will read the current value from the cache and increment that value by 1 and store the new value on the cache and return the new value.

const widgetCount = await hyper.ext.counter.inc('widgets')
console.log(widgetCount)

Decrement

The decrement command will read the current value from the cache and decrement the value by 1 and store the new value on the cache return the new value.

const widgetCount = await hyper.ext.counter.dec('widgets')
console.log(widgetCount)

Reset

The reset command will reset the current value in the cache to zero and return zero to the caller.

const widgetCount = await hyper.ext.counter.reset('widgets')
console.log(widgetCount)

Each of these commands take a single argument, this argument is a unique key in the cache store and can be called whatever the developer chooses as long as it is alphanumeric and does not contain any non-alphanumeric characters and starts with an alpha character (a-z).

summary

hyper services are built to extend and provide consistent general value that can be combined in several ways to create re-usable purposeful functionality. These extensions can speed up application development of business rules as well as maintain a clear separation from the business layer and the services layer.

--

--

hyper
hyper

Written by hyper

build hyper-scale applications with hyper services

No responses yet