
Security News
PEP 810 Proposes Explicit Lazy Imports for Python 3.15
An opt-in lazy import keyword aims to speed up Python startups, especially CLIs, without the ecosystem-wide risks that sank PEP 690.
@twolions/warmer-backend-utilities
Advanced tools
Collection of common NodeJS utilities used in Warmer's backend services
Collection of common NodeJS utilities used in Warmer's backend services
npm i -S @twolions/warmer-backend-utilities
AMQPClient
Used to send and receive messages from a RabbitMQ broker.
AMQPClient
expects RABBITMQ_URL
and RABBITMQ_DLX
to be defined in process.env
.
The name of the queue to connect to.
const { AMQPClient } = require('@twolions/warmer-backend-utililies');
const client = new AMQPClient('<queue>');
// send a message to the queue
await client.send({ type: 'email:send', payload: {...} });
// receive messages from queue
//
// this is a process that last for the duration of the process itself; if you want to use it along with other processes (http server, etc...) do not `await client.receive`.
await client.receive((msg) => { ... });
// acknowledge a message
client.ack(msg);
// reject a message
// if requeue is false, messages will end up in DLQ, otherwise they will be sent back to the queue where they were consumed from
client.reject(msg, opts = { requeue = false });
// close connection
await client.close();
validateRequest
A Koa middleware to validate ctx.query
, ctx.params
, ctx.body
.
validateRequest
uses ajv
under the hood to perform validations (defined with JSON Schema).
A Simplified representation of a JSON Schema:
'?'
to denote them as optionaladditionalProperties: false
set; you can override this by having '*': true
required
array, with the keys of non-optional fieldsvoid
const { validateRequest } = require('@twolions/warmer-backend-utilities')
router.post(
'/',
validateRequest({
params: {
id: { type: 'string', minLength: 1 }
},
body: {
'optional?': { type: 'string' }
nested: {
type: { type: 'string', minLength: 1 },
'count?': { type: 'number', minLength: 1 },
},
},
}),
async (ctx) => {
const { id } = ctx.request.params;
const { optional, nested } = ctx.request.body;
// optional and nested.count can be `null`
},
)
validate
A function that uses the same simplified representation of a JSON Schema as validateRequest
, but to validate any value you might require.
A Simplified representation of a JSON Schema:
The value to validate against schema
{
valid: Boolean,
errors: Array,
}
const { validate } = require('@twolions/warmer-backend-utilities')
sleep
⏰
async
function
Returns a promise that resolves after ms
miliseconds.
Number of miliseconds to wait before resolving promise
void
await sleep(1000); // will wait one second before resolving
retry
⏰
async
function
Function to retry.
Configuration options. Defaults to 3 attempts with no delay.
{
attempts: 3,
delay: 0,
}
Whatever the return value of fn
argument is.
Throws if attempts are reached without fn
resolving.
await retry(possiblyFailingFunction, { attempts: 10, delay: 100 });
FAQs
Collection of common NodeJS utilities used in Warmer's backend services
We found that @twolions/warmer-backend-utilities demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
An opt-in lazy import keyword aims to speed up Python startups, especially CLIs, without the ecosystem-wide risks that sank PEP 690.
Security News
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
Security News
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.