New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

wrappa

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wrappa

Connector wrapper in order to make using async connector in a sync way.

latest
Source
npmnpm
Version
0.0.13
Version published
Weekly downloads
10
900%
Maintainers
1
Weekly downloads
 
Created
Source

wrappa

Build Status Coverage Status

Promise-delayer and connection object stubber in order to be able to use async connectors with sync limitations.

Synopsis

Example usage with amqplib in a factory for electrolyte.

const amqp = require("amqplib");
const {ChannelModel} = require("amqplib/lib/channel_model");
const Wrappa = require("wrappa");

const connectionString = "justAnExampleConnectionString";

module.exports = function createRmqInstance() {
  return new Wrappa(() => amqp.connection(connectionString), ChannelModel).getWrappedConnectionClass();
};

module.exports["@require"] = ["base/configuration"];
module.exports["@singleton"] = true;

The fellow would return a mock equivalent for an instance of ChannelModel, every call will return a promise, they'll be delayed until the connection function returns the connection then it'll be casted to the connection instance, by default there's lazyness built in, so the connectionFactoryFn described upper will not be called until there's at least one call from the mock returned.

API

Wrappa(connectionFactoryFn, ConnectionClass);

Returns an instance of Wrappa.

wrappa.getWrappedConnectionClass()

Returns a callable mock equivalent to ConnectionClass.

More

These are the main functions only, please find the rest at the tests.

Why the heck i would use it anyways?

An example use-case:

Given that most IoC containers are sync, You might encounter the situation that You have to use a library which provides only async return of it's connection object, but You don't want to hack through it yourself nor You want to add extra noise to every place where the lib is used to wait for the connection.

So You can then make a go with Wrappa and hopefully skip the suffering.

Code examples to be added.

Questions, suggestions

Suggestions and constructive critique is highly appreciated, please feel free to drop me a line at hello@danielgulyas.me. :) Questions also welcome!

Keywords

async

FAQs

Package last updated on 28 Oct 2016

Did you know?

Socket

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.

Install

Related posts