Skip to content

Commit 19996b6

Browse files
committed
Merge remote-tracking branch 'origin/master' into add_docs_page
# Conflicts: # package.json # yarn.lock
2 parents 823fb6e + e64485b commit 19996b6

32 files changed

+1753
-7103
lines changed

.eslintrc

Lines changed: 0 additions & 41 deletions
This file was deleted.

.eslintrc.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"root": true,
3+
"ignorePatterns": ["**/*"],
4+
"plugins": ["@nrwl/nx"],
5+
"overrides": [
6+
{
7+
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
8+
"parserOptions": {
9+
"project": "./tsconfig.*?.json"
10+
},
11+
"rules": {
12+
"@nrwl/nx/enforce-module-boundaries": [
13+
"error",
14+
{
15+
"enforceBuildableLibDependency": true,
16+
"allow": ["playground"],
17+
"depConstraints": [
18+
{
19+
"sourceTag": "*",
20+
"onlyDependOnLibsWithTags": ["*"]
21+
}
22+
]
23+
}
24+
]
25+
}
26+
},
27+
{
28+
"files": ["*.ts", "*.tsx"],
29+
"extends": ["plugin:@nrwl/nx/typescript"],
30+
"parserOptions": {
31+
"project": "./tsconfig.*?.json"
32+
},
33+
"rules": {}
34+
},
35+
{
36+
"files": ["*.js", "*.jsx"],
37+
"extends": ["plugin:@nrwl/nx/javascript"],
38+
"rules": {}
39+
}
40+
]
41+
}

.vscode/extensions.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"recommendations": [
3+
"nrwl.angular-console",
4+
"ms-vscode.vscode-typescript-tslint-plugin",
5+
"esbenp.prettier-vscode",
6+
"firsttris.vscode-jest-runner"
7+
]
8+
}

README.md

Lines changed: 15 additions & 217 deletions
Original file line numberDiff line numberDiff line change
@@ -1,225 +1,24 @@
1-
# NestJS Addons: In-Memory DB
2-
3-
[![npm version](https://badge.fury.io/js/%40nestjs-addons%2Fin-memory-db.svg)](https://badge.fury.io/js/%40nestjs-addons%2Fin-memory-db)
4-
[![npm downloads](https://img.shields.io/npm/dt/@nestjs-addons/in-memory-db?label=npm%20downloads)](https://www.npmjs.com/package/@nestjs-addons/in-memory-db)
5-
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
6-
[![CI Status](https://github.com/nestjs-addons/in-memory-db/workflows/master/badge.svg)](#)
7-
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
8-
[![All Contributors](https://img.shields.io/badge/all_contributors-6-orange.svg?style=flat-square)](#contributors)
9-
10-
## Breaking Changes
11-
12-
Please note that starting with V2.0.0, the InMemoryDB\* has been deprecated and moved to V1 instances. For more information on this API, checkout docs here: [V1 Docs](API_V1.md).
13-
14-
Detailed Changes:
15-
16-
- All V1 assets have been renamed to `InMemoryDBv1***`
17-
- New V2+ assets are the same name as before the V1 deprecation. You will just need to make modifications to support the `id` being a `string` as opposed to `number`
18-
- `id` has been changed from `number` to `string` to support GUIDs.
19-
- You can now _optionally_ provide a `getNextId` function that the service will use to generate new string IDs. By default, it will use the `uuid` npm package and `v4` implementation.
20-
21-
## Description
22-
23-
`@nestjs-addons/in-memory-db` provides a ridiculously simple, no configuration needed, way to create a simple in-memory database for use in your `nestjs` applications. You simply define an `interface` that extends the `interface InMemoryDBEntity`, inject the `InMemoryDBService<T>` into your controllers and/or services, and immediately profit. The records are stored in-memory, as a singleton, for each interface, for the life of the service.
24-
25-
This provides a great way to quickly get up and running with prototypes and mock backends.
26-
27-
## Table of Contents
28-
29-
- [Installation](#installation)
30-
- [Quick Start](#quick-start)
31-
- [Feature Modules](#feature-modules---registering-multiple-instances-using-forfeature)
32-
- [Entity Controller](#entity-controller)
33-
34-
## Installation
35-
36-
### Option 1
37-
38-
**With NPM**
39-
40-
```bash
41-
$ npm i --save @nestjs-addons/in-memory-db
42-
```
43-
44-
**With Yarn**
45-
46-
```bash
47-
$ yarn add @nestjs-addons/in-memory-db
48-
```
49-
50-
### Option 2
51-
52-
The library support nest add command, you can run the below command to install and import the libary to root module.
53-
54-
```bash
55-
nest add @nestjs-addons/in-memory-db
56-
```
57-
58-
## Video Walkthrough
59-
60-
[![](http://img.youtube.com/vi/eSx6nKDw5PQ/0.jpg)](http://www.youtube.com/watch?v=eSx6nKDw5PQ 'NestJS Addons - In Memory DB - Walkthrough')
61-
62-
## Quick Start
63-
64-
### Import into Module(s)
65-
66-
To get started, let's first update our `app.module.ts` to include the necessary pieces.
67-
68-
> While we are importing to the AppModule in this example, InMemoryDBModule could be imported in Feature modules just as well.
69-
70-
#### Registering a forRoot InMemoryDBModule
71-
72-
```typescript
73-
// app.module.ts
74-
75-
import { Module } from '@nestjs/common';
76-
import { InMemoryDBModule } from '@nestjs-addons/in-memory-db';
77-
...
78-
79-
@Module({
80-
...
81-
imports: [InMemoryDBModule.forRoot({})],
82-
...
83-
})
84-
export class AppModule {}
85-
```
86-
87-
As you can see we did the following:
88-
89-
- Import `InMemoryDBModule` from `@nestjs-addons/in-memory-db`
90-
- Add `InMemoryDBModule` to the `imports` array in the `@Module` of your choice
91-
92-
### Define an interface for each InMemoryEntity
93-
94-
An instance of `InMemoryDBService<T>` will be created for each `InMemoryDBEntity` entity `interface` defined. The `InMemoryDBEntity` adds an `id: string` property as the only required field. Additional fields can be defined by extending the `interface`.
95-
96-
To define a new `InMemoryDBEntity` extension create an `interface` similar to the following example:
97-
98-
```typescript
99-
interface UserEntity extends InMemoryDBEntity {
100-
firstName: string;
101-
lastName: string;
102-
emailAddress: string;
103-
admin: boolean;
104-
}
105-
```
106-
107-
Now we can make use of our new `interface` when injecting the `InMemoryDBService<T>` into our controllers or other services.
108-
109-
### Inject into Controller(s) and/or Services(s)
110-
111-
In order to use the `InMemoryDBService<T>` we need to do the following:
112-
113-
- Add `private readonly inMemoryDB: InMemoryDBService<T>` to the `constructor` of each controller and/or service that you would like to use it in.
114-
- Begin using `InMemoryDBService` as expected.
115-
116-
An example of injecting `InMemoryDBService` into a `UserController` for the `UserEntity` we defined earlier would look something like this:
117-
118-
```typescript
119-
@Controller()
120-
export class UserController {
121-
constructor(private readonly userService: InMemoryDBService<UserEntity>) {}
122-
123-
@Get('users/:id')
124-
getUser(@Param() id: string): UserEntity {
125-
return this.userService.get(id);
126-
}
127-
128-
@Post('users')
129-
createUser(@Body() user: UserEntity): UserEntity {
130-
return this.userService.create(user);
131-
}
132-
}
133-
```
134-
135-
## Feature Modules - Registering Multiple Instances using `forFeature`
136-
137-
Registering multiple instances for specific feature modules is super simple. Each feature module is guaranteed isolated to that feature. In order to get up and running you need to do the following:
138-
139-
#### Registering a forFeature InMemoryDBService
140-
141-
For each feature module(s), do the following:
142-
143-
```typescript
144-
// feature-one.module.ts
145-
146-
import { Module } from '@nestjs/common';
147-
import { InMemoryDBModule } from '@nestjs-addons/in-memory-db';
148-
...
149-
150-
@Module({
151-
...
152-
imports: [InMemoryDBModule.forFeature('one', {})],
153-
...
154-
})
155-
export class FeatureOneModule {}
156-
```
157-
158-
As you can see we:
159-
160-
- Imported `InMemoryDBModule` from `@nestjs-addons/in-memory-db`
161-
- Added `InMemoryDBModule` to the `imports` array in the `@Module` of your choice
162-
- Added the `forFeature` method call passing `one` as the feature name
163-
164-
#### Using the Feature Instance
165-
166-
If you would like to use the feature-specific instance, make use of the included `@InjectInMemoryDBService` decorator:
167-
168-
```typescript
169-
@Controller({...})
170-
export class FeatureOneController {
171-
constructor(@InjectInMemoryDBService('one') private oneService: InMemoryDBService<OneEntity>) {}
172-
...
173-
@Get()
174-
getAll(): OneEntity[] {
175-
return this.oneService.getAll();
176-
}
177-
}
178-
```
179-
180-
Using this decorator ensures that the correct instance is injected.
181-
182-
## Entity Controller
183-
184-
In order to prevent code duplication and boilerplate for each controller, we have created two base entity controllers `InMemoryDBEntityController` and `InMemoryDBEntityAsyncController`. This allows you to quickly provide endpoints to make requests without having to manually implement each action.
185-
186-
To use the controllers, simply create a new controller and extend it with one of the provided base controllers.
187-
188-
```typescript
189-
@Controller('api/users')
190-
class UsersController extends InMemoryDBEntityController<UserEntity> {
191-
constructor(protected dbService: InMemoryDBService<UserEntity>) {
192-
super(dbService);
193-
}
194-
}
195-
```
196-
197-
In order to have an Entity Controller use a feature-specific instance of the service, use the decorator `InjectInMemoryDBService` in the controller's provided by this library as shown below:
198-
199-
```typescript
200-
@Controller('api/users')
201-
class UsersController extends InMemoryDBEntityController<UserEntity> {
202-
constructor(
203-
@InjectInMemoryDBService('customer')
204-
protected readonly inMemoryDBService: InMemoryDBService<UserEntity>,
205-
) {
206-
super(inMemoryDBService);
207-
}
208-
}
209-
```
210-
211-
## Docs
212-
213-
[Click here for more detailed API Documentation](API.md)
214-
215-
[DEPRECATED V1 API - Click here for more detailed API Documentation](API_V1.md)
2161

2172
## Stay in touch
2183

2194
- Author - [Wes Grimes](https://wesleygrimes.com)
220-
- Website - [https://github.com/nestjs-addons/in-memory-db](https://github.com/nestjs-addons/in-memory-db/)
5+
- Website - [https://github.com/nestjs-addons/platform](https://github.com/nestjs-addons/platform/)
2216
- Twitter - [@wesgrimes](https://twitter.com/wesgrimes)
2227

8+
## Maintainers ✨
9+
10+
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
11+
<!-- prettier-ignore -->
12+
<table>
13+
<tr>
14+
<td align="center"><a href="https://wesleygrimes.com"><img src="https://avatars0.githubusercontent.com/u/324308?v=4" width="100px;" alt="Wes Grimes"/><br /><sub><b>Wes Grimes</b></sub></a><br /><a href="#infra-wesleygrimes" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="https://github.com/nestjs-addons/in-memory-db/commits?author=wesleygrimes" title="Tests">⚠️</a> <a href="https://github.com/nestjs-addons/in-memory-db/commits?author=wesleygrimes" title="Code">💻</a></td>
15+
<td align="center"><a href="https://github.com/yharaskrik"><img src="https://avatars.githubusercontent.com/u/9469090?s=460&u=cdb912283b06f43b36da0137e61d66a48f9f7e85&v=4" width="100px;" alt="Jay Bell"/><br /><sub><b>Jay Bell</b></sub></a><br /><a href="https://github.com/nestjs-addons/in-memory-db/commits?author=yharaskrik" title="Tests">⚠️</a> <a href="https://github.com/nestjs-addons/in-memory-db/commits?author=yharaskrik" title="Code">💻</a></td>
16+
<td align="center"><a href="https://github.com/DominikPieper"><img src="https://avatars.githubusercontent.com/u/77470?s=400&u=dcb757adc603e0d4caebb02182be9674299e0de0&v=4" width="100px;" alt="Dominik Pieper"/><br /><sub><b>Dominik Pieper</b></sub></a><br /><a href="https://github.com/nestjs-addons/in-memory-db/commits?author=DominikPieper" title="Tests">⚠️</a> <a href="https://github.com/nestjs-addons/in-memory-db/commits?author=yharaskrik" title="Code">💻</a></td>
17+
</tr>
18+
</table>
19+
20+
<!-- ALL-CONTRIBUTORS-LIST:END -->
21+
22322
## Contributors ✨
22423

22524
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
@@ -228,7 +27,6 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
22827
<!-- prettier-ignore -->
22928
<table>
23029
<tr>
231-
<td align="center"><a href="https://wesleygrimes.com"><img src="https://avatars0.githubusercontent.com/u/324308?v=4" width="100px;" alt="Wes Grimes"/><br /><sub><b>Wes Grimes</b></sub></a><br /><a href="#infra-wesleygrimes" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="https://github.com/nestjs-addons/in-memory-db/commits?author=wesleygrimes" title="Tests">⚠️</a> <a href="https://github.com/nestjs-addons/in-memory-db/commits?author=wesleygrimes" title="Code">💻</a></td>
23230
<td align="center"><a href="https://github.com/cmwhited"><img src="https://avatars0.githubusercontent.com/u/18075124?v=4" width="100px;" alt="Chris Whited"/><br /><sub><b>Chris Whited</b></sub></a><br /><a href="#infra-cmwhited" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="https://github.com/nestjs-addons/in-memory-db/commits?author=cmwhited" title="Tests">⚠️</a> <a href="https://github.com/nestjs-addons/in-memory-db/commits?author=cmwhited" title="Code">💻</a></td>
23331
<td align="center"><a href="https://github.com/wescopeland"><img src="https://avatars0.githubusercontent.com/u/3984985?v=4" width="100px;" alt="Wes Copeland"/><br /><sub><b>Wes Copeland</b></sub></a><br /><a href="https://github.com/nestjs-addons/in-memory-db/commits?author=wescopeland" title="Code">💻</a> <a href="https://github.com/nestjs-addons/in-memory-db/commits?author=wescopeland" title="Tests">⚠️</a></td>
23432
<td align="center"><a href="http://hirejordanpowell.com"><img src="https://avatars0.githubusercontent.com/u/3605268?v=4" width="100px;" alt="Jordan"/><br /><sub><b>Jordan</b></sub></a><br /><a href="https://github.com/nestjs-addons/in-memory-db/commits?author=jordanpowell88" title="Code">💻</a> <a href="https://github.com/nestjs-addons/in-memory-db/commits?author=jordanpowell88" title="Tests">⚠️</a></td>

jest.config.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
module.exports = {
2-
testMatch: ['**/+(*.)+(spec|test).+(ts|js)?(x)'],
3-
transform: {
4-
'^.+\\.(ts|js|html)$': 'ts-jest',
5-
},
6-
resolver: '@nrwl/jest/plugins/resolver',
7-
moduleFileExtensions: ['ts', 'js', 'html'],
8-
coverageReporters: ['html'],
2+
projects: [
3+
'<rootDir>/packages/playground',
4+
'<rootDir>/packages/in-memory-db',
5+
'<rootDir>/packages/playground-e2e',
6+
'<rootDir>/packages/spectator',
7+
],
98
};

jest.preset.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const nxPreset = require('@nrwl/jest/preset');
2+
module.exports = {
3+
...nxPreset,
4+
testMatch: ['**/+(*.)+(spec|test).+(ts|js)?(x)'],
5+
transform: {
6+
'^.+\\.(ts|js|html)$': 'ts-jest',
7+
},
8+
resolver: '@nrwl/jest/plugins/resolver',
9+
moduleFileExtensions: ['ts', 'js', 'html'],
10+
coverageReporters: ['html'],
11+
};

0 commit comments

Comments
 (0)