diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..32bbd2e
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,5 @@
+node_modules/
+test/data
+pages/
+coverage/
+public/
diff --git a/.gitlab.ci.yml b/.gitlab.ci.yml
new file mode 100644
index 0000000..d3a9baa
--- /dev/null
+++ b/.gitlab.ci.yml
@@ -0,0 +1,43 @@
+image: hosttoday/ht-docker-node:npmts
+
+stages:
+- test
+- release
+
+before_script:
+ - sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
+ - echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
+ - sudo apt-get update
+ - sudo apt-get install -y mongodb-org
+
+testLEGACY:
+ stage: test
+ script:
+ - npmci test legacy
+ tags:
+ - docker
+ allow_failure: true
+
+testLTS:
+ stage: test
+ script:
+ - npmci test lts
+ tags:
+ - docker
+
+testSTABLE:
+ stage: test
+ script:
+ - npmci test stable
+ tags:
+ - docker
+
+release:
+ stage: release
+ environment: npm_registry
+ script:
+ - npmci publish
+ only:
+ - tags
+ tags:
+ - docker
\ No newline at end of file
diff --git a/dist/index.d.ts b/dist/index.d.ts
new file mode 100644
index 0000000..5647ed9
--- /dev/null
+++ b/dist/index.d.ts
@@ -0,0 +1,14 @@
+///
+import * as plugins from './smartdata.plugins';
+export declare class DbCollection {
+ 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;
+ close(): plugins.q.Promise;
+}
diff --git a/dist/index.js b/dist/index.js
new file mode 100644
index 0000000..f5327ef
--- /dev/null
+++ b/dist/index.js
@@ -0,0 +1,35 @@
+"use strict";
+const plugins = require('./smartdata.plugins');
+class DbCollection {
+ constructor(nameArg, db) {
+ let collection = db.collection(nameArg);
+ }
+}
+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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsTUFBWSxPQUFPLFdBQU0scUJBRXpCLENBQUMsQ0FGNkM7QUFFOUM7SUFDSSxZQUFZLE9BQWUsRUFBRSxFQUFzQjtRQUMvQyxJQUFJLFVBQVUsR0FBRyxFQUFFLENBQUMsVUFBVSxDQUFDLE9BQU8sQ0FBQyxDQUFBO0lBQzNDLENBQUM7QUFDTCxDQUFDO0FBSlksb0JBQVksZUFJeEIsQ0FBQTtBQUlEO0lBS0ksWUFBWSxLQUFhO1FBQ3JCLElBQUksQ0FBQyxLQUFLLEdBQUcsS0FBSyxDQUFBO0lBQ3RCLENBQUM7SUFFRCxPQUFPO1FBQ0gsSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQUUsQ0FBQTtRQUM1QixPQUFPLENBQUMsT0FBTyxDQUFDLFdBQVcsQ0FBQyxPQUFPLENBQUMsSUFBSSxDQUFDLEtBQUssRUFBRSxDQUFDLEdBQUcsRUFBRSxFQUFFO1lBQ3BELEVBQUUsQ0FBQyxDQUFDLEdBQUcsQ0FBQyxDQUFDLENBQUM7Z0JBQUMsT0FBTyxDQUFDLEdBQUcsQ0FBQyxHQUFHLENBQUMsQ0FBQTtZQUFDLENBQUM7WUFDN0IsT0FBTyxDQUFDLE1BQU0sQ0FBQyxLQUFLLENBQUMsSUFBSSxFQUFFLEdBQUcsQ0FBQyxDQUFBO1lBQy9CLElBQUksQ0FBQyxFQUFFLEdBQUcsRUFBRSxDQUFBO1lBQ1osT0FBTyxDQUFDLFNBQVMsQ0FBQyxPQUFPLENBQUMsNEJBQTRCLElBQUksQ0FBQyxLQUFLLEVBQUUsQ0FBQyxDQUFBO1lBQ25FLElBQUksQ0FBQyxPQUFPLENBQUMsSUFBSSxDQUFDLEVBQUUsQ0FBQyxDQUFBO1FBQ3pCLENBQUMsQ0FBQyxDQUFBO1FBQ0YsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUE7SUFDdkIsQ0FBQztJQUVELEtBQUs7UUFDRCxJQUFJLElBQUksR0FBRyxPQUFPLENBQUMsQ0FBQyxDQUFDLEtBQUssRUFBRSxDQUFBO1FBQzVCLElBQUksQ0FBQyxFQUFFLENBQUMsS0FBSyxFQUFFLENBQUE7UUFDZixPQUFPLENBQUMsU0FBUyxDQUFDLEVBQUUsQ0FBQywrQkFBK0IsSUFBSSxDQUFDLEtBQUssRUFBRSxDQUFDLENBQUE7UUFDakUsSUFBSSxDQUFDLE9BQU8sRUFBRSxDQUFBO1FBQ2QsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUE7SUFDdkIsQ0FBQztBQUNMLENBQUM7QUE1Qlksb0JBQVksZUE0QnhCLENBQUEifQ==
\ No newline at end of file
diff --git a/dist/smartdata.plugins.d.ts b/dist/smartdata.plugins.d.ts
new file mode 100644
index 0000000..6712c07
--- /dev/null
+++ b/dist/smartdata.plugins.d.ts
@@ -0,0 +1,5 @@
+import 'typings-global';
+export import assert = require('assert');
+export import beautylog = require('beautylog');
+export import mongodb = require('mongodb');
+export import q = require('q');
diff --git a/dist/smartdata.plugins.js b/dist/smartdata.plugins.js
new file mode 100644
index 0000000..4a33057
--- /dev/null
+++ b/dist/smartdata.plugins.js
@@ -0,0 +1,7 @@
+"use strict";
+require('typings-global');
+exports.assert = require('assert');
+exports.beautylog = require('beautylog');
+exports.mongodb = require('mongodb');
+exports.q = require('q');
+//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRkYXRhLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGRhdGEucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsUUFBTyxnQkFDUCxDQUFDLENBRHNCO0FBQ1QsY0FBTSxXQUFXLFFBQVEsQ0FBQyxDQUFBO0FBQzFCLGlCQUFTLFdBQVcsV0FBVyxDQUFDLENBQUE7QUFDaEMsZUFBTyxXQUFXLFNBQVMsQ0FBQyxDQUFBO0FBQzVCLFNBQUMsV0FBVyxHQUFHLENBQUMsQ0FBQSJ9
\ No newline at end of file
diff --git a/package.json b/package.json
index 0b50292..f5b4713 100644
--- a/package.json
+++ b/package.json
@@ -3,6 +3,7 @@
"version": "1.0.0",
"description": "do more with data",
"main": "dist/index.js",
+ "typings":"dist/index.d.ts",
"scripts": {
"test": "(npmts)"
},
@@ -15,5 +16,20 @@
"bugs": {
"url": "https://gitlab.com/pushrocks/smartdata/issues"
},
- "homepage": "https://gitlab.com/pushrocks/smartdata#README"
+ "homepage": "https://gitlab.com/pushrocks/smartdata#README",
+ "dependencies": {
+ "@types/mongodb": "^2.1.32",
+ "@types/q": "0.0.30",
+ "beautylog": "^5.0.23",
+ "mongodb": "^2.2.9",
+ "q": "^1.4.1",
+ "typings-global": "^1.0.14"
+ },
+ "devDependencies": {
+ "@types/shelljs": "^0.3.30",
+ "@types/should": "^8.1.29",
+ "shelljs": "^0.7.4",
+ "should": "^11.1.0",
+ "typings-test": "^1.0.3"
+ }
}
diff --git a/test/test.d.ts b/test/test.d.ts
new file mode 100644
index 0000000..2fd432a
--- /dev/null
+++ b/test/test.d.ts
@@ -0,0 +1 @@
+import 'typings-test';
diff --git a/test/test.js b/test/test.js
new file mode 100644
index 0000000..1355d5a
--- /dev/null
+++ b/test/test.js
@@ -0,0 +1,29 @@
+"use strict";
+require('typings-test');
+const shelljs = require('shelljs');
+const smartdata = require('../dist/index');
+let mongoChildProcess;
+let testDbConnection;
+describe('mongodb', function () {
+ it('should start mongodb', function (done) {
+ mongoChildProcess = shelljs.exec('mongod --dbpath=./test/data --port 27017', { async: true });
+ setTimeout(() => { done(); }, 1500);
+ });
+});
+describe('smartdata', function () {
+ it('should establish a connection to mongodb', function (done) {
+ testDbConnection = new smartdata.DbConnection('mongodb://localhost:27017/smartdata');
+ testDbConnection.connect().then(() => { done(); });
+ });
+ it('should create a collection', function () {
+ });
+ it('should close the db Connection', function () {
+ testDbConnection.close();
+ });
+});
+describe('mongodb', function () {
+ it('should kill mongodb', function () {
+ mongoChildProcess.kill('SIGTERM');
+ });
+});
+//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sY0FDUCxDQUFDLENBRG9CO0FBQ3JCLE1BQVksT0FBTyxXQUFNLFNBQ3pCLENBQUMsQ0FEaUM7QUFFbEMsTUFBWSxTQUFTLFdBQU0sZUFHM0IsQ0FBQyxDQUh5QztBQUcxQyxJQUFJLGlCQUFpQixDQUFBO0FBQ3JCLElBQUksZ0JBQXdDLENBQUE7QUFHNUMsUUFBUSxDQUFDLFNBQVMsRUFBQztJQUNmLEVBQUUsQ0FBQyxzQkFBc0IsRUFBQyxVQUFTLElBQUk7UUFDbkMsaUJBQWlCLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQywwQ0FBMEMsRUFBQyxFQUFDLEtBQUssRUFBRSxJQUFJLEVBQUMsQ0FBQyxDQUFBO1FBQzFGLFVBQVUsQ0FBQyxRQUFRLElBQUksRUFBRSxDQUFBLENBQUMsQ0FBQyxFQUFFLElBQUksQ0FBQyxDQUFBO0lBQ3RDLENBQUMsQ0FBQyxDQUFBO0FBQ04sQ0FBQyxDQUFDLENBQUE7QUFDRixRQUFRLENBQUMsV0FBVyxFQUFDO0lBQ2pCLEVBQUUsQ0FBQywwQ0FBMEMsRUFBQyxVQUFTLElBQUk7UUFDdkQsZ0JBQWdCLEdBQUcsSUFBSSxTQUFTLENBQUMsWUFBWSxDQUFDLHFDQUFxQyxDQUFDLENBQUE7UUFDcEYsZ0JBQWdCLENBQUMsT0FBTyxFQUFFLENBQUMsSUFBSSxDQUFDLFFBQVEsSUFBSSxFQUFFLENBQUEsQ0FBQyxDQUFDLENBQUMsQ0FBQTtJQUNyRCxDQUFDLENBQUMsQ0FBQTtJQUNGLEVBQUUsQ0FBQyw0QkFBNEIsRUFBQztJQUVoQyxDQUFDLENBQUMsQ0FBQTtJQUNGLEVBQUUsQ0FBQyxnQ0FBZ0MsRUFBQztRQUNoQyxnQkFBZ0IsQ0FBQyxLQUFLLEVBQUUsQ0FBQztJQUM3QixDQUFDLENBQUMsQ0FBQTtBQUNOLENBQUMsQ0FBQyxDQUFBO0FBRUYsUUFBUSxDQUFDLFNBQVMsRUFBQztJQUNmLEVBQUUsQ0FBQyxxQkFBcUIsRUFBQztRQUNyQixpQkFBaUIsQ0FBQyxJQUFJLENBQUMsU0FBUyxDQUFDLENBQUE7SUFDckMsQ0FBQyxDQUFDLENBQUE7QUFDTixDQUFDLENBQUMsQ0FBQSJ9
\ No newline at end of file
diff --git a/test/test.ts b/test/test.ts
new file mode 100644
index 0000000..95420d1
--- /dev/null
+++ b/test/test.ts
@@ -0,0 +1,34 @@
+import 'typings-test'
+import * as shelljs from 'shelljs'
+import * as should from 'should'
+import * as smartdata from '../dist/index'
+
+
+let mongoChildProcess
+let testDbConnection: smartdata.DbConnection
+
+
+describe('mongodb',function(){
+ it('should start mongodb',function(done){
+ mongoChildProcess = shelljs.exec('mongod --dbpath=./test/data --port 27017',{async: true})
+ setTimeout(() => { done() }, 1500)
+ })
+})
+describe('smartdata',function(){
+ it('should establish a connection to mongodb',function(done){
+ testDbConnection = new smartdata.DbConnection('mongodb://localhost:27017/smartdata')
+ testDbConnection.connect().then(() => { done() })
+ })
+ it('should create a collection',function(){
+
+ })
+ it('should close the db Connection',function(){
+ testDbConnection.close()
+ })
+})
+
+describe('mongodb',function(){
+ it('should kill mongodb',function(){
+ mongoChildProcess.kill('SIGTERM')
+ })
+})
diff --git a/ts/index.ts b/ts/index.ts
new file mode 100644
index 0000000..92d063f
--- /dev/null
+++ b/ts/index.ts
@@ -0,0 +1,39 @@
+import * as plugins from './smartdata.plugins'
+
+export class DbCollection {
+ 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 {
+ 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 {
+ let done = plugins.q.defer()
+ this.db.close()
+ plugins.beautylog.ok(`disconnected to database at ${this.dbUrl}`)
+ done.resolve()
+ return done.promise
+ }
+}
diff --git a/ts/smartdata.plugins.ts b/ts/smartdata.plugins.ts
new file mode 100644
index 0000000..c9a57a0
--- /dev/null
+++ b/ts/smartdata.plugins.ts
@@ -0,0 +1,5 @@
+import 'typings-global'
+export import assert = require('assert')
+export import beautylog = require('beautylog')
+export import mongodb = require('mongodb')
+export import q = require('q')
diff --git a/tslint.json b/tslint.json
new file mode 100644
index 0000000..508bcac
--- /dev/null
+++ b/tslint.json
@@ -0,0 +1,3 @@
+{
+ "extends": "tslint-config-standard"
+}
\ No newline at end of file