onion-transformer
TypeScript icon, indicating that this package has built-in type declarations

0.2.5 • Public • Published

onion-transformer

onion-transformer is a TypeScript transformer designed to simplify Dependency Injection (DI) in the Onion architecture. It automatically transforms TypeScript code to make dependency injections simpler and less error-prone.

Features

  • Automatic DI Metadata Addition: Simplifies dependency injection by automatically adding necessary metadata.
  • Type safe DI: Types check on compile type
  • Decorator Support: Recognizes and processes decorators used for dependency injections.
  • Compatibility: Designed to work seamlessly with the Onion DI package, ensuring smooth integration.

Installation

Install onion-transformer using npm or yarn:

npm install onion-transformer --save-dev

# or

yarn add onion-transformer --dev
npx ts-patch install

This step modifies the TypeScript compiler to support custom transformers.

Usage

To use onion-transformer in your project, add it to your TypeScript configuration (usually tsconfig.json) under compilerOptions.plugins:

{
  "compilerOptions": {
    "plugins": [
      {
        "transform": "onion-transformer"
      }
    ]
  }
}

Examples

Before Transformation

@Service()
class MyService {
  constructor(@Inject() private myOtherService: MyOtherService) {}
}

After Transformation

@Service({ name: "MyService" })
class MyService {
  constructor(@Inject({ name: "MyOtherService" }) private myOtherService: MyOtherService) {}
}

Development

For local development and testing:

Package Sidebar

Install

npm i onion-transformer

Weekly Downloads

8

Version

0.2.5

License

MIT

Unpacked Size

44 kB

Total Files

43

Last publish

Collaborators

  • isqanderm