split into class files

This commit is contained in:
Philipp Kunz 2016-09-11 18:01:46 +02:00
parent 50b5f84955
commit 295096de24
11 changed files with 151 additions and 86 deletions

16
dist/index.d.ts vendored
View File

@ -1,14 +1,2 @@
/// <reference types="q" />
import * as plugins from './smartdata.plugins';
export declare class DbCollection<T> {
constructor(nameArg: string, db: plugins.mongodb.Db);
}
export declare type TDbConnectionStatus = 'disconnected' | 'connected' | 'failed';
export declare class DbConnection {
dbUrl: string;
db: plugins.mongodb.Db;
status: TDbConnectionStatus;
constructor(dbUrl: string);
connect(): plugins.q.Promise<any>;
close(): plugins.q.Promise<any>;
}
export * from './smartdata.classes.dbcollection';
export * from './smartdata.classes.dbconnection';

38
dist/index.js vendored
View File

@ -1,35 +1,7 @@
"use strict";
const plugins = require('./smartdata.plugins');
class DbCollection {
constructor(nameArg, db) {
let collection = db.collection(nameArg);
}
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
exports.DbCollection = DbCollection;
class DbConnection {
constructor(dbUrl) {
this.dbUrl = dbUrl;
}
connect() {
let done = plugins.q.defer();
plugins.mongodb.MongoClient.connect(this.dbUrl, (err, db) => {
if (err) {
console.log(err);
}
plugins.assert.equal(null, err);
this.db = db;
plugins.beautylog.success(`connected to database at ${this.dbUrl}`);
done.resolve(this.db);
});
return done.promise;
}
close() {
let done = plugins.q.defer();
this.db.close();
plugins.beautylog.ok(`disconnected to database at ${this.dbUrl}`);
done.resolve();
return done.promise;
}
}
exports.DbConnection = DbConnection;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsTUFBWSxPQUFPLFdBQU0scUJBRXpCLENBQUMsQ0FGNkM7QUFFOUM7SUFDSSxZQUFZLE9BQWUsRUFBRSxFQUFzQjtRQUMvQyxJQU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ENBQUMsS0FBSyxFQUFFLENBQUE7UUFDZixPQUFPLENBQUMsU0FBUyxDQUFDLEVBQUUsQ0FBQywrQkFBK0IsSUFBSSxDQUFDLEtBQUssRUFBRSxDQUFDLENBQUE7UUFDakUsSUFBSSxDQUFDLE9BQU8sRUFBRSxDQUFBO1FBQ2QsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUE7SUFDdkIsQ0FBQztBQUNMLENBQUM7QUE1Qlksb0JBQVksZUE0QnhCLENBQUEifQ==
__export(require('./smartdata.classes.dbcollection'));
__export(require('./smartdata.classes.dbconnection'));
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7O0FBRUEsaUJBQWMsa0NBQ2QsQ0FBQyxFQUQrQztBQUNoRCxpQkFBYyxrQ0FDZCxDQUFDLEVBRCtDIn0=

View File

@ -0,0 +1,18 @@
import * as plugins from './smartdata.plugins';
import { DbConnection } from './smartdata.classes.dbconnection';
export declare class DbCollection<T> {
collection: plugins.mongodb.Collection;
constructor(nameArg: string, dbConnectionArg: DbConnection);
/**
* adds a validation function that all newly inserted and updated objects have to pass
*/
addObjectValidation(): void;
/**
* inserts am object into the DbCollection
*/
insert(objectArg: T): void;
/**
* inserts many objects at once into the DbCollection
*/
insertMany(objectArrayArg: T[]): void;
}

20
dist/smartdata.classes.dbcollection.js vendored Normal file
View File

@ -0,0 +1,20 @@
"use strict";
class DbCollection {
constructor(nameArg, dbConnectionArg) {
this.collection = dbConnectionArg.db.collection(nameArg);
}
/**
* adds a validation function that all newly inserted and updated objects have to pass
*/
addObjectValidation() { }
/**
* inserts am object into the DbCollection
*/
insert(objectArg) { }
/**
* inserts many objects at once into the DbCollection
*/
insertMany(objectArrayArg) { }
}
exports.DbCollection = DbCollection;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRkYXRhLmNsYXNzZXMuZGJjb2xsZWN0aW9uLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRkYXRhLmNsYXNzZXMuZGJjb2xsZWN0aW9uLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFHQTtJQUVJLFlBQVksT0FBZSxFQUFFLGVBQTZCO1FBQ3RELElBQUksQ0FBQyxVQUFVLEdBQUcsZUFBZSxDQUFDLEVBQUUsQ0FBQyxVQUFVLENBQUMsT0FBTyxDQUFDLENBQUE7SUFDNUQsQ0FBQztJQUVEOztPQUVHO0lBQ0gsbUJBQW1CLEtBQUcsQ0FBQztJQUV2Qjs7T0FFRztJQUNILE1BQU0sQ0FBQyxTQUFZLElBQUcsQ0FBQztJQUV2Qjs7T0FFRztJQUNILFVBQVUsQ0FBQyxjQUFtQixJQUFHLENBQUM7QUFDdEMsQ0FBQztBQXBCWSxvQkFBWSxlQW9CeEIsQ0FBQSJ9

View File

@ -0,0 +1,11 @@
/// <reference types="q" />
import * as plugins from './smartdata.plugins';
export declare type TDbConnectionStatus = 'disconnected' | 'connected' | 'failed';
export declare class DbConnection {
dbUrl: string;
db: plugins.mongodb.Db;
status: TDbConnectionStatus;
constructor(dbUrl: string);
connect(): plugins.q.Promise<any>;
close(): plugins.q.Promise<any>;
}

29
dist/smartdata.classes.dbconnection.js vendored Normal file
View File

@ -0,0 +1,29 @@
"use strict";
const plugins = require('./smartdata.plugins');
class DbConnection {
constructor(dbUrl) {
this.dbUrl = dbUrl;
}
connect() {
let done = plugins.q.defer();
plugins.mongodb.MongoClient.connect(this.dbUrl, (err, db) => {
if (err) {
console.log(err);
}
plugins.assert.equal(null, err);
this.db = db;
plugins.beautylog.success(`connected to database at ${this.dbUrl}`);
done.resolve(this.db);
});
return done.promise;
}
close() {
let done = plugins.q.defer();
this.db.close();
plugins.beautylog.ok(`disconnected to database at ${this.dbUrl}`);
done.resolve();
return done.promise;
}
}
exports.DbConnection = DbConnection;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRkYXRhLmNsYXNzZXMuZGJjb25uZWN0aW9uLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRkYXRhLmNsYXNzZXMuZGJjb25uZWN0aW9uLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxNQUFZLE9BQU8sV0FBTSxxQkFFekIsQ0FBQyxDQUY2QztBQUk5QztJQUtJLFlBQVksS0FBYTtRQUNyQixJQUFJLENBQUMsS0FBSyxHQUFHLEtBQUssQ0FBQTtJQUN0QixDQUFDO0lBRUQsT0FBTztRQUNILElBQUksSUFBSSxHQUFHLE9BQU8sQ0FBQyxDQUFDLENBQUMsS0FBSyxFQUFFLENBQUE7UUFDNUIsT0FBTyxDQUFDLE9BQU8sQ0FBQyxXQUFXLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxLQUFLLEVBQUUsQ0FBQyxHQUFHLEVBQUUsRUFBRTtZQUNwRCxFQUFFLENBQUMsQ0FBQyxHQUFHLENBQUMsQ0FBQyxDQUFDO2dCQUFDLE9BQU8sQ0FBQyxHQUFHLENBQUMsR0FBRyxDQUFDLENBQUE7WUFBQyxDQUFDO1lBQzdCLE9BQU8sQ0FBQyxNQUFNLENBQUMsS0FBSyxDQUFDLElBQUksRUFBRSxHQUFHLENBQUMsQ0FBQTtZQUMvQixJQUFJLENBQUMsRUFBRSxHQUFHLEVBQUUsQ0FBQTtZQUNaLE9BQU8sQ0FBQyxTQUFTLENBQUMsT0FBTyxDQUFDLDRCQUE0QixJQUFJLENBQUMsS0FBSyxFQUFFLENBQUMsQ0FBQTtZQUNuRSxJQUFJLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxFQUFFLENBQUMsQ0FBQTtRQUN6QixDQUFDLENBQUMsQ0FBQTtRQUNGLE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFBO0lBQ3ZCLENBQUM7SUFFRCxLQUFLO1FBQ0QsSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQUUsQ0FBQTtRQUM1QixJQUFJLENBQUMsRUFBRSxDQUFDLEtBQUssRUFBRSxDQUFBO1FBQ2YsT0FBTyxDQUFDLFNBQVMsQ0FBQyxFQUFFLENBQUMsK0JBQStCLElBQUksQ0FBQyxLQUFLLEVBQUUsQ0FBQyxDQUFBO1FBQ2pFLElBQUksQ0FBQyxPQUFPLEVBQUUsQ0FBQTtRQUNkLE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFBO0lBQ3ZCLENBQUM7QUFDTCxDQUFDO0FBNUJZLG9CQUFZLGVBNEJ4QixDQUFBIn0=

View File

@ -4,6 +4,7 @@ const shelljs = require('shelljs');
const smartdata = require('../dist/index');
let mongoChildProcess;
let testDbConnection;
let testDbCollection;
describe('mongodb', function () {
it('should start mongodb', function (done) {
this.timeout(10000);
@ -17,6 +18,7 @@ describe('smartdata', function () {
testDbConnection.connect().then(() => { done(); });
});
it('should create a collection', function () {
testDbCollection = new smartdata.DbCollection('something', testDbConnection);
});
it('should close the db Connection', function () {
testDbConnection.close();
@ -24,8 +26,9 @@ describe('smartdata', function () {
});
describe('mongodb', function () {
it('should kill mongodb', function () {
this.timeout(10000);
shelljs.exec('mongod --dbpath=./test/data --shutdown');
mongoChildProcess.kill('SIGTERM');
});
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sY0FDUCxDQUFDLENBRG9CO0FBQ3JCLE1BQVksT0FBTyxXQUFNLFNBQ3pCLENBQUMsQ0FEaUM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dBQVcsRUFBQztJQUNqQixFQUFFLENBQUMsMENBQTBDLEVBQUMsVUFBUyxJQUFJO1FBQ3ZELGdCQUFnQixHQUFHLElBQUksU0FBUyxDQUFDLFlBQVksQ0FBQyxxQ0FBcUMsQ0FBQyxDQUFBO1FBQ3BGLGdCQUFnQixDQUFDLE9BQU8sRUFBRSxDQUFDLElBQUksQ0FBQyxRQUFRLElBQUksRUFBRSxDQUFBLENBQUMsQ0FBQyxDQUFDLENBQUE7SUFDckQsQ0FBQyxDQUFDLENBQUE7SUFDRixFQUFFLENBQUMsNEJBQTRCLEVBQUM7UUFDNUIsZ0JBQWdCLEdBQUcsSUFBSSxTQUFTLENBQUMsWUFBWSxDQUFDLFdBQVcsRUFBQyxnQkFBZ0IsQ0FBQyxDQUFBO0lBQy9FLENBQUMsQ0FBQyxDQUFBO0lBQ0YsRUFBRSxDQUFDLGdDQUFnQyxFQUFDO1FBQ2hDLGdCQUFnQixDQUFDLEtBQUssRUFBRSxDQUFBO0lBQzVCLENBQUMsQ0FBQyxDQUFBO0FBQ04sQ0FBQyxDQUFDLENBQUE7QUFFRixRQUFRLENBQUMsU0FBUyxFQUFDO0lBQ2YsRUFBRSxDQUFDLHFCQUFxQixFQUFDO1FBQ3JCLElBQUksQ0FBQyxPQUFPLENBQUMsS0FBSyxDQUFDLENBQUE7UUFDbkIsT0FBTyxDQUFDLElBQUksQ0FBQyx3Q0FBd0MsQ0FBQyxDQUFBO1FBQ3RELGlCQUFpQixDQUFDLElBQUksQ0FBQyxTQUFTLENBQUMsQ0FBQTtJQUNyQyxDQUFDLENBQUMsQ0FBQTtBQUNOLENBQUMsQ0FBQyxDQUFBIn0=

View File

@ -6,6 +6,7 @@ import * as smartdata from '../dist/index'
let mongoChildProcess
let testDbConnection: smartdata.DbConnection
let testDbCollection: smartdata.DbCollection<any>
describe('mongodb',function(){
@ -21,7 +22,7 @@ describe('smartdata',function(){
testDbConnection.connect().then(() => { done() })
})
it('should create a collection',function(){
testDbCollection = new smartdata.DbCollection('something',testDbConnection)
})
it('should close the db Connection',function(){
testDbConnection.close()
@ -30,6 +31,7 @@ describe('smartdata',function(){
describe('mongodb',function(){
it('should kill mongodb',function(){
this.timeout(10000)
shelljs.exec('mongod --dbpath=./test/data --shutdown')
mongoChildProcess.kill('SIGTERM')
})

View File

@ -1,39 +1,4 @@
import * as plugins from './smartdata.plugins'
export class DbCollection<T> {
constructor(nameArg: string, db: plugins.mongodb.Db) {
let collection = db.collection(nameArg)
}
}
export type TDbConnectionStatus = 'disconnected' | 'connected' | 'failed'
export class DbConnection {
dbUrl: string
db: plugins.mongodb.Db
status: TDbConnectionStatus
constructor(dbUrl: string) {
this.dbUrl = dbUrl
}
connect(): plugins.q.Promise<any> {
let done = plugins.q.defer()
plugins.mongodb.MongoClient.connect(this.dbUrl, (err, db) => {
if (err) { console.log(err) }
plugins.assert.equal(null, err)
this.db = db
plugins.beautylog.success(`connected to database at ${this.dbUrl}`)
done.resolve(this.db)
})
return done.promise
}
close(): plugins.q.Promise<any> {
let done = plugins.q.defer()
this.db.close()
plugins.beautylog.ok(`disconnected to database at ${this.dbUrl}`)
done.resolve()
return done.promise
}
}
export * from './smartdata.classes.dbcollection'
export * from './smartdata.classes.dbconnection'

View File

@ -0,0 +1,24 @@
import * as plugins from './smartdata.plugins'
import { DbConnection } from './smartdata.classes.dbconnection'
export class DbCollection<T> {
collection: plugins.mongodb.Collection
constructor(nameArg: string, dbConnectionArg: DbConnection) {
this.collection = dbConnectionArg.db.collection(nameArg)
}
/**
* adds a validation function that all newly inserted and updated objects have to pass
*/
addObjectValidation(){}
/**
* inserts am object into the DbCollection
*/
insert(objectArg: T) {}
/**
* inserts many objects at once into the DbCollection
*/
insertMany(objectArrayArg: T[]) {}
}

View File

@ -0,0 +1,33 @@
import * as plugins from './smartdata.plugins'
export type TDbConnectionStatus = 'disconnected' | 'connected' | 'failed'
export class DbConnection {
dbUrl: string
db: plugins.mongodb.Db
status: TDbConnectionStatus
constructor(dbUrl: string) {
this.dbUrl = dbUrl
}
connect(): plugins.q.Promise<any> {
let done = plugins.q.defer()
plugins.mongodb.MongoClient.connect(this.dbUrl, (err, db) => {
if (err) { console.log(err) }
plugins.assert.equal(null, err)
this.db = db
plugins.beautylog.success(`connected to database at ${this.dbUrl}`)
done.resolve(this.db)
})
return done.promise
}
close(): plugins.q.Promise<any> {
let done = plugins.q.defer()
this.db.close()
plugins.beautylog.ok(`disconnected to database at ${this.dbUrl}`)
done.resolve()
return done.promise
}
}