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

@exodus/module

Package Overview
Dependencies
Maintainers
85
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@exodus/module - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

src/errors.js

12

package.json
{
"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])
)
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