Socket
Socket
Sign inDemoInstall

pdi

Package Overview
Dependencies
4
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.0 to 1.1.1

.travis.yml

3

package.json
{
"name": "pdi",
"version": "1.1.0",
"version": "1.1.1",
"description": "Minimal Promise based dependency injection framework",

@@ -14,2 +14,3 @@ "main": "src/index.js",

"bluebird": "^3.4.1",
"debug": "^3.0.0",
"ramda": "^0.21.0"

@@ -16,0 +17,0 @@ },

@@ -1,3 +0,5 @@

PDI - Minimal Promise based Dependency Injection framework
# PDI - Minimal Promise based Dependency Injection framework
[![Build Status](https://travis-ci.org/davidgtonge/pdi.svg?branch=master)](https://travis-ci.org/davidgtonge/pdi)
This is a simple library that provides a powerful abstraction for dealing with dependency injection both for system start up and for complex async tasks.

@@ -4,0 +6,0 @@

const Promise = require("bluebird")
const {is, always, zipObj, contains, reduce, flatten, curry,
values, map, flip, apply, prop, compose, merge, difference,
pluck, filter, forEach} = require("ramda")
const debug = require("debug")("pdi")
const {
is,
always,
zipObj,
contains,
reduce,
flatten,
curry,
values,
map,
flip,
apply,
prop,
compose,
merge,
difference,
pluck,
filter,
forEach,
} = require("ramda")
const reducer = curry((hash, name, memo, item) => {
if(!hash[item]) {
if (!hash[item]) {
throw new Error(`${name} depends on ${item} which hasn't been registered`)
}
let deps = hash[item].deps
if(contains(name, deps)) {
if (contains(name, deps)) {
throw new Error(`Circular dependency for ${name} within ${item}`)

@@ -20,9 +38,9 @@ }

const mapper = curry((hash, {name, deps, fn}) => {
const mapper = curry((hash, { name, deps, fn }) => {
const result = reduce(reducer(hash, name), [], deps)
return {result, deps, name, fn}
return { result, deps, name, fn }
})
function move(subset, from, to) {
forEach((item) => {
forEach(item => {
const fromPos = from.indexOf(item)

@@ -37,5 +55,5 @@ from.splice(fromPos, 1)

const output = []
while(input.length) {
while (input.length) {
const sorted = compose(pluck("name"), flatten)(output)
const ready = filter(({result}) => {
const ready = filter(({ result }) => {
return difference(result, sorted).length === 0

@@ -49,7 +67,3 @@ }, input)

function checkAndSortDependencies(obj) {
return compose(
sorter,
values,
map(mapper(obj))
)(obj)
return compose(sorter, values, map(mapper(obj)))(obj)
}

@@ -59,4 +73,4 @@

const names = pluck("name", items)
console.log(`Initialising ${names.join(", ")}`)
return Promise.map(items, (item) => {
debug(`Initialising ${names.join(", ")}`)
return Promise.map(items, item => {
const args = map(flip(prop)(memo), item.deps)

@@ -100,3 +114,3 @@ return Promise.resolve(apply(item.fn, args))

}
registry[name] = {fn, deps, name}
registry[name] = { fn, deps, name }
}

@@ -107,7 +121,7 @@ function start(deps, fn) {

}
console.log("First add", firstAdd - startTime)
console.log("Activation started", Date.now() - startTime)
debug("First add", firstAdd - startTime)
debug("Activation started", Date.now() - startTime)
const sorted = checkAndSortDependencies(registry)
return startActivation(sorted).then((_modules) => {
console.log("Activation complete", Date.now() - startTime)
return startActivation(sorted).then(_modules => {
debug("Activation complete", Date.now() - startTime)
modules = _modules

@@ -117,3 +131,3 @@ activated = true

if (deps && fn) {
console.log(`Running start function with ${deps.join(", ")}`)
debug(`Running start function with ${deps.join(", ")}`)
result = apply(fn, map(flip(prop)(modules), deps))

@@ -143,3 +157,3 @@ }

return {add, start, clear, __test}
return { add, start, clear, __test }
}

@@ -146,0 +160,0 @@

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc