Skip to content

Commit

Permalink
Feature/repository (#1)
Browse files Browse the repository at this point in the history
* refactor: splited logic beеween couchdb and nest contexts

* feat(repository): updated repositiry factory

* test(couchdb): added repository factory coverage

* refactor: changed ts asserts to generics

* test(module): added inject decorators coverage

* refactor(couchdb): added repository mixin and Repository interface

* test(couchdb): added repository methods coverage

* docs: added README
  • Loading branch information
michaelyali authored and Zach Gray committed Jul 18, 2019
1 parent f39499c commit 2c4c95d
Show file tree
Hide file tree
Showing 50 changed files with 5,897 additions and 82 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,7 @@ typings/
.next

# Build
dist/
dist/*
!dist/package.json
!dist/README.md
!dist/LICENSE
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
(The MIT License)

Copyright (c) 2019 Scal.io, LLC

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
116 changes: 114 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,114 @@
# nest-couchdb
CouchDB module for Nest framework
## Description

The [CouchDB](http://couchdb.apache.org/) module for Nest framework

## Installation

```bash
$ npm i @scalio/nest-couchdb nano
```

## Usage

`@scalio/nest-couchdb` uses [nano](https://www.npmjs.com/package/nano) as a data provider for CouchDB and the `Repository` pattern to handle all documents related operations.

First, let's create an `Entity`:

```typescript
import { Entity, CouchDbEntity } from '@scalio/nest-couchdb';

@Entity('cats')
export class Cat extends CouchDbEntity {
name: string;
}
```

Where `cats` is the CouchDB database name.

The `CouchDbEntity` is a base class which has some common properties:

```typescript
class CouchDbEntity {
_id: string;
_rev: string;
}
```

Then, we need to import `CouchDbModule` in our `ApplicationModule`:

```typescript
import { Module } from '@nestjs/common';
import { CouchDbModule } from '@scalio/nest-couchdb';

@Module({
imports: [
CouchDbModule.forRoot({
url: 'http://localhost:5984',
username: 'couchdb',
userpass: 'password',
requestDefaults: { jar: true },
}),
],
})
export class ApplicationModule {}
```

In our `CatsModule` we need to initiate repository for our `Cat` entity:

```typescript
import { Module } from '@nestjs/common';
import { CouchDbModule } from '@scalio/nest-couchdb';
import { CatsService } from './cats.service';
import { CatsController } from './cats.controller';
import { Cat } from './cat.entity';

@Module({
imports: [CouchDbModule.forFeature([Cat])],
providers: [CatsService],
controllers: [CatsController],
})
export class CatsModule {}
```

And here is the usage of the repository in the service:

```typescript
import { DocumentListResponse } from 'nano';
import { Injectable } from '@nestjs/common';
import { InjectRepository, Repository } from '@scalio/nest-couchdb';
import { Cat } from './cat.entity';

@Injectable()
export class CatsService {
constructor(
@InjectRepository(Cat)
private readonly catsRepository: Repository<Cat>,
) {}

findAll(): Promise<DocumentListResponse<Cat> {
return this.catsRepository.list();
}
}
```
## Test
```bash
$ docker-compose up -d
$ npm test
```
## License
[MIT](LICENSE)
## Credits
Created by [@zMotivat0r](https://github.com/zMotivat0r) @ [Scalio](https://scal.io/)
<p align="center">
<br/>
<a href="https://scal.io/">
<img src="https://raw.githubusercontent.com/scalio/bazel-nestjs-starter/master/readme-assets/scalio.png"/>
</a>
</p>
22 changes: 22 additions & 0 deletions dist/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
(The MIT License)

Copyright (c) 2019 Scal.io, LLC

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
114 changes: 114 additions & 0 deletions dist/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
## Description

The [CouchDB](http://couchdb.apache.org/) module for Nest framework

## Installation

```bash
$ npm i @scalio/nest-couchdb nano
```

## Usage

`@scalio/nest-couchdb` uses [nano](https://www.npmjs.com/package/nano) as a data provider for CouchDB and the `Repository` pattern to handle all documents related operations.

First, let's create an `Entity`:

```typescript
import { Entity, CouchDbEntity } from '@scalio/nest-couchdb';

@Entity('cats')
export class Cat extends CouchDbEntity {
name: string;
}
```

Where `cats` is the CouchDB database name.

The `CouchDbEntity` is a base class which has some common properties:

```typescript
class CouchDbEntity {
_id: string;
_rev: string;
}
```

Then, we need to import `CouchDbModule` in our `ApplicationModule`:

```typescript
import { Module } from '@nestjs/common';
import { CouchDbModule } from '@scalio/nest-couchdb';

@Module({
imports: [
CouchDbModule.forRoot({
url: 'http://localhost:5984',
username: 'couchdb',
userpass: 'password',
requestDefaults: { jar: true },
}),
],
})
export class ApplicationModule {}
```

In our `CatsModule` we need to initiate repository for our `Cat` entity:

```typescript
import { Module } from '@nestjs/common';
import { CouchDbModule } from '@scalio/nest-couchdb';
import { CatsService } from './cats.service';
import { CatsController } from './cats.controller';
import { Cat } from './cat.entity';

@Module({
imports: [CouchDbModule.forFeature([Cat])],
providers: [CatsService],
controllers: [CatsController],
})
export class CatsModule {}
```

And here is the usage of the repository in the service:

```typescript
import { DocumentListResponse } from 'nano';
import { Injectable } from '@nestjs/common';
import { InjectRepository, Repository } from '@scalio/nest-couchdb';
import { Cat } from './cat.entity';

@Injectable()
export class CatsService {
constructor(
@InjectRepository(Cat)
private readonly catsRepository: Repository<Cat>,
) {}

findAll(): Promise<DocumentListResponse<Cat> {
return this.catsRepository.list();
}
}
```
## Test
```bash
$ docker-compose up -d
$ npm test
```
## License
[MIT](LICENSE)
## Credits
Created by [@zMotivat0r](https://github.com/zMotivat0r) @ [Scalio](https://scal.io/)
<p align="center">
<br/>
<a href="https://scal.io/">
<img src="https://raw.githubusercontent.com/scalio/bazel-nestjs-starter/master/readme-assets/scalio.png"/>
</a>
</p>
34 changes: 34 additions & 0 deletions dist/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "@scalio/nest-couchdb",
"description": "CouchDB module for Nest framework",
"version": "0.1.0",
"license": "MIT",
"main": "index.js",
"typings": "index.d.ts",
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "https://github.com/scalio/nest-couchdb.git"
},
"bugs": {
"url": "https://github.com/scalio/nest-couchdb/issues"
},
"keywords": [
"typescript",
"couchdb",
"orm",
"nest",
"nestjs",
"api",
"backend",
"frameworks"
],
"author": {
"name": "Michael Yali",
"email": "mihon4ik@gmail.com"
},
"dependencies": {},
"peerDependencies": {}
}
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = {
tsConfig: 'tsconfig.jest.json',
},
},
setupFiles: ['./jest.setup.js'],
coverageReporters: ['json', 'lcov', 'text-summary'],
coverageDirectory: 'coverage',
collectCoverageFrom: [
Expand Down
1 change: 1 addition & 0 deletions jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('reflect-metadata');
28 changes: 15 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@scalio/nest-couchdb",
"description": "CouchDB module for Nest framework",
"version": "0.0.0",
"version": "0.1.0",
"license": "MIT",
"private": true,
"scripts": {
Expand All @@ -11,7 +11,7 @@
"commit": "npx git-cz",
"lint": "npx tslint 'src/*.ts'",
"format": "npx pretty-quick --pattern 'src/**/*.ts'",
"test": "echo \"OK\""
"test": "npx jest -c=jest.config.js test/ --verbose --runInBand"
},
"husky": {
"hooks": {
Expand All @@ -29,27 +29,29 @@
}
},
"dependencies": {
"@nestjs/common": "^6.5.2",
"@nestjs/core": "^6.5.2",
"@nestjs/platform-express": "^6.5.2",
"@nestjs/testing": "^6.5.2",
"@nestjs/common": "6.5.2",
"@nestjs/core": "6.5.2",
"@nestjs/platform-express": "6.5.2",
"@nestjs/testing": "6.5.2",
"@types/jest": "24.0.15",
"@types/node": "^12.6.2",
"@types/node": "12.6.2",
"@zmotivat0r/o0": "^1.0.2",
"class-transformer": "^0.2.3",
"commitizen": "3.1.1",
"coveralls": "^3.0.5",
"coveralls": "3.0.5",
"cz-conventional-changelog": "2.1.0",
"husky": "2.7.0",
"jest": "24.8.0",
"nano": "^8.1.0",
"nano": "8.1.0",
"prettier": "1.18.2",
"pretty-quick": "1.11.1",
"reflect-metadata": "^0.1.13",
"rxjs": "^6.5.2",
"reflect-metadata": "0.1.13",
"rxjs": "6.5.2",
"ts-jest": "24.0.2",
"ts-node": "^8.3.0",
"ts-node": "8.3.0",
"tslint": "5.18.0",
"tslint-config-prettier": "1.18.0",
"typescript": "^3.5.3",
"typescript": "3.5.3",
"validate-commit-msg": "2.14.0"
}
}
2 changes: 0 additions & 2 deletions src/constants.ts

This file was deleted.

Loading

0 comments on commit 2c4c95d

Please sign in to comment.