Comparing version 0.2.1 to 0.2.2
@@ -25,3 +25,6 @@ "use strict"; | ||
disconnect() { | ||
return this.db.close(); | ||
if (this.db) { | ||
return this.db.close(); | ||
} | ||
return Promise.resolve(); | ||
} | ||
@@ -33,5 +36,6 @@ static connect(uri, options) { | ||
return new Promise((resolve, reject) => { | ||
MongoDb.MongoClient.connect(uri, options, (error, db) => { | ||
const callback = (error, db) => { | ||
error ? reject(error) : resolve(new Connection(db)); | ||
}); | ||
}; | ||
MongoDb.MongoClient.connect(uri, options, callback); | ||
}); | ||
@@ -38,0 +42,0 @@ } |
@@ -49,4 +49,4 @@ /// <reference types="node" /> | ||
protected readonly cast: (value: any) => T; | ||
constructor(values: T[], cast?: (value: any) => T); | ||
toArray(): any[]; | ||
constructor(values?: T[], cast?: (value: any) => T); | ||
toArray(): any; | ||
push(...items: Object[]): number; | ||
@@ -53,0 +53,0 @@ unshift(...items: Object[]): number; |
@@ -37,5 +37,4 @@ "use strict"; | ||
case 'object': { | ||
if (Array.isArray(value)) { | ||
return [].concat(value) | ||
.map(x => TypeCast.toPlainValue(x)); | ||
if (value === null) { | ||
return value; | ||
} | ||
@@ -48,4 +47,9 @@ if (value instanceof mongodb_1.ObjectID) { | ||
} | ||
if (value instanceof SchemaArray) { | ||
return value.toArray(); | ||
} | ||
if (Array.isArray(value)) { | ||
return value.map(x => TypeCast.toPlainValue(x)); | ||
} | ||
return Object.assign({}, ...Object.keys(value) | ||
.filter(key => typeof value[key] !== 'undefined') | ||
.map(key => ({ [key]: TypeCast.toPlainValue(value[key]) }))); | ||
@@ -198,6 +202,8 @@ } | ||
this.cast = cast ? cast : x => x; | ||
values.forEach(value => this.push(value)); | ||
if (values && typeof values === 'object') { | ||
[...values].forEach(value => this.push(value)); | ||
} | ||
} | ||
toArray() { | ||
return this.map(value => TypeCast.toPlainValue(value)); | ||
return [...this].map(value => TypeCast.toPlainValue(value)); | ||
} | ||
@@ -204,0 +210,0 @@ push(...items) { |
@@ -11,3 +11,3 @@ import * as MongoDb from 'mongodb'; | ||
}): F; | ||
destroy(): Promise<void>; | ||
destroy(): Promise<any>; | ||
} | ||
@@ -14,0 +14,0 @@ export { Repository }; |
@@ -17,3 +17,3 @@ "use strict"; | ||
destroy() { | ||
return this.state.then(connection => connection.disconnect()); | ||
return this.state.then(connection => connection.disconnect(), error => error); | ||
} | ||
@@ -20,0 +20,0 @@ } |
@@ -35,4 +35,4 @@ "use strict"; | ||
class FooFragment extends document_1.SchemaFragment { | ||
constructor(...args) { | ||
super(...args); | ||
constructor() { | ||
super(...arguments); | ||
this.bar = new BarFragment({ baz: 'hello' }); | ||
@@ -47,4 +47,4 @@ } | ||
class TestDocument extends document_1.SchemaDocument { | ||
constructor(...args) { | ||
super(...args); | ||
constructor() { | ||
super(...arguments); | ||
this.number = Math.random(); | ||
@@ -51,0 +51,0 @@ this.listOfNumbers = new document_1.SchemaArray([1, 2, 3]); |
{ | ||
"name": "mongot", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"description": "A lightweight typed MongoDb library for TypeScript.", | ||
@@ -33,3 +33,3 @@ "main": "build/index.js", | ||
"dependencies": { | ||
"@types/mongodb": "^2.1.30", | ||
"@types/mongodb": "^2.1.33", | ||
"mongodb": "^2.2.5" | ||
@@ -42,4 +42,4 @@ }, | ||
"tape": "^4.6.0", | ||
"typescript": "^2.0.0" | ||
"typescript": "^2.0.3" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
115787
1783
Updated@types/mongodb@^2.1.33