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

di-check-deps

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

di-check-deps

Type utility to check whether your dependencies resolvers are not missing any dependencies at compile time.

  • 0.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

DI Check Deps

Type utility to check whether we didn't forget any factories/resolvers when using Dependency Injection, especially when using automatic DI containers, that usually don't check for missing dependencies in compile time.

Example:

import { checkDependencies } from "di-check-deps";

const makeA = () => ({
  x: 234234,
});

type A = ReturnType<typeof makeA>;

type BDeps = {
  a: A;
};

// B is a service that 
// depends on `a`
const makeB =
  ({ a }: BDeps) =>
  () => ({
    y: "asdasdas",
  });

type B = ReturnType<typeof makeB>;

const dependenciesResolvers = {
  // Oops, we forgot `a`'s resolver!
  b: makeB
};

/**
 * TS Error!
 * Argument of type 
 * '{
 *    b: ({ a }: BDeps) => () => { y: string; }; 
 *  }' is not assignable to parameter of type 
 * '{ 
 *    a: 
 *      Resolver<{ x: number; }>; } & 
 *      { b: ({ a }: BDeps) => () => { y: string; }; 
 *  }'.
 * Property 'a' is missing in type 
 * '{ 
 *    b: ({ a }: BDeps) => () => { y: string; }; 
 *  }' but required in type 
 * '{ 
 *    a: Resolver<{ x: number; }>; 
 *  }'.ts(2345)
 */
checkDependencies(dependenciesResolvers);

// Some function that creates our container
// automatically from resolvers
createContainer(dependenciesResolvers);

Usage

This lib exports a single checkDependencies function that you can use to check whether you're missing some dependency.

import { checkDependencies } from "di-check-deps";

const dependenciesResolvers = {
  depA: makeDepA, //Factory Function
  depB: DepB, //Class
  someValue: 234234 //Value
};

checkDependencies(dependenciesResolvers);

checkDependencies does absolutely nothing in runtime (it returns undefined) and if you use a bundler/terser/minifier it's likely that it'll get stripped out from bundled code.

If you're missing some dependency, checkDependencies will raise a type error telling you which dependencies you are missing and what their types are.

Features

di-check-deps handles:

  • Factory function resolvers
  • Class resolvers
  • "Pure" value resolvers
  • Cyclic dependencies

Keywords

FAQs

Package last updated on 16 Aug 2022

Did you know?

Socket

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.

Install

Related posts

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