Skip to content

Commit

Permalink
feat(sequelize): add sequelize plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
nartc committed Mar 6, 2021
1 parent 99d124e commit b9105bb
Show file tree
Hide file tree
Showing 17 changed files with 382 additions and 11 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"onlyDependOnLibsWithTags": [
"type:library",
"type:type-defs",
"type:util"
"type:util",
"type:plugin"
]
},
{
Expand Down
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ This is a monorepo of `@automapper/core` and official packages.

## Packages

| Project | Package | Version | Links |
| ----------- | ---------------------------------------------------------------------- | ----------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **core** | [`@automapper/core`](https://npmjs.com/package/@automapper/core) | ![npm (scoped)](https://img.shields.io/npm/v/@automapper/core) | [![README](https://img.shields.io/badge/README--green.svg)](/packages/core/README.md) ![npm bundle size (scoped)](https://img.shields.io/bundlephobia/minzip/@automapper/core) ![NPM](https://img.shields.io/npm/l/@automapper/core) |
| **classes** | [`@automapper/classes`](https://npmjs.com/package/@automapper/classes) | ![npm (scoped)](https://img.shields.io/npm/v/@automapper/classes) | [![README](https://img.shields.io/badge/README--green.svg)](/packages/classes/README.md) ![npm bundle size (scoped)](https://img.shields.io/bundlephobia/minzip/@automapper/classes) ![NPM](https://img.shields.io/npm/l/@automapper/classes) |
| **pojos** | [`@automapper/pojos`](https://npmjs.com/package/@automapper/pojos) | ![npm (scoped)](https://img.shields.io/npm/v/@automapper/pojos) | [![README](https://img.shields.io/badge/README--green.svg)](/packages/pojos/README.md) ![npm bundle size (scoped)](https://img.shields.io/bundlephobia/minzip/@automapper/pojos) ![NPM](https://img.shields.io/npm/l/@automapper/pojos) |
| **nestjs** | [`@automapper/nestjs`](https://npmjs.com/package/@automapper/nestjs) | ![npm (scoped)](https://img.shields.io/npm/v/@automapper/nestjs) | [![README](https://img.shields.io/badge/README--green.svg)](/packages/nestjs/README.md) ![npm bundle size (scoped)](https://img.shields.io/bundlephobia/minzip/@automapper/nestjs) ![NPM](https://img.shields.io/npm/l/@automapper/nestjs) |
| **types** | [`@automapper/types`](https://npmjs.com/package/@automapper/types) | ![npm (scoped)](https://img.shields.io/npm/v/@automapper/types) | [![README](https://img.shields.io/badge/README--green.svg)](/packages/types/README.md) ![npm bundle size (scoped)](https://img.shields.io/bundlephobia/minzip/@automapper/types) ![NPM](https://img.shields.io/npm/l/@automapper/types) |
| Project | Package | Version | Links |
| ------------- | -------------------------------------------------------------------------- | ------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **core** | [`@automapper/core`](https://npmjs.com/package/@automapper/core) | ![npm (scoped)](https://img.shields.io/npm/v/@automapper/core) | [![README](https://img.shields.io/badge/README--green.svg)](/packages/core/README.md) ![npm bundle size (scoped)](https://img.shields.io/bundlephobia/minzip/@automapper/core) ![NPM](https://img.shields.io/npm/l/@automapper/core) |
| **classes** | [`@automapper/classes`](https://npmjs.com/package/@automapper/classes) | ![npm (scoped)](https://img.shields.io/npm/v/@automapper/classes) | [![README](https://img.shields.io/badge/README--green.svg)](/packages/classes/README.md) ![npm bundle size (scoped)](https://img.shields.io/bundlephobia/minzip/@automapper/classes) ![NPM](https://img.shields.io/npm/l/@automapper/classes) |
| **pojos** | [`@automapper/pojos`](https://npmjs.com/package/@automapper/pojos) | ![npm (scoped)](https://img.shields.io/npm/v/@automapper/pojos) | [![README](https://img.shields.io/badge/README--green.svg)](/packages/pojos/README.md) ![npm bundle size (scoped)](https://img.shields.io/bundlephobia/minzip/@automapper/pojos) ![NPM](https://img.shields.io/npm/l/@automapper/pojos) |
| **sequelize** | [`@automapper/sequelize`](https://npmjs.com/package/@automapper/sequelize) | ![npm (scoped)](https://img.shields.io/npm/v/@automapper/sequelize) | [![README](https://img.shields.io/badge/README--green.svg)](/packages/sequelize/README.md) ![npm bundle size (scoped)](https://img.shields.io/bundlephobia/minzip/@automapper/sequelize) ![NPM](https://img.shields.io/npm/l/@automapper/sequelize) |
| **nestjs** | [`@automapper/nestjs`](https://npmjs.com/package/@automapper/nestjs) | ![npm (scoped)](https://img.shields.io/npm/v/@automapper/nestjs) | [![README](https://img.shields.io/badge/README--green.svg)](/packages/nestjs/README.md) ![npm bundle size (scoped)](https://img.shields.io/bundlephobia/minzip/@automapper/nestjs) ![NPM](https://img.shields.io/npm/l/@automapper/nestjs) |
| **types** | [`@automapper/types`](https://npmjs.com/package/@automapper/types) | ![npm (scoped)](https://img.shields.io/npm/v/@automapper/types) | [![README](https://img.shields.io/badge/README--green.svg)](/packages/types/README.md) ![npm bundle size (scoped)](https://img.shields.io/bundlephobia/minzip/@automapper/types) ![NPM](https://img.shields.io/npm/l/@automapper/types) |

### Experimental

Expand Down
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ module.exports = {
'<rootDir>/packages/nestjs',
'<rootDir>/packages/nestjs-integration-test',
'<rootDir>/packages/experimental/transformer-plugin',
'<rootDir>/packages/sequelize',
],
};
3 changes: 3 additions & 0 deletions nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
},
"classes-experimental-transformer-plugin": {
"tags": ["type:transformer-plugin"]
},
"sequelize": {
"tags": ["type:plugin"]
}
},
"workspaceLayout": {
Expand Down
141 changes: 140 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"@types/jest": "26.0.20",
"@types/jest-when": "2.7.2",
"@types/node": "14.14.28",
"@types/sequelize": "4.28.9",
"@types/supertest": "2.0.10",
"@typescript-eslint/eslint-plugin": "4.15.1",
"@typescript-eslint/parser": "4.15.1",
Expand All @@ -93,6 +94,7 @@
"reflect-metadata": "0.1.13",
"release-it": "14.4.0",
"rxjs": "~6.6.3",
"sequelize": "6.5.0",
"supertest": "6.1.3",
"ts-jest": "26.5.1",
"ts-node": "9.1.1",
Expand Down
9 changes: 9 additions & 0 deletions packages/sequelize/.eslintrc.json
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
}
}
52 changes: 52 additions & 0 deletions packages/sequelize/README.md
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)
14 changes: 14 additions & 0 deletions packages/sequelize/jest.config.js
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',
};
Loading

0 comments on commit b9105bb

Please sign in to comment.