-
Notifications
You must be signed in to change notification settings - Fork 10.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(core): Replace typedi with our custom DI system (no-changelo…
…g) (#12389) Co-authored-by: Iván Ovejero <ivov.src@gmail.com>
- Loading branch information
Showing
413 changed files
with
978 additions
and
451 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const sharedOptions = require('@n8n_io/eslint-config/shared'); | ||
|
||
/** @type {import('@types/eslint').ESLint.ConfigData} */ | ||
module.exports = { | ||
extends: ['@n8n_io/eslint-config/base'], | ||
...sharedOptions(__dirname), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
## @n8n/di | ||
|
||
`@n8n/di` is a dependency injection (DI) container library, based on [`typedi`](https://github.com/typestack/typedi). | ||
|
||
n8n no longer uses `typedi` because: | ||
|
||
- `typedi` is no longer officially maintained | ||
- Need for future-proofing, e.g. stage-3 decorators | ||
- Small enough that it is worth the maintenance burden | ||
- Easier to customize, e.g. to simplify unit tests | ||
|
||
### Usage | ||
|
||
```typescript | ||
// from https://github.com/typestack/typedi/blob/develop/README.md | ||
import { Container, Service } from 'typedi'; | ||
|
||
@Service() | ||
class ExampleInjectedService { | ||
printMessage() { | ||
console.log('I am alive!'); | ||
} | ||
} | ||
|
||
@Service() | ||
class ExampleService { | ||
constructor( | ||
// because we annotated ExampleInjectedService with the @Service() | ||
// decorator TypeDI will automatically inject an instance of | ||
// ExampleInjectedService here when the ExampleService class is requested | ||
// from TypeDI. | ||
public injectedService: ExampleInjectedService | ||
) {} | ||
} | ||
|
||
const serviceInstance = Container.get(ExampleService); | ||
// we request an instance of ExampleService from TypeDI | ||
|
||
serviceInstance.injectedService.printMessage(); | ||
// logs "I am alive!" to the console | ||
``` | ||
|
||
Requires enabling these flags in `tsconfig.json`: | ||
|
||
```json | ||
{ | ||
"compilerOptions": { | ||
"experimentalDecorators": true, | ||
"emitDecoratorMetadata": true | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/** @type {import('jest').Config} */ | ||
module.exports = require('../../../jest.config'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"name": "@n8n/di", | ||
"version": "0.1.0", | ||
"scripts": { | ||
"clean": "rimraf dist .turbo", | ||
"dev": "pnpm watch", | ||
"typecheck": "tsc --noEmit", | ||
"build": "tsc -p tsconfig.build.json", | ||
"format": "biome format --write .", | ||
"format:check": "biome ci .", | ||
"lint": "eslint .", | ||
"lintfix": "eslint . --fix", | ||
"watch": "tsc -p tsconfig.build.json --watch", | ||
"test": "jest", | ||
"test:dev": "jest --watch" | ||
}, | ||
"main": "dist/di.js", | ||
"module": "src/di.ts", | ||
"types": "dist/di.d.ts", | ||
"files": [ | ||
"dist/**/*" | ||
], | ||
"dependencies": { | ||
"reflect-metadata": "catalog:" | ||
} | ||
} |
Oops, something went wrong.