@exodus/module
Advanced tools
Comparing version 1.0.0 to 1.1.0
{ | ||
"name": "@exodus/module", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Exodus base module implementation.", | ||
@@ -21,3 +21,3 @@ "author": "diegomura <diegomuracciole@gmail.com>", | ||
"scripts": { | ||
"lint": "eslint .", | ||
"lint": "eslint . --ignore-path ../../.gitignore", | ||
"lint:fix": "yarn lint --fix", | ||
@@ -30,5 +30,11 @@ "test": "jest" | ||
"dependencies": { | ||
"@exodus/basic-utils": "^1.0.0", | ||
"events": "^1.1.1", | ||
"lodash": "^4.17.11", | ||
"proxy-freeze": "^1.0.0" | ||
} | ||
}, | ||
"devDependencies": { | ||
"jest": "^29.1.2" | ||
}, | ||
"gitHead": "d293d2fc68887f11bd7a925cda043a2a01cc2899" | ||
} |
# Exodus Module | ||
[![npm][npm-image]][npm-url] | ||
[npm-image]: https://img.shields.io/npm/v/@exodus/module.svg?style=flat-square | ||
[npm-url]: https://www.npmjs.com/package/@exodus/module | ||
Exodus base module implementation. | ||
@@ -26,3 +22,3 @@ | ||
class ContactsModule extends ExodusModule { | ||
constructor () { | ||
constructor() { | ||
super({ name: 'ContactsModule' }) | ||
@@ -29,0 +25,0 @@ } |
@@ -1,4 +0,7 @@ | ||
import { EventEmitter } from 'events' | ||
import { bindAll, functions } from 'lodash' | ||
import EventEmitter from 'events/' // '/' forces it to use the module from node_modules | ||
import { bindAll, clone, functions } from 'lodash' | ||
import { pick } from '@exodus/basic-utils' | ||
import proxyFreeze from 'proxy-freeze' | ||
import { InvalidModuleError } from './errors' | ||
@@ -9,2 +12,4 @@ import createLogger from './logger' | ||
const dependencyInjectionFields = ['id', 'dependencies'] | ||
export default class ExodusModule extends EventEmitter { | ||
@@ -27,1 +32,33 @@ _name | ||
} | ||
export const validateModule = (module) => { | ||
const { id, dependencies } = module | ||
if (typeof id !== 'string') { | ||
throw new InvalidModuleError('expected property "id"') | ||
} | ||
if (!Array.isArray(dependencies) || dependencies.some((dep) => typeof dep !== 'string')) { | ||
throw new InvalidModuleError('expected property "dependencies"') | ||
} | ||
} | ||
const defineDependencyInjectionField = (target, field, value) => | ||
Object.defineProperty(target, field, { | ||
writable: false, | ||
value: Object.freeze(clone(value)), | ||
}) | ||
export const exportModuleFactoryFromConstructor = (Clazz) => { | ||
validateModule(Clazz) | ||
const factory = (opts) => new Clazz(pick(opts, Clazz.dependencies)) | ||
const dependencyInjectionFieldValues = pick(Clazz, dependencyInjectionFields) | ||
setDependencyInjectionFields(factory, dependencyInjectionFieldValues) | ||
validateModule(factory) | ||
return factory | ||
} | ||
// e.g. setDependencyInjectionFields(factory, { id, dependencies }) | ||
export const setDependencyInjectionFields = (factory, dependencyInjectionFieldValues) => | ||
dependencyInjectionFields.forEach((field) => | ||
defineDependencyInjectionField(factory, field, dependencyInjectionFieldValues[field]) | ||
) |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
4240
5
61
4
1
32
1
+ Added@exodus/basic-utils@^1.0.0
+ Addedevents@^1.1.1
+ Added@exodus/basic-utils@1.5.0(transitive)
+ Addedevents@1.1.1(transitive)
+ Addedminimalistic-assert@1.0.1(transitive)