Comparing version 1.4.0 to 2.0.0
@@ -1,5 +0,4 @@ | ||
import 'reflect-metadata'; | ||
export * from './repository'; | ||
export * from './decorators'; | ||
export * from './db'; | ||
export * from './types'; | ||
export * from './Repository'; | ||
export * from './Decorators'; | ||
export * from './Types'; | ||
export * from './DatabaseClient'; |
@@ -6,7 +6,6 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
require("reflect-metadata"); | ||
__export(require("./repository")); | ||
__export(require("./decorators")); | ||
__export(require("./db")); | ||
__export(require("./types")); | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7QUFBQSw0QkFBMEI7QUFDMUIsa0NBQTZCO0FBQzdCLGtDQUE2QjtBQUM3QiwwQkFBcUI7QUFDckIsNkJBQXdCIiwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0ICdyZWZsZWN0LW1ldGFkYXRhJztcbmV4cG9ydCAqIGZyb20gJy4vcmVwb3NpdG9yeSc7XG5leHBvcnQgKiBmcm9tICcuL2RlY29yYXRvcnMnO1xuZXhwb3J0ICogZnJvbSAnLi9kYic7XG5leHBvcnQgKiBmcm9tICcuL3R5cGVzJztcbiJdfQ== | ||
__export(require("./Repository")); | ||
__export(require("./Decorators")); | ||
__export(require("./Types")); | ||
__export(require("./DatabaseClient")); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "mongtype", | ||
"version": "1.4.0", | ||
"version": "2.0.0", | ||
"description": "Mongo Repository for Node written in TypeScript", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"build": "tsc", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"build": "rimraf dist && tsc", | ||
"test": "npm run lint && npm run test:unit", | ||
"test:unit": "mocha --require ts-node/register ./tests/**/*.spec.ts -R spec --bail", | ||
"test:cov": "nyc npm run test:unit", | ||
"test:report": "cat ./coverage/lcov.info | codacy-coverage --language typescript", | ||
"lint": "tslint ./{src,tests}/{,**/}*.ts", | ||
"prepublishOnly": "npm run test && npm run build" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://amcdnl@github.com/swimlane/montype.git" | ||
"url": "git+https://github.com/swimlane/montype.git" | ||
}, | ||
@@ -20,3 +28,3 @@ "keywords": [ | ||
], | ||
"author": "Swimlane", | ||
"author": "Swimlane <dev@swimlane.com>", | ||
"license": "MIT", | ||
@@ -28,14 +36,47 @@ "bugs": { | ||
"devDependencies": { | ||
"@types/node": "^6.0.81", | ||
"tslint": "^4.4.2", | ||
"tslint-config-swimlane": "^2.0.1", | ||
"typescript": "^2.2.2" | ||
"@types/chai": "^4.1.0", | ||
"@types/faker": "^4.1.2", | ||
"@types/mocha": "^2.2.46", | ||
"@types/mongodb": "^2.2.19", | ||
"@types/node": "^8.5.8", | ||
"@types/retry": "^0.10.2", | ||
"chai": "^4.1.2", | ||
"codacy-coverage": "^2.0.3", | ||
"faker": "^4.1.0", | ||
"mocha": "^4.1.0", | ||
"mongo-mock": "^2.9.0", | ||
"nyc": "^11.4.1", | ||
"reflect-metadata": "^0.1.10", | ||
"rimraf": "^2.6.2", | ||
"ts-node": "^4.1.0", | ||
"tslint": "^5.9.1", | ||
"tslint-config-swimlane": "^3.0.4", | ||
"typescript": "^2.6.2" | ||
}, | ||
"dependencies": { | ||
"injection-js": "^2.0.1", | ||
"inversify": "^4.3.0", | ||
"mongodb": "^2.2.25", | ||
"reflect-metadata": "^0.1.10", | ||
"mongodb": "^2.2.34", | ||
"retry": "^0.10.1" | ||
}, | ||
"peerDependencies": { | ||
"reflect-metadata": "^0.1.10" | ||
}, | ||
"nyc": { | ||
"include": [ | ||
"src/*.ts", | ||
"src/**/*.ts" | ||
], | ||
"exclude": [ | ||
"src/*.d.ts", | ||
"src/**/*.d.ts" | ||
], | ||
"extension": [ | ||
".ts" | ||
], | ||
"reporter": [ | ||
"lcov", | ||
"html", | ||
"text" | ||
], | ||
"all": true | ||
} | ||
} |
# MongType | ||
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/4435e55cddf24b0f98831c3ae34c960d)](https://www.codacy.com/app/Swimlane/mongtype?utm_source=github.com&utm_medium=referral&utm_content=swimlane/mongtype&utm_campaign=Badge_Grade) [![Codacy Badge](https://api.codacy.com/project/badge/Coverage/4435e55cddf24b0f98831c3ae34c960d)](https://www.codacy.com/app/Swimlane/mongtype?utm_source=github.com&utm_medium=referral&utm_content=swimlane/mongtype&utm_campaign=Badge_Coverage) [![Build Status](https://travis-ci.org/swimlane/mongtype.svg?branch=master)](https://travis-ci.org/swimlane/mongtype) [![npm version](https://badge.fury.io/js/mongtype.svg)](https://badge.fury.io/js/mongtype) | ||
MongoDB Repository pattern for NodeJS written in TypeScript. | ||
## Install | ||
`npm i mongtype --S` | ||
## Building | ||
`npm run build` | ||
@@ -12,5 +17,26 @@ | ||
#### Using DI | ||
[Migrating from 1.X to 2.X](UPGRADE.md) | ||
### DatabaseClient | ||
The `DatabaseClient` class provides a wrapper around a mongodb connection | ||
It has a single method called `connect` that allows you to provide a uri to a MongoDB instance and optionally include an already established mongodb connection. | ||
```typescript | ||
import { DatabaseClient } from 'mongtype'; | ||
const uri = 'mongodb://localhost/Foo'; | ||
const dbc = new DatabaseClient(); | ||
// DatabaseClient manages the connection | ||
dbc.connect(uri); | ||
// DatabaseClient reuses an existing connection | ||
dbc.connect(uri, mongodbInstance); | ||
``` | ||
### Using DI | ||
```javascript | ||
import { MongoRepository, Collection, Pre, Post, Database } from 'mongtype'; | ||
import { MongoRepository, Collection, Pre, Post } from 'mongtype'; | ||
import { Injectable } from 'injection-js'; | ||
@@ -38,6 +64,4 @@ | ||
export class App { | ||
constructor(private db: Database, private userRepo: UserRepository) { | ||
db.connect('yourconnectionstring'); | ||
} | ||
constructor(private userRepo: UserRepository) { } | ||
async findUsers() { | ||
@@ -52,7 +76,8 @@ const one = await this.userRepo.findById('3434-34-34343-3434'); | ||
#### Without DI | ||
### Without DI | ||
```javascript | ||
const db = new Database(); | ||
db.connect('yourconnectionstring'); | ||
const svc = new UserRepository(db); | ||
const dbc = new DatabaseClient(); | ||
dbc.connect('mongodb://your.mongo.url'); // optional existing connection as second arg | ||
const svc = new UserRepository(dbc); | ||
@@ -66,5 +91,7 @@ const one = await svc.findById('3434-34-34343-3434'); | ||
## Similar | ||
- [ts-mongo](https://github.com/joesonw/ts-mongo/) | ||
## Credits | ||
MongType is a [Swimlane](http://swimlane.com) open-source project; we believe in giving back to the open-source community by sharing some of the projects we build for our application. Swimlane is an automated cyber security operations and incident response platform that enables cyber security teams to leverage threat intelligence, speed up incident response and automate security operations. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
3
0
94
32716
18
18
580
2
- Removedinjection-js@^2.0.1
- Removedinversify@^4.3.0
- Removedreflect-metadata@^0.1.10
- Removedinjection-js@2.4.0(transitive)
- Removedinversify@4.14.0(transitive)
- Removedtslib@2.8.1(transitive)
Updatedmongodb@^2.2.34