forked from nartc/mapper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sequelize): add sequelize plugin
- Loading branch information
Showing
17 changed files
with
382 additions
and
11 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"extends": ["../../.eslintrc.json"], | ||
"ignorePatterns": ["!**/*"], | ||
"rules": { | ||
"@typescript-eslint/no-non-null-assertion": 0, | ||
"no-prototype-builtins": 0, | ||
"@typescript-eslint/no-explicit-any": 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,52 @@ | ||
# @automapper/sequelize | ||
|
||
This is the official plugin from `@automapper` to work with `Sequelize` enabled projects | ||
|
||
## Installation | ||
|
||
```sh | ||
npm i @automapper/sequelize | ||
``` | ||
|
||
or with `yarn`: | ||
|
||
```sh | ||
yarn add @automapper/sequelize | ||
``` | ||
|
||
#### `peerDependencies` | ||
|
||
`@automapper/sequelize` depends on `sequelize`, `@automapper/classes`, and all of `@automapper/classes` `peerDependencies` | ||
|
||
```sh | ||
npm i sequelize @automapper/{core,classes} reflect-metadata | ||
npm i --save-dev @types/sequelize @automapper/types | ||
``` | ||
|
||
or with `yarn`: | ||
|
||
```sh | ||
yarn add sequelize @automapper/{core,classes} reflect-metadata | ||
yarn add --dev @types/sequelize @automapper/types | ||
``` | ||
|
||
## Usage | ||
|
||
- `@automapper/sequelize` provides `sequelize` as a `(valueGetter) => MapPluginInitializer`. Pass `sequelize()` to `createMapper` to create | ||
a `Mapper` that uses `sequelize` plugin. | ||
|
||
- `valueGetter` is an optional getter that, if passed in, will be used to extract the value of the model after instantiation. By default, it will use `sequelize#Model.get()` if it's available. | ||
|
||
```ts | ||
import { classes } from '@automapper/classes'; | ||
|
||
const mapper = createMapper({ | ||
..., | ||
pluginInitializer: sequelize() // or sequelize(model => model.get(getterOptions)) | ||
}) | ||
|
||
mapper.createMap(User, UserVm); | ||
mapper.map(user, UserVm, User); | ||
``` | ||
|
||
Read more about this plugin on [sequelize documentation](https://automapperts.netlify.app/docs/plugins-system/introduce-to-sequelize) |
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,14 @@ | ||
module.exports = { | ||
displayName: 'sequelize', | ||
preset: '../../jest.preset.js', | ||
globals: { | ||
'ts-jest': { | ||
tsConfig: '<rootDir>/tsconfig.spec.json', | ||
}, | ||
}, | ||
transform: { | ||
'^.+\\.[tj]sx?$': 'ts-jest', | ||
}, | ||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'], | ||
coverageDirectory: '../../coverage/packages/sequelize', | ||
}; |
Oops, something went wrong.