Research
Security News
Kill Switch Hidden in npm Packages Typosquatting Chalk and Chokidar
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Auto dependency injector for typescript.
This is a proof of concept project, it may not be stable.
$ npm install autoinject
import {autoInject, dependencyInjection} from 'autoinject';
class User {
test = 'It works fine';
}
@autoInject
class Db {
user: User;
constructor(user: User) {
this.user = user;
}
}
@autoInject
class MyClass {
db: Db;
constructor(db: Db) {
this.db = db;
}
}
const myClass = dependencyInjection(MyClass);
console.log(myClass.db.user.test);
All dependencies are stored on a static prototype on the target object.
import {autoInject} from 'autoinject';
import {Db} from 'db';
@autoInject
class Controller {
constructor(db: Db) {}
}
console.log(Controller.inject); // [ Db ]
You can also auto instantiate a class
import {autoInject, autoInstantiate} from 'autoinject';
class User {
test = 'It works fine';
}
@autoInjecte
class Db {
constructor(public user: User) {}
}
@autoInstantiate
class MyClass {
constructor(public db?: Db) {}
}
var k = new MyClass();
console.log(k.db.user.test); // output: "It works fine"
You can always override the inject (for testing purpose)
// http.ts
class Http {
get(url: string) {
// some logic
}
}
export {Http};
// image-repository.ts
import {autoInject} from 'autoinject';
import {Http} from './http';
@autoInjecte
class ImageRepository {
http: Http;
constructor(http: Http) {
this.http = http;
}
getImage() {
return this.http.get('/image');
}
}
export {ImageRepository};
// test.ts
import {dependencyInjection} from 'autoinject';
import {ImageRepository} from './image-repository';
const httpMock = {
get() {
return 'Nice';
}
};
ImageRepository.inject = [httpMock];
const imageRepository = dependencyInjection(ImageRepository);
console.assert(imageRepository.getImage(), 'Nice');
Include the typing with:
"moduleResolution": "node"
in your tsconfig.json
FAQs
Autoinject classes
We found that autoinject demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.