Socket
Socket
Sign inDemoInstall

knifecycle

Package Overview
Dependencies
Maintainers
1
Versions
100
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

knifecycle - npm Package Compare versions

Comparing version 2.0.0 to 2.1.0

10

CHANGELOG.md

@@ -0,1 +1,11 @@

<a name="2.1.0"></a>
# [2.1.0](https://github.com/nfroidure/knifecycle/compare/v2.0.0...v2.1.0) (2017-06-04)
### Features
* **Util:** Add a function to decorate initializers ([477ad14](https://github.com/nfroidure/knifecycle/commit/477ad14))
<a name="2.0.0"></a>

@@ -2,0 +12,0 @@ # [2.0.0](https://github.com/nfroidure/knifecycle/compare/v1.4.0...v2.0.0) (2017-05-28)

@@ -11,2 +11,3 @@ 'use strict';

exports.reuseSpecialProps = reuseSpecialProps;
exports.wrapInitializer = wrapInitializer;
exports.inject = inject;

@@ -74,2 +75,18 @@ exports.options = options;

/**
* Allows to wrap an initializer to add extra
* @param {Function} wrapper
* A function taking dependencies and the base
* service in arguments
* @param {Function} baseInitializer
* The initializer to decorate
* @return {Function}
* The new initializer
*/
function wrapInitializer(wrapper, baseInitializer) {
return reuseSpecialProps(baseInitializer, function (services) {
return baseInitializer(services).then(wrapper.bind(null, services));
});
}
/**
* Decorator creating a new initializer with some

@@ -76,0 +93,0 @@ * dependencies declarations appended to it.

@@ -7,2 +7,6 @@ 'use strict';

var _sinon = require('sinon');
var _sinon2 = _interopRequireDefault(_sinon);
var _util = require('./util');

@@ -54,2 +58,32 @@

describe('wrapInitializer', function (done) {
it('should work', function () {
function baseInitializer() {
return Promise.resolve(function () {
return 'test';
});
}
baseInitializer.$name = 'baseInitializer';
baseInitializer.$type = 'service';
baseInitializer.$inject = ['log'];
baseInitializer.$options = { singleton: false };
var log = _sinon2.default.stub();
var newInitializer = (0, _util.wrapInitializer)(function (_ref, service) {
var log = _ref.log;
log('Wrapping...');
return function () {
return service() + '-wrapped';
};
}, baseInitializer);
newInitializer({ log: log }).then(function (service) {
_assert2.default.equal(service(), 'test-wrapped');
_assert2.default.deepEqual(log.args, [['Wrapping...']]);
}).then(done).catch(done);
});
});
describe('parseDependencyDeclaration', function () {

@@ -56,0 +90,0 @@ it('should work', function () {

2

package.json
{
"name": "knifecycle",
"version": "2.0.0",
"version": "2.1.0",
"description": "Manage your NodeJS processes's lifecycle.",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -344,2 +344,5 @@ <!--

</dd>
<dt><a href="#wrapInitializer">wrapInitializer(wrapper, baseInitializer)</a> ⇒ <code>function</code></dt>
<dd><p>Allows to wrap an initializer to add extra</p>
</dd>
<dt><a href="#inject">inject(dependenciesDeclarations, initializer, [merge])</a> ⇒ <code>function</code></dt>

@@ -628,2 +631,15 @@ <dd><p>Decorator creating a new initializer with some

<a name="wrapInitializer"></a>
## wrapInitializer(wrapper, baseInitializer) ⇒ <code>function</code>
Allows to wrap an initializer to add extra
**Kind**: global function
**Returns**: <code>function</code> - The new initializer
| Param | Type | Description |
| --- | --- | --- |
| wrapper | <code>function</code> | A function taking dependencies and the base service in arguments |
| baseInitializer | <code>function</code> | The initializer to decorate |
<a name="inject"></a>

@@ -630,0 +646,0 @@

@@ -47,2 +47,21 @@ import YError from 'yerror';

/**
* Allows to wrap an initializer to add extra
* @param {Function} wrapper
* A function taking dependencies and the base
* service in arguments
* @param {Function} baseInitializer
* The initializer to decorate
* @return {Function}
* The new initializer
*/
export function wrapInitializer(wrapper, baseInitializer) {
return reuseSpecialProps(
baseInitializer,
services =>
baseInitializer(services)
.then(wrapper.bind(null, services))
);
}
/**
* Decorator creating a new initializer with some

@@ -49,0 +68,0 @@ * dependencies declarations appended to it.

import assert from 'assert';
import sinon from 'sinon';
import {
reuseSpecialProps,
wrapInitializer,
parseDependencyDeclaration,

@@ -45,2 +47,32 @@ } from './util';

describe('wrapInitializer', (done) => {
it('should work', () => {
function baseInitializer() {
return Promise.resolve(() => 'test');
}
baseInitializer.$name = 'baseInitializer';
baseInitializer.$type = 'service';
baseInitializer.$inject = ['log'];
baseInitializer.$options = { singleton: false };
const log = sinon.stub();
const newInitializer = wrapInitializer(
({ log }, service) => {
log('Wrapping...');
return () => service() + '-wrapped';
},
baseInitializer
);
newInitializer({ log })
.then((service) => {
assert.equal(service(), 'test-wrapped');
assert.deepEqual(log.args, [['Wrapping...']]);
})
.then(done)
.catch(done);
});
});
describe('parseDependencyDeclaration', () => {

@@ -47,0 +79,0 @@ it('should work', () => {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc