# di-check-deps

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

Latest version **0.0.2** (published 2022-08-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install di-check-deps
pnpm add di-check-deps
yarn add di-check-deps
bun add di-check-deps
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2022-08-16 |
| First published | 2022-08-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Henrique Yuji Rossetti Inonhe |
| Maintainers | henriqueinonhe |
| Keywords | di, dependency injection, awilix, inversion of control, dependency inversion |

## Links

- npm: https://www.npmjs.com/package/di-check-deps
- Repository: https://github.com/henriqueinonhe/di-check-deps
- Homepage: https://github.com/henriqueinonhe/di-check-deps#readme
- Issues: https://github.com/henriqueinonhe/di-check-deps.git
- npm.io page: https://npm.io/package/di-check-deps

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 0.0.2 (latest) — 2022-08-16
- 0.0.1 — 2022-08-16

## README

# 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:

```ts
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.

```ts
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

---
_Source: https://npm.io/package/di-check-deps · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
