-
-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nestjs): add nestjs integration package
- Loading branch information
Showing
28 changed files
with
297 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,9 @@ | |
}, | ||
"pojos": { | ||
"tags": [] | ||
}, | ||
"nestjs": { | ||
"tags": [] | ||
} | ||
}, | ||
"workspaceLayout": { | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 @@ | ||
{ "extends": "../../.eslintrc.json", "ignorePatterns": ["!**/*"], "rules": {} } |
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 @@ | ||
# nestjs | ||
|
||
This library was generated with [Nx](https://nx.dev). | ||
|
||
## Running unit tests | ||
|
||
Run `nx test nestjs` to execute the unit tests via [Jest](https://jestjs.io). |
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,15 @@ | ||
module.exports = { | ||
displayName: 'nestjs', | ||
preset: '../../jest.preset.js', | ||
globals: { | ||
'ts-jest': { | ||
tsConfig: '<rootDir>/tsconfig.spec.json', | ||
}, | ||
}, | ||
testEnvironment: 'node', | ||
transform: { | ||
'^.+\\.[tj]sx?$': 'ts-jest', | ||
}, | ||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'], | ||
coverageDirectory: '../../coverage/packages/nestjs', | ||
}; |
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,8 @@ | ||
{ | ||
"name": "@automapper/nestjs", | ||
"version": "0.0.1", | ||
"peerDependencies": { | ||
"@nestjs/common": "^7.0.0", | ||
"@nestjs/core": "^7.0.0" | ||
} | ||
} |
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,4 @@ | ||
export * from './lib/automapper.module'; | ||
export * from './lib/interfaces'; | ||
export * from './lib/di'; | ||
export * from './lib/abstracts'; |
12 changes: 12 additions & 0 deletions
12
packages/nestjs/src/lib/abstracts/automapper-profile.abstract.ts
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,12 @@ | ||
import type { Mapper, MappingProfile } from '@automapper/types'; | ||
|
||
export abstract class AutomapperProfile { | ||
protected mapper: Mapper; | ||
|
||
protected constructor(mapper: Mapper) { | ||
this.mapper = mapper; | ||
this.mapper.addProfile(this.mapProfile()); | ||
} | ||
|
||
abstract mapProfile(): MappingProfile; | ||
} |
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 @@ | ||
export * from './automapper-profile.abstract'; |
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,19 @@ | ||
import { DynamicModule, Global, Logger, Module } from '@nestjs/common'; | ||
import type { AutomapperModuleOptions } from './interfaces'; | ||
import { createAutomapperProviders } from './utils'; | ||
|
||
@Global() | ||
@Module({}) | ||
export class AutomapperModule { | ||
private static readonly logger = new Logger(AutomapperModule.name); | ||
|
||
static forRoot(forRootOptions: AutomapperModuleOptions): DynamicModule { | ||
const providers = createAutomapperProviders(forRootOptions, this.logger); | ||
|
||
return { | ||
module: AutomapperModule, | ||
providers, | ||
exports: providers, | ||
}; | ||
} | ||
} |
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,5 @@ | ||
export const DEFAULT_MAPPER_TOKEN = 'automapper:nestjs:default'; | ||
|
||
export function getMapperToken(name?: string) { | ||
return name ? `automapper:nestjs:${name}` : DEFAULT_MAPPER_TOKEN; | ||
} |
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 @@ | ||
export * from './get-mapper-token'; |
15 changes: 15 additions & 0 deletions
15
packages/nestjs/src/lib/interfaces/automapper-module-options.interface.ts
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,15 @@ | ||
import type { | ||
CreateMapperOptions, | ||
ErrorHandler, | ||
NamingConvention, | ||
} from '@automapper/types'; | ||
|
||
export interface AutomapperModuleOptions { | ||
options: CreateMapperOptions[]; | ||
globalErrorHandler?: ErrorHandler; | ||
globalNamingConventions?: { | ||
source: NamingConvention; | ||
destination: NamingConvention; | ||
}; | ||
singular?: boolean; | ||
} |
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 @@ | ||
export * from './automapper-module-options.interface'; |
60 changes: 60 additions & 0 deletions
60
packages/nestjs/src/lib/utils/create-automapper-providers.util.ts
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,60 @@ | ||
import { createMapper } from '@automapper/core'; | ||
import type { Provider } from '@nestjs/common'; | ||
import { Logger } from '@nestjs/common'; | ||
import { getMapperToken } from '../di'; | ||
import type { AutomapperModuleOptions } from '../interfaces'; | ||
|
||
export function createAutomapperProviders( | ||
forRootOptions: AutomapperModuleOptions, | ||
logger: Logger | ||
): Provider[] { | ||
const { | ||
options, | ||
globalErrorHandler, | ||
globalNamingConventions, | ||
singular = false, | ||
} = forRootOptions; | ||
|
||
if (singular) { | ||
if (options.length > 1) { | ||
const error = | ||
'singular cannot be set to true when you have more than one plugin'; | ||
logger.error(error); | ||
throw new Error(error); | ||
} | ||
|
||
const [ | ||
{ name, namingConventions, errorHandler, pluginInitializer }, | ||
] = options; | ||
const mapper = createMapper({ | ||
name, | ||
pluginInitializer, | ||
errorHandler: errorHandler || | ||
globalErrorHandler || { handle: logger.error }, | ||
namingConventions: namingConventions || globalNamingConventions, | ||
}); | ||
|
||
return [ | ||
{ | ||
provide: getMapperToken(), | ||
useValue: mapper, | ||
}, | ||
]; | ||
} | ||
|
||
return options.map( | ||
({ name, errorHandler, namingConventions, pluginInitializer }) => { | ||
const mapper = createMapper({ | ||
name, | ||
pluginInitializer, | ||
errorHandler: errorHandler || | ||
globalErrorHandler || { handle: logger.error }, | ||
namingConventions: namingConventions || globalNamingConventions, | ||
}); | ||
return { | ||
provide: getMapperToken(mapper.name), | ||
useValue: mapper, | ||
}; | ||
} | ||
); | ||
} |
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 @@ | ||
export * from './create-automapper-providers.util' |
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,13 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"files": [], | ||
"include": [], | ||
"references": [ | ||
{ | ||
"path": "./tsconfig.lib.json" | ||
}, | ||
{ | ||
"path": "./tsconfig.spec.json" | ||
} | ||
] | ||
} |
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,12 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"outDir": "../../dist/out-tsc", | ||
"declaration": true, | ||
"types": ["node"], | ||
"target": "es6" | ||
}, | ||
"exclude": ["**/*.spec.ts"], | ||
"include": ["**/*.ts"] | ||
} |
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,15 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "../../dist/out-tsc", | ||
"module": "commonjs", | ||
"types": ["jest", "node"] | ||
}, | ||
"include": [ | ||
"**/*.spec.ts", | ||
"**/*.spec.tsx", | ||
"**/*.spec.js", | ||
"**/*.spec.jsx", | ||
"**/*.d.ts" | ||
] | ||
} |
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
Oops, something went wrong.