Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

knifecycle

Package Overview
Dependencies
Maintainers
1
Versions
103
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 5.1.3 to 5.1.4

10

CHANGELOG.md

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

## [5.1.4](https://github.com/nfroidure/knifecycle/compare/v5.1.3...v5.1.4) (2019-01-26)
### Bug Fixes
* **autoService/Provider:** Fix auto detection for services and providers with no deps ([761921e](https://github.com/nfroidure/knifecycle/commit/761921e))
* **Types:** Fix the provider declaration for optional properties ([cf2abcc](https://github.com/nfroidure/knifecycle/commit/cf2abcc))
## [5.1.3](https://github.com/nfroidure/knifecycle/compare/v5.1.2...v5.1.3) (2019-01-24)

@@ -2,0 +12,0 @@

53

dist/util.js

@@ -192,3 +192,7 @@ "use strict";

function parseInjections(source) {
function parseInjections(source, {
allowEmpty = false
} = {
allowEmpty: false
}) {
const matches = source.match(/^\s*(?:async\s+function(?:\s+\w+)?|async)\s*\(\{\s*([^{}}]+)\s*\}/);

@@ -201,2 +205,6 @@

if (allowEmpty && source.match(/^\s*(?:async\s+function(?:\s+\w+)?|async)\s*\(\s*\)/)) {
return [];
}
throw new _yerror.default('E_AUTO_INJECTION_FAILURE', source);

@@ -343,9 +351,17 @@ }

function autoName(initializer) {
const functionName = parseName(initializer.name || '');
return name(readFunctionName(initializer), initializer);
}
function readFunctionName(aFunction) {
if (typeof aFunction !== 'function') {
throw new _yerror.default('E_AUTO_NAMING_FAILURE', typeof aFunction);
}
const functionName = parseName(aFunction.name || '');
if (!functionName) {
throw new _yerror.default('E_AUTO_NAMING_FAILURE', initializer.name);
throw new _yerror.default('E_AUTO_NAMING_FAILURE', aFunction.name);
}
return name(functionName, initializer);
return functionName;
}

@@ -522,6 +538,11 @@

function autoService(serviceBuilder) {
const name = readFunctionName(serviceBuilder);
const source = serviceBuilder.toString();
const dependencies = parseInjections(source, {
allowEmpty: true
});
return initializer({
name: autoName(serviceBuilder)[SPECIAL_PROPS.NAME],
name,
type: 'service',
inject: autoInject(serviceBuilder)[SPECIAL_PROPS.INJECT]
inject: dependencies
}, serviceBuilder);

@@ -599,8 +620,13 @@ }

function autoProvider(baseInitializer) {
function autoProvider(providerBuilder) {
const name = readFunctionName(providerBuilder);
const source = providerBuilder.toString();
const dependencies = parseInjections(source, {
allowEmpty: true
});
return initializer({
name: autoName(baseInitializer)[SPECIAL_PROPS.NAME],
name,
type: 'provider',
inject: autoInject(baseInitializer)[SPECIAL_PROPS.INJECT]
}, baseInitializer);
inject: dependencies
}, providerBuilder);
}

@@ -675,6 +701,9 @@

function autoHandler(handlerFunction) {
const name = readFunctionName(handlerFunction);
const source = handlerFunction.toString();
const dependencies = parseInjections(source);
return initializer({
name: autoName(handlerFunction)[SPECIAL_PROPS.NAME],
name,
type: 'service',
inject: autoInject(handlerFunction)[SPECIAL_PROPS.INJECT]
inject: dependencies
}, async (...args) => handlerFunction.bind(null, ...args));

@@ -681,0 +710,0 @@ }

@@ -666,3 +666,3 @@ "use strict";

describe('autoService', () => {
it('should detect the provider details', () => {
it('should detect the service details', () => {
const baseServiceBuilder = async function initializeMySQL({

@@ -684,2 +684,17 @@ ENV

});
it('should detect the service details even with no dependencies', () => {
const baseServiceBuilder = async function initializeMySQL() {
return;
};
const newInitializer = (0, _util.autoService)(baseServiceBuilder);
_assert.default.notEqual(newInitializer, baseServiceBuilder);
_assert.default.deepEqual(newInitializer[_util.SPECIAL_PROPS.INJECT], []);
_assert.default.equal(newInitializer[_util.SPECIAL_PROPS.NAME], 'mySQL');
_assert.default.equal(newInitializer[_util.SPECIAL_PROPS.TYPE], 'service');
});
});

@@ -761,2 +776,17 @@ describe('provider', () => {

});
it('should detect the provider details even with no dependencies', () => {
const baseInitializer = async function initializeMySQL() {
return;
};
const newInitializer = (0, _util.autoProvider)(baseInitializer);
_assert.default.notEqual(newInitializer, baseInitializer);
_assert.default.deepEqual(newInitializer[_util.SPECIAL_PROPS.INJECT], []);
_assert.default.equal(newInitializer[_util.SPECIAL_PROPS.NAME], 'mySQL');
_assert.default.equal(newInitializer[_util.SPECIAL_PROPS.TYPE], 'provider');
});
});

@@ -763,0 +793,0 @@ describe('handler', () => {

{
"name": "knifecycle",
"version": "5.1.3",
"version": "5.1.4",
"description": "Manage your NodeJS processes's lifecycle automatically with an unobtrusive dependency injection implementation.",

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

@@ -6,4 +6,4 @@ type Dependencies = { [name: string]: any };

service: S;
dispose: () => Promise<void>;
fatalErrorPromise: Promise<void>;
dispose?: () => Promise<void>;
fatalErrorPromise?: Promise<void>;
}>;

@@ -106,3 +106,3 @@ }

>(
initializer: T,
serviceBuilder: T,
name?: string,

@@ -116,3 +116,3 @@ dependencies?: DependenciesDeclarations,

T extends ServiceInitializer<D, S>
>(initializer: T): T;
>(serviceBuilder: T): T;
export function provider<

@@ -123,3 +123,3 @@ D extends Dependencies,

>(
initializer: T,
providerBuilder: T,
name?: string,

@@ -133,3 +133,3 @@ dependencies?: DependenciesDeclarations,

T extends ProviderInitializer<D, S>
>(initializer: T): T;
>(providerBuilder: T): T;
export function handler<D extends Dependencies, U extends any[], V>(

@@ -136,0 +136,0 @@ handlerInitializer: HandlerInitializer<D, U, V>,

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