Compare commits

...

144 Commits

Author SHA1 Message Date
72894e3ef1 3.1.29 2020-06-12 05:59:08 +00:00
bbe5f8c6a8 fix(core): update 2020-06-12 05:59:07 +00:00
02af9f5c4b 3.1.28 2020-06-11 23:08:38 +00:00
17de480272 fix(core): update 2020-06-11 23:08:38 +00:00
776fd3ee4e 3.1.27 2020-06-11 23:05:46 +00:00
3272bb7235 fix(core): update 2020-06-11 23:05:45 +00:00
116dfbc3b0 update module structure 2020-06-11 23:05:32 +00:00
3f714b1a33 3.1.26 2020-02-19 18:30:35 +00:00
e58fa57525 fix(core): update 2020-02-19 18:30:34 +00:00
8e7ad5210f 3.1.25 2020-02-08 14:37:45 +00:00
cea6c662ac fix(core): update 2020-02-08 14:37:44 +00:00
6eb43a4b9f 3.1.24 2020-02-08 14:01:55 +00:00
7f89cbeecd fix(core): update 2020-02-08 14:01:55 +00:00
a042a589a0 3.1.23 2019-09-11 12:36:03 +02:00
75b5f6af08 fix(core): update 2019-09-11 12:36:02 +02:00
e6a36f22ac 3.1.22 2019-09-11 12:12:51 +02:00
246e3486f0 fix(id field now properly populated): update 2019-09-11 12:12:50 +02:00
c1c4a29415 3.1.21 2019-09-11 11:56:41 +02:00
6448516aa0 fix(core): update 2019-09-11 11:56:41 +02:00
24a7b2dbd3 3.1.20 2019-09-04 17:41:53 +02:00
afa7c2fe61 fix(core): update 2019-09-04 17:41:53 +02:00
b768896fbe 3.1.19 2019-09-04 17:25:50 +02:00
8d7d9adef1 fix(core): update 2019-09-04 17:25:50 +02:00
ca6d3c60c0 3.1.18 2019-09-02 16:58:19 +02:00
38c1fcd53a fix(core): update 2019-09-02 16:58:19 +02:00
e433b9e212 3.1.17 2019-09-02 16:51:22 +02:00
bf3656f792 fix(core): update 2019-09-02 16:51:22 +02:00
7e9fc62ce7 3.1.16 2019-09-02 16:50:23 +02:00
670a0c63fb fix(core): update 2019-09-02 16:50:22 +02:00
64e76b3ed1 3.1.15 2019-09-02 16:42:30 +02:00
25803330de fix(core): update 2019-09-02 16:42:29 +02:00
c6cbff1308 3.1.14 2019-02-13 22:08:58 +01:00
3eeac7b936 fix(structure): format 2019-02-13 22:08:58 +01:00
761b742e21 3.1.13 2019-01-08 19:55:14 +01:00
e56def621c fix(core): update 2019-01-08 19:55:13 +01:00
ab1799f4f2 3.1.12 2019-01-08 18:59:36 +01:00
9985b849d1 3.1.11 2019-01-08 18:45:31 +01:00
1800273b25 fix(core): update 2019-01-08 18:45:30 +01:00
e715cc6d37 3.1.10 2019-01-08 18:22:48 +01:00
f7abc175aa fix(core): update 2019-01-08 18:22:48 +01:00
bbcb3a614e 3.1.9 2019-01-08 14:37:17 +01:00
941d2f0902 fix(core): update 2019-01-08 14:37:17 +01:00
5c78f83a28 3.1.8 2019-01-08 13:52:09 +01:00
124f117352 fix(core): update 2019-01-08 13:52:08 +01:00
f67da898ae 3.1.7 2019-01-08 12:39:00 +01:00
3c8f70f77e fix(core): update 2019-01-08 12:38:59 +01:00
3674d7d9a5 3.1.6 2019-01-08 00:09:43 +01:00
fe2a622488 3.1.5 2019-01-07 02:50:10 +01:00
f092eefbf3 fix(core): update 2019-01-07 02:50:09 +01:00
8d0aa361f9 3.1.4 2019-01-07 02:41:38 +01:00
692a1223a8 fix(core): update 2019-01-07 02:41:38 +01:00
ae7d101ab9 3.1.3 2019-01-07 02:38:30 +01:00
3825b15a65 fix(core): update 2019-01-07 02:38:30 +01:00
3fc41678d2 3.1.2 2018-07-10 21:45:26 +02:00
39f1b7ada1 fix(test): fix import 2018-07-10 21:45:26 +02:00
f763de2403 3.1.1 2018-07-10 21:33:49 +02:00
cba1d031b6 fix(ci): fix tools install 2018-07-10 21:33:49 +02:00
d31e6a5931 3.1.0 2018-07-10 21:27:17 +02:00
46514a2743 feat(SmartdataDoc): add custom unique indexes 2018-07-10 21:27:16 +02:00
1cf02157c4 3.0.5 2018-07-10 00:19:23 +02:00
72efa14da8 fix(test): update npmts 2018-07-10 00:19:22 +02:00
a73c2084c0 3.0.4 2018-07-10 00:17:17 +02:00
5ed557a21a fix(test): test now throws correctly 2018-07-10 00:17:16 +02:00
2b6c30ff55 3.0.3 2018-07-10 00:02:39 +02:00
12ef599333 3.0.2 2018-07-10 00:02:10 +02:00
191ea5d3c6 update to mongodb 2018-07-10 00:02:04 +02:00
bdf33ed1ca 3.0.1 2018-07-08 23:49:05 +02:00
1c76905dcd fix(structure): clean 2018-07-08 23:49:05 +02:00
4d88cea69d 3.0.0 2018-07-08 23:48:15 +02:00
8b4f7169ff BREAKING CHANGE(scope/db driver): switched to pushrocks scope and from rethinkdb to mongodb as db 2018-07-08 23:48:14 +02:00
2a1c45608f 2.0.7 2018-01-16 00:40:12 +01:00
85a6444263 feat(IConnectionOptions): export ConnectionOptions 2018-01-16 00:40:08 +01:00
766ae1d1ff 2.0.6 2018-01-14 18:07:35 +01:00
7630882312 docs(README): update 2018-01-14 18:07:29 +01:00
4aec47f207 2.0.5 2018-01-14 18:04:00 +01:00
c2e3a1ae6e docs(README): update 2018-01-14 18:03:57 +01:00
3d8f8646b1 2.0.4 2018-01-14 17:58:35 +01:00
aca9817c56 docs(README): update 2018-01-14 17:57:57 +01:00
7e341f2b50 2.0.3 2018-01-14 17:32:07 +01:00
d2ca108ef8 feat(core): now retrieves classes properly 2018-01-14 17:32:04 +01:00
e2d12f8c9c 2.0.2 2018-01-12 01:36:12 +01:00
cfcd9ab386 fix(CI): npmts now installing correctly during CI 2018-01-12 01:36:08 +01:00
3048035374 2.0.1 2018-01-12 01:34:00 +01:00
6c70cf05c4 update ci 2018-01-12 01:33:54 +01:00
04b0910883 2.0.0 2018-01-12 01:23:02 +01:00
3671fe4df4 feat(add RethinkDB as main driver and revert to docs in README): 2018-01-12 01:22:58 +01:00
bd30da1c4a fix(core): remove old code for outdated objectstorage 2018-01-07 18:15:14 +01:00
05938bf2af feat(ci): add commitizen for more consistent commit messages 2018-01-07 18:10:16 +01:00
cddb0caf1f feat(ci): add commitizen for more consistent commit messages 2018-01-07 18:08:42 +01:00
1af51dd989 update rethink integration 2018-01-07 17:58:30 +01:00
8101e49026 update deps and docs 2018-01-07 17:43:02 +01:00
2d97ab9dc5 prepare v2 of smartdata 2018-01-07 17:26:34 +01:00
3ba2bc8446 add rethink 2018-01-07 14:45:43 +01:00
5735ab8577 1.0.28 2017-11-16 14:35:30 +01:00
def671cbe4 update 2017-11-16 14:23:06 +01:00
14042151ba update tests 2017-09-13 13:47:38 +02:00
c74873d02c 1.0.27 2017-07-16 00:11:06 +02:00
800cdd655a fix rxjs dependency 2017-07-16 00:11:03 +02:00
68c0ceeb14 update 2017-07-16 00:09:54 +02:00
154dc5c1b3 Merge branch '3-plugins-are-not-exported' 2017-06-24 09:57:29 +02:00
d5c027caf0 fix import 2017-06-24 09:57:11 +02:00
30776a7da0 1.0.26 2017-06-23 16:42:08 +02:00
fedc0bd8c8 fix import 2017-06-23 16:42:03 +02:00
7b78b47a1b 1.0.25 2017-06-23 16:38:11 +02:00
a4acfc0f6e 1.0.24 2017-06-23 11:40:26 +02:00
a934f3608f remove NeDB and update to use MongoDB Atlas for testing 2017-06-23 11:40:20 +02:00
a4f3f23bed update npmextra 2017-06-18 19:53:29 +02:00
2039f1c807 update ci 2017-06-18 19:52:54 +02:00
57d1a6dd0a added npmdocker for local development 2017-02-25 11:37:05 +01:00
d504e90e47 1.0.22 2016-11-18 13:56:18 +01:00
7079340657 refactor @saveable to @svDb() 2016-11-18 13:56:15 +01:00
63ceded1b8 1.0.21 2016-11-18 13:20:47 +01:00
b45e7ee206 fix mongodb startup 2016-11-18 13:20:43 +01:00
715709f3ec 1.0.20 2016-11-18 01:00:06 +01:00
0b8adea736 improve README 2016-11-18 00:59:57 +01:00
90d9a25b3f 1.0.19 2016-11-18 00:42:29 +01:00
e49811eecd now allows adding a saveable decorator 2016-11-18 00:42:25 +01:00
9cbdf317dc 1.0.18 2016-11-17 22:41:05 +01:00
d55339013a improve README 2016-11-17 22:41:01 +01:00
9acdbd2842 1.0.17 2016-11-17 22:36:16 +01:00
dfce8cfcc0 add NeDB support 2016-11-17 22:36:12 +01:00
38446fc79b 1.0.16 2016-11-17 12:20:56 +01:00
af8c41ad6c added nedb to the mix 2016-11-17 12:20:52 +01:00
3a24f829b4 improve README 2016-09-14 01:03:25 +02:00
67db1325c1 1.0.15 2016-09-14 01:02:23 +02:00
6683c05c22 added Decorator support for easy connection between classes and collections 2016-09-14 01:02:11 +02:00
f7f7852b7f 1.0.14 2016-09-13 22:53:27 +02:00
df4346e0a2 implenting dbDoc 2016-09-13 22:53:21 +02:00
eb54fbcd0d improve README 2016-09-13 10:38:00 +02:00
f13c12cd47 improve README 2016-09-13 10:35:51 +02:00
08d53f22f5 improve README 2016-09-13 10:31:14 +02:00
5b6523e6f4 improve README 2016-09-13 10:26:17 +02:00
138290a7b8 1.0.13 2016-09-13 10:23:49 +02:00
036cafc282 improve README 2016-09-13 10:23:46 +02:00
7764ba5cb8 1.0.12 2016-09-13 10:17:46 +02:00
7f77634ea1 imrpove README 2016-09-13 10:17:34 +02:00
acf3c29939 1.0.11 2016-09-13 00:14:54 +02:00
925cd639b4 imrpove README 2016-09-13 00:14:50 +02:00
af8de58dcd improve README 2016-09-13 00:13:00 +02:00
f39703b8d9 1.0.10 2016-09-13 00:04:20 +02:00
fa1951b4dd imrprove README 2016-09-13 00:04:07 +02:00
8c37a367a0 1.0.9 2016-09-12 23:50:31 +02:00
37f388e998 fix tests 2016-09-12 23:50:25 +02:00
78bdb6760e imrove README 2016-09-12 23:48:58 +02:00
35 changed files with 6420 additions and 522 deletions

21
.gitignore vendored
View File

@ -1,5 +1,20 @@
node_modules/
test/data
pages/
.nogit/
# artifacts
coverage/
public/
pages/
# installs
node_modules/
# caches
.yarn/
.cache/
.rpt2_cache
# builds
dist/
dist_*/
# custom

View File

@ -1,43 +1,127 @@
image: hosttoday/ht-docker-node:npmts
# gitzone ci_default
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
cache:
paths:
- .npmci_cache/
key: '$CI_BUILD_STAGE'
stages:
- test
- release
- security
- test
- release
- metadata
before_script:
- 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" | tee /etc/apt/sources.list.d/mongodb-org-3.2.list
- apt-get update
- apt-get install -y mongodb-org
# ====================
# security stage
# ====================
mirror:
stage: security
script:
- npmci git mirror
tags:
- lossless
- docker
- notpriv
testLEGACY:
audit:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- npmci command npm install --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high
tags:
- lossless
- docker
- notpriv
# ====================
# test stage
# ====================
testStable:
stage: test
script:
- npmci test legacy
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- lossless
- docker
allow_failure: true
- priv
testLTS:
testBuild:
stage: test
script:
- npmci test lts
tags:
- docker
testSTABLE:
stage: test
script:
- npmci test stable
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- lossless
- docker
- notpriv
release:
stage: release
environment: npm_registry
script:
- npmci publish
- npmci node install stable
- npmci npm publish
only:
- tags
tags:
- docker
- lossless
- docker
- notpriv
# ====================
# metadata stage
# ====================
codequality:
stage: metadata
allow_failure: true
script:
- npmci command npm install -g tslint typescript
- npmci npm prepare
- npmci npm install
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
tags:
- lossless
- docker
- priv
trigger:
stage: metadata
script:
- npmci trigger
only:
- tags
tags:
- lossless
- docker
- notpriv
pages:
stage: metadata
script:
- npmci node install lts
- npmci command npm install -g @gitzone/tsdoc
- npmci npm prepare
- npmci npm install
- npmci command tsdoc
tags:
- lossless
- docker
- notpriv
only:
- tags
artifacts:
expire_in: 1 week
paths:
- public
allow_failure: true

29
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,29 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "current file",
"type": "node",
"request": "launch",
"args": [
"${relativeFile}"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": "test.ts",
"type": "node",
"request": "launch",
"args": [
"test/test.ts"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
}
]
}

26
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,26 @@
{
"json.schemas": [
{
"fileMatch": ["/npmextra.json"],
"schema": {
"type": "object",
"properties": {
"npmci": {
"type": "object",
"description": "settings for npmci"
},
"gitzone": {
"type": "object",
"description": "settings for gitzone",
"properties": {
"projectType": {
"type": "string",
"enum": ["website", "element", "service", "npm"]
}
}
}
}
}
}
]
}

View File

@ -1,63 +0,0 @@
# smartdata
smartdata is a ODM that adheres to TypeScript practices and uses classes to organize data.
It uses MongoDB as persistent storage.
## Intention
There are many ODMs out there, however when we searched for a ODM that uses TypeScript,
acts smart while still embracing an easy the NoSQL idea we didn't find a matching solution.
This is why we started smartdata
How MongoDB terms map to smartdata classes
MongoDB term | smartdata class
--- | ---
Database | smartdata.Db
Collection | smartdata.DbCollection
Document | smartdata.DbDoc
### class Db
represents a Database. Naturally it has .connect() etc. methods on it.
Since it is a class you can have multiple DBs defined.
```TypeScript
import * as smartdata from 'smartdata'
let myDb1 = new smartdata.Db('someConnectionUrl')
let myDb2 = new smartdata.Db('someConnectionUrl')
myDb1.connect()
myDb2.connect()
```
### class Collection
represents a collection of objects.
A collection is defined by the object class (that is extending smartdata.dbdoc) it respresents
So to get to get access to a specific collection you document
```
class myObject extends DbDoc {
property1:string
property2:number
constructor(optionsArg:{
queryArg?:any,
dataArg?:{
property1:string,
property2:string
}
}) {
super(this,optionsArg)
}
}
let myCollection = myDb1.getCollection(myObject)
```
> Alert: You NEVER instantiate a collection.
This is done for you!!!
### class DbDoc
represents a individual document in a collection.
[![npm](https://push.rocks/assets/repo-header.svg)](https://push.rocks)

2
dist/index.d.ts vendored
View File

@ -1,2 +0,0 @@
export * from './smartdata.classes.dbcollection';
export * from './smartdata.classes.dbconnection';

7
dist/index.js vendored
View File

@ -1,7 +0,0 @@
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
__export(require('./smartdata.classes.dbcollection'));
__export(require('./smartdata.classes.dbconnection'));
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7O0FBRUEsaUJBQWMsa0NBQ2QsQ0FBQyxFQUQrQztBQUNoRCxpQkFBYyxrQ0FDZCxDQUFDLEVBRCtDIn0=

View File

@ -1,24 +0,0 @@
/// <reference types="q" />
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(funcArg: any): void;
/**
* finds an object in the DbCollection
*/
find(docMatchArg: T | any): plugins.q.Promise<T[]>;
/**
* inserts object into the DbCollection
*/
insertOne(docArg: T): plugins.q.Promise<void>;
/**
* inserts many objects at once into the DbCollection
*/
insertMany(docArrayArg: T[]): plugins.q.Promise<void>;
private checkDoc(doc);
}

View File

@ -1,57 +0,0 @@
"use strict";
const plugins = require('./smartdata.plugins');
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(funcArg) { }
/**
* finds an object in the DbCollection
*/
find(docMatchArg) {
let done = plugins.q.defer();
this.collection.find(docMatchArg).toArray((err, docs) => {
if (err) {
throw err;
}
done.resolve(docs);
});
return done.promise;
}
/**
* inserts object into the DbCollection
*/
insertOne(docArg) {
let done = plugins.q.defer();
this.checkDoc(docArg).then(() => {
this.collection.insertOne(docArg)
.then(() => { done.resolve(); });
});
return done.promise;
}
/**
* inserts many objects at once into the DbCollection
*/
insertMany(docArrayArg) {
let done = plugins.q.defer();
let checkDocPromiseArray = [];
for (let docArg of docArrayArg) {
checkDocPromiseArray.push(this.checkDoc(docArg));
}
plugins.q.all(checkDocPromiseArray).then(() => {
this.collection.insertMany(docArrayArg)
.then(() => { done.resolve(); });
});
return done.promise;
}
checkDoc(doc) {
let done = plugins.q.defer();
done.resolve();
return done.promise;
}
}
exports.DbCollection = DbCollection;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRkYXRhLmNsYXNzZXMuZGJjb2xsZWN0aW9uLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRkYXRhLmNsYXNzZXMuZGJjb2xsZWN0aW9uLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxNQUFZLE9BQU8sV0FBTSxxQkFDekIsQ0FBQyxDQUQ2QztBQUc5QztJQUVJLFlBQVksT0FBZSxFQUFFLGVBQTZCO1FBQ3RELElBQUksQ0FBQyxVQUFVLEdBQUcsZUFBZSxDQUFDLEVBQUUsQ0FBQyxVQUFVLENBQUMsT0FBTyxDQUFDLENBQUE7SUFDNUQsQ0FBQztJQUVEOztPQUVHO0lBQ0gsbUJBQW1CLENBQUMsT0FBTyxJQUFJLENBQUM7SUFFaEM7O09BRUc7SUFDSCxJQUFJLENBQUMsV0FBb0I7UUFDckIsSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQU8sQ0FBQTtRQUNqQyxJQUFJLENBQUMsVUFBVSxDQUFDLElBQUksQ0FBQyxXQUFXLENBQUMsQ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3BELENBQUM7UUFDRCxPQUFPLENBQUMsQ0FBQyxDQUFDLEdBQUcsQ0FBQyxvQkFBb0IsQ0FBQyxDQUFDLElBQUksQ0FBQztZQUNyQyxJQUFJLENBQUMsVUFBVSxDQUFDLFVBQVUsQ0FBQyxXQUFXLENBQUM7aUJBQ2xDLElBQUksQ0FBQyxRQUFRLElBQUksQ0FBQyxPQUFPLEVBQUUsQ0FBQSxDQUFDLENBQUMsQ0FBQyxDQUFBO1FBQ3ZDLENBQUMsQ0FBQyxDQUFBO1FBQ0YsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUE7SUFDdkIsQ0FBQztJQUVPLFFBQVEsQ0FBQyxHQUFNO1FBQ25CLElBQUksSUFBSSxHQUFHLE9BQU8sQ0FBQyxDQUFDLENBQUMsS0FBSyxFQUFRLENBQUE7UUFDbEMsSUFBSSxDQUFDLE9BQU8sRUFBRSxDQUFBO1FBQ2QsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUE7SUFDdkIsQ0FBQztBQUNMLENBQUM7QUF4RFksb0JBQVksZUF3RHhCLENBQUEifQ==

View File

@ -1,11 +0,0 @@
/// <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>;
}

View File

@ -1,29 +0,0 @@
"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

@ -1,5 +0,0 @@
import 'typings-global';
export import assert = require('assert');
export import beautylog = require('beautylog');
export import mongodb = require('mongodb');
export import q = require('q');

View File

@ -1,7 +0,0 @@
"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

View File

@ -1,19 +0,0 @@
# smartdata
smartdata is a ODM that adheres to TypeScript practices and uses classes to organize data.
It uses MongoDB as persistent storage.
## Intention
There are many ODMs out there, however when we searched for a ODM that uses TypeScript,
acts smart while still embracing an easy the NoSQL idea we didn't find a matching solution.
This is why we started smartdata
How MongoDB terms map to smartdata classes
MongoDB term | smartdata class
--- | ---
Database | smartdata.DbConnection
Collection | smartdata.DbCollection
Document | smartdata.DbDoc
[![npm](https://push.rocks/assets/repo-header.svg)](https://push.rocks)

23
npmextra.json Normal file
View File

@ -0,0 +1,23 @@
{
"npmdocker": {
"baseImage": "hosttoday/ht-docker-node:mongo",
"command": "npmci test stable",
"dockerSock": false
},
"npmci": {
"npmGlobalTools": [],
"npmAccessLevel": "public",
"npmRegistryUrl": "registry.npmjs.org"
},
"gitzone": {
"projectType": "npm",
"module": {
"githost": "gitlab.com",
"gitscope": "pushrocks",
"gitrepo": "smartdata",
"shortDescription": "do more with data",
"npmPackagename": "@pushrocks/smartdata",
"license": "MIT"
}
}
}

5405
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +1,14 @@
{
"name": "smartdata",
"version": "1.0.8",
"name": "@pushrocks/smartdata",
"version": "3.1.29",
"private": false,
"description": "do more with data",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"scripts": {
"test": "(npm run prepareMongo && npmts)",
"prepareMongo": "(rm -rf ./test/data && mkdir ./test/data/)"
"test": "(tstest test/)",
"testLocal": "(npmdocker)",
"build": "(tsbuild --web)"
},
"repository": {
"type": "git",
@ -19,19 +21,39 @@
},
"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"
"@pushrocks/lik": "^4.0.13",
"@pushrocks/smartlog": "^2.0.35",
"@pushrocks/smartpromise": "^3.0.6",
"@pushrocks/smartstring": "^3.0.18",
"@pushrocks/smartunique": "^3.0.3",
"@types/lodash": "^4.14.155",
"@types/mongodb": "^3.5.20",
"lodash": "^4.17.15",
"mongodb": "^3.5.8",
"runtime-type-checks": "0.0.4"
},
"devDependencies": {
"@types/shelljs": "^0.3.30",
"@types/should": "^8.1.29",
"shelljs": "^0.7.4",
"should": "^11.1.0",
"smartstring": "^2.0.17",
"typings-test": "^1.0.3"
}
"@gitzone/tsbuild": "^2.1.24",
"@gitzone/tstest": "^1.0.33",
"@pushrocks/qenv": "^4.0.10",
"@pushrocks/tapbundle": "^3.2.1",
"@types/mongodb-memory-server": "^2.3.0",
"@types/node": "^14.0.13",
"@types/shortid": "0.0.29",
"mongodb-memory-server": "^6.6.1",
"tslint": "^6.1.2",
"tslint-config-prettier": "^1.18.0"
},
"files": [
"ts/**/*",
"ts_web/**/*",
"dist/**/*",
"dist_*/**/*",
"dist_ts/**/*",
"dist_ts_web/**/*",
"assets/**/*",
"cli.js",
"npmextra.json",
"readme.md"
]
}

4
qenv.yml Normal file
View File

@ -0,0 +1,4 @@
required:
- MONGO_URL
- MONGO_DBNAME
- MONGO_PASS

147
readme.md Normal file
View File

@ -0,0 +1,147 @@
# @pushrocks/smartdata
do more with data
## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartdata)
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartdata)
* [github.com (source mirror)](https://github.com/pushrocks/smartdata)
* [docs (typedoc)](https://pushrocks.gitlab.io/smartdata/)
## Status for master
Status Category | Status Badge
-- | --
GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/smartdata/badges/master/pipeline.svg)](https://lossless.cloud)
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/smartdata/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/smartdata)](https://lossless.cloud)
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/smartdata)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@pushrocks/smartdata)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/smartdata)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/smartdata)](https://lossless.cloud)
Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](https://lossless.cloud)
## Usage
Use TypeScript for best in class instellisense.
smartdata is an ODM that adheres to TypeScript practices and uses classes to organize data.
It uses RethinkDB as persistent storage.
## Intention
There are many ODMs out there, however when we searched for an ODM that uses TypeScript,
acts smart while still embracing the NoSQL idea we didn't find a matching solution.
This is why we started smartdata.
How RethinkDB's terms map to the ones of smartdata:
| MongoDb term | smartdata class |
| ------------ | ----------------------------- |
| Database | smartdata.SmartdataDb |
| Collection | smartdata.SmartdataCollection |
| Document | smartdata.SmartadataDoc |
### class Db
represents a Database. Naturally it has .connect() etc. methods on it.
```typescript
import * as smartdata from 'smartdata';
const smartdataDb = new smartdata.SmartdataDb({
mongoDbUrl: '//someurl',
mongoDbName: 'myDatabase',
mongoDbPass: 'mypassword'
});
smartdataDb.connect();
```
### class DbCollection
represents a collection of objects.
A collection is defined by the object class (that is extending smartdata.dbdoc) it respresents
So to get to get access to a specific collection you document
```typescript
// continues from the block before...
@smartdata.Collection(smartdataDb)
class MyObject extends smartdata.DbDoc<MyObject> {
// read the next block about DbDoc
@smartdata.svDb()
property1: string; // @smartdata.svDb() marks the property for db save
property2: number; // this one is not marked, so it won't be save upon calling this.save()
constructor() {
super(); // the super call is important ;) But you probably know that.
}
}
// start to instantiate instances of classes from scratch or database
const localObject = new MyObject({
property1: 'hi',
property2: 2
});
localObject.save(); // saves the object to the database
// start retrieving instances
MyObject.getInstance<MyObject>({
property: 'hi'
}); // outputs a new instance of MyObject with the values from db assigned
```
### class DbDoc
represents a individual document in a collection
and thereby is ideally suited to extend the class you want to actually store.
### CRUD operations
smartdata supports full CRUD operations
**Store** or **Update** instances of classes to MongoDB:
DbDoc extends your class with the following methods:
- async `.save()` will save (or update) the object you call it on only. Any referenced non-savable objects will not get stored.
- async `.saveDeep()` does the same like `.save()`.
In addition it will look for properties that reference an object
that extends DbDoc as well and call .saveDeep() on them as well.
Loops are prevented
**Get** a new class instance from MongoDB:
DbDoc exposes a static method that allows you specify a filter to retrieve a cloned class of the one you used to that doc at some point later in time:
- static async `.getInstance({ /* filter props here */ })` gets you an instance that has the data of the first matched document as properties.
- static async `getInstances({ /* filter props here */ })` get you an array instances (one instance for every matched document).
**Delete** instances from MongoDb:
smartdata extends your class with a method to easily delete the doucment from DB:
- async `.delete()`will delete the document from DB.
## TypeScript
How does TypeScript play into this?
Since you define your classes in TypeScript and types flow through smartdata in a generic way
you should get all the Intellisense and type checking you love when using smartdata.
smartdata itself also bundles typings. You don't need to install any additional types for smartdata.
## Contribution
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
For further information read the linked docs at the top of this readme.
> MIT licensed | **&copy;** [Lossless GmbH](https://lossless.gmbh)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)

1
test/test.d.ts vendored
View File

@ -1 +0,0 @@
import 'typings-test';

View File

@ -1,74 +0,0 @@
"use strict";
require('typings-test');
const shelljs = require('shelljs');
const should = require('should');
const smartstring = require('smartstring');
// the tested module
const smartdata = require('../dist/index');
let mongoChildProcess;
let testDbConnection;
let testDbCollection;
describe('mongodb', function () {
it('should start mongodb', function (done) {
this.timeout(30000);
mongoChildProcess = shelljs.exec('mongod --dbpath=./test/data --port 27017', { async: true, silent: true });
let doneCalled = false;
mongoChildProcess.stdout.on('data', function (data) {
console.log(smartstring.indent.indentWithPrefix(data, "*** MongoDB Process *** : "));
if (!doneCalled) {
if (/waiting for connections on port 27017/.test(data)) {
doneCalled = true;
done();
}
}
});
});
});
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 () {
testDbCollection = new smartdata.DbCollection('something', testDbConnection);
});
it('should insert a doc into the collection', function (done) {
testDbCollection.insertOne({ value1: 'test' }).then(() => { done(); });
});
it('should find all docs of testDbCollection', function (done) {
testDbCollection.find({}).then((resultArray) => {
console.log(resultArray);
should(resultArray[0].value1).equal('test');
done();
});
});
it('should insert many docs into the collection', function (done) {
testDbCollection.insertMany([
{ value1: 'test2' },
{ value1: 'test', value2: 3, value3: 'hi' }
]).then(() => { done(); });
});
it('should find a specified doc', function (done) {
testDbCollection.find({ 'value3': { '$exists': true } }).then((resultArray) => {
console.log(resultArray);
should(resultArray[0].value3).equal('hi');
done();
}).catch(console.log);
});
it('should close the db Connection', function () {
testDbConnection.close();
});
});
describe('mongodb', function () {
it('should kill mongodb', function (done) {
this.timeout(30000);
mongoChildProcess.stdout.on('data', function (data) {
if (/dbexit: rc: 0/.test(data)) {
done();
}
});
shelljs.exec('mongod --dbpath=./test/data --shutdown');
mongoChildProcess.kill('SIGTERM');
});
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyI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QUMsR0FBRyxDQUFDLENBQUE7SUFDekIsQ0FBQyxDQUFDLENBQUE7SUFDRixFQUFFLENBQUMsZ0NBQWdDLEVBQUU7UUFDakMsZ0JBQWdCLENBQUMsS0FBSyxFQUFFLENBQUE7SUFDNUIsQ0FBQyxDQUFDLENBQUE7QUFDTixDQUFDLENBQUMsQ0FBQTtBQUVGLFFBQVEsQ0FBQyxTQUFTLEVBQUU7SUFDaEIsRUFBRSxDQUFDLHFCQUFxQixFQUFFLFVBQVUsSUFBSTtRQUNwQyxJQUFJLENBQUMsT0FBTyxDQUFDLEtBQUssQ0FBQyxDQUFBO1FBQ25CLGlCQUFpQixDQUFDLE1BQU0sQ0FBQyxFQUFFLENBQUMsTUFBTSxFQUFFLFVBQVUsSUFBSTtZQUM5QyxFQUFFLENBQUMsQ0FBQyxnQkFBZ0IsQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLENBQUMsQ0FBQyxDQUFDO2dCQUM5QixJQUFJLEVBQUUsQ0FBQTtZQUNWLENBQUM7UUFDTCxDQUFDLENBQUMsQ0FBQTtRQUNGLE9BQU8sQ0FBQyxJQUFJLENBQUMsd0NBQXdDLENBQUMsQ0FBQTtRQUN0RCxpQkFBaUIsQ0FBQyxJQUFJLENBQUMsU0FBUyxDQUFDLENBQUE7SUFDckMsQ0FBQyxDQUFDLENBQUE7QUFDTixDQUFDLENBQUMsQ0FBQSJ9

View File

@ -1,93 +1,143 @@
import 'typings-test'
import { tap, expect } from '@pushrocks/tapbundle';
import { Qenv } from '@pushrocks/qenv';
import * as shelljs from 'shelljs'
import * as should from 'should'
import * as smartstring from 'smartstring'
const testQenv = new Qenv(process.cwd(), process.cwd() + '/.nogit/');
// the tested module
import * as smartdata from '../dist/index'
import * as smartdata from '../ts/index';
import { smartstring } from '../ts/smartdata.plugins';
import * as smartunique from '@pushrocks/smartunique';
let mongoChildProcess
let testDbConnection: smartdata.DbConnection
import * as mongoPlugin from 'mongodb-memory-server';
interface ITestObject1 {
value1: string
value2?: number
value3?: string
// =======================================
// Connecting to the database server
// =======================================
let testDb: smartdata.SmartdataDb;
let smartdataOptions: smartdata.ISmartdataOptions;
let mongod: mongoPlugin.MongoMemoryServer;
tap.test('should create a testinstance as database', async () => {
mongod = new mongoPlugin.MongoMemoryServer();
smartdataOptions = {
mongoDbName: await mongod.getDbName(),
mongoDbPass: '',
mongoDbUrl: await mongod.getConnectionString()
};
console.log(smartdataOptions);
testDb = new smartdata.SmartdataDb(smartdataOptions);
});
tap.test('should establish a connection to the rethink Db cluster', async () => {
await testDb.init();
});
// =======================================
// The actual tests
// =======================================
// ------
// Collections
// ------
@smartdata.Collection(() => {
return testDb;
})
class Car extends smartdata.SmartDataDbDoc<Car, Car> {
@smartdata.unI()
public index: string = smartunique.shortId();
@smartdata.svDb()
public color: string;
@smartdata.svDb()
public brand: string;
constructor(colorArg: string, brandArg: string) {
super();
this.color = colorArg;
this.brand = brandArg;
}
}
let testDbCollection: smartdata.DbCollection<ITestObject1>
tap.test('should save the car to the db', async () => {
const myCar = new Car('red', 'Volvo');
await myCar.save();
class testCar {
color: string
constructor(colorArg:string) {
this.color = colorArg
}
const myCar2 = new Car('red', 'Volvo');
await myCar2.save();
const myCar3 = new Car('red', 'Renault');
await myCar3.save();
});
tap.test('expect to get instance of Car', async () => {
const myCars = await Car.getInstances<Car>({
brand: 'Volvo'
});
expect(myCars[0].color).to.equal('red');
});
tap.test('expect to get instance of Car and update it', async () => {
const myCar = await Car.getInstance<Car>({
brand: 'Volvo'
});
expect(myCar.color).to.equal('red');
myCar.color = 'blue';
await myCar.save();
});
tap.test('should be able to delete an instance of car', async () => {
const myCar = await Car.getInstance<Car>({
brand: 'Volvo'
});
expect(myCar.color).to.equal('blue');
await myCar.delete();
const myCar2 = await Car.getInstance<Car>({
brand: 'Volvo'
});
expect(myCar2.color).to.equal('red');
});
// tslint:disable-next-line: max-classes-per-file
@smartdata.Collection(() => {
return testDb;
})
class Truck extends smartdata.SmartDataDbDoc<Car, Car> {
@smartdata.unI()
public id: string = smartunique.shortId();
@smartdata.svDb()
public color: string;
@smartdata.svDb()
public brand: string;
constructor(colorArg: string, brandArg: string) {
super();
this.color = colorArg;
this.brand = brandArg;
}
}
tap.test('should store a new Truck', async () => {
const truck = new Truck('blue', 'MAN');
await truck.save();
const myTruck = await Truck.getInstance<Truck>({ color: 'blue' });
myTruck.id = 'foo';
await myTruck.save();
const myTruck2 = await Truck.getInstance<Truck>({ color: 'blue' });
console.log(myTruck2);
});
describe('mongodb', function () {
it('should start mongodb', function (done) {
this.timeout(30000)
mongoChildProcess = shelljs.exec('mongod --dbpath=./test/data --port 27017', { async: true, silent: true })
let doneCalled = false
mongoChildProcess.stdout.on('data', function (data) {
console.log(smartstring.indent.indentWithPrefix(data, "*** MongoDB Process *** : "))
if (!doneCalled) {
if (/waiting for connections on port 27017/.test(data)) {
doneCalled = true
done()
}
}
})
})
})
// =======================================
// close the database connection
// =======================================
tap.test('should close the database connection', async tools => {
await testDb.close();
await mongod.stop();
});
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 () {
testDbCollection = new smartdata.DbCollection<ITestObject1>('something', testDbConnection)
})
it('should insert a doc into the collection', function (done) {
testDbCollection.insertOne({ value1: 'test' }).then(() => { done() })
})
it('should find all docs of testDbCollection', function (done) {
testDbCollection.find({}).then((resultArray) => {
console.log(resultArray)
should(resultArray[0].value1).equal('test')
done()
})
})
it('should insert many docs into the collection', function (done) {
testDbCollection.insertMany([
{ value1: 'test2' },
{ value1: 'test', value2: 3, value3: 'hi' }
]).then(() => { done() })
})
it('should find a specified doc', function (done) {
testDbCollection.find({'value3': {'$exists': true}}).then((resultArray) => {
console.log(resultArray)
should(resultArray[0].value3).equal('hi')
done()
}).catch(console.log)
})
it('should close the db Connection', function () {
testDbConnection.close()
})
})
describe('mongodb', function () {
it('should kill mongodb', function (done) {
this.timeout(30000)
mongoChildProcess.stdout.on('data', function (data) {
if (/dbexit: rc: 0/.test(data)) {
done()
}
})
shelljs.exec('mongod --dbpath=./test/data --shutdown')
mongoChildProcess.kill('SIGTERM')
})
})
tap.start({ throwOnError: true });

View File

@ -1,4 +1,5 @@
import * as plugins from './smartdata.plugins'
export * from './smartdata.classes.db';
export * from './smartdata.classes.collection';
export * from './smartdata.classes.doc';
export * from './smartdata.classes.dbcollection'
export * from './smartdata.classes.db'
export { IMongoDescriptor } from './interfaces';

1
ts/interfaces/index.ts Normal file
View File

@ -0,0 +1 @@
export * from './mongodescriptor';

View File

@ -0,0 +1,5 @@
export interface IMongoDescriptor {
mongoDbName: string;
mongoDbUrl: string;
mongoDbPass: string;
}

View File

@ -0,0 +1,163 @@
import * as plugins from './smartdata.plugins';
import { SmartdataDb } from './smartdata.classes.db';
import { SmartDataDbDoc } from './smartdata.classes.doc';
export interface IFindOptions {
limit?: number;
}
/**
*
*/
export interface IDocValidationFunc<T> {
(doc: T): boolean;
}
export type TDelayedDbCreation = () => SmartdataDb;
/**
* This is a decorator that will tell the decorated class what dbTable to use
* @param dbArg
*/
export function Collection(dbArg: SmartdataDb | TDelayedDbCreation) {
return function(constructor) {
if (dbArg instanceof SmartdataDb) {
// tslint:disable-next-line: no-string-literal
constructor['smartdataCollection'] = new SmartdataCollection(constructor, dbArg);
} else {
constructor['smartdataDelayedCollection'] = () => {
return new SmartdataCollection(constructor, dbArg());
};
}
};
}
export class SmartdataCollection<T> {
/**
* the collection that is used
*/
public mongoDbCollection: plugins.mongodb.Collection;
public objectValidation: IDocValidationFunc<T> = null;
public collectionName: string;
public smartdataDb: SmartdataDb;
public uniqueIndexes: string[] = [];
constructor(collectedClassArg: T & SmartDataDbDoc<T, unknown>, smartDataDbArg: SmartdataDb) {
// tell the collection where it belongs
this.collectionName = collectedClassArg.name;
this.smartdataDb = smartDataDbArg;
// tell the db class about it (important since Db uses different systems under the hood)
this.smartdataDb.addTable(this);
}
/**
* makes sure a collection exists within MongoDb that maps to the SmartdataCollection
*/
public async init() {
if (!this.mongoDbCollection) {
// connect this instance to a MongoDB collection
const availableMongoDbCollections = await this.smartdataDb.mongoDb.collections();
const wantedCollection = availableMongoDbCollections.find(collection => {
return collection.collectionName === this.collectionName;
});
if (!wantedCollection) {
await this.smartdataDb.mongoDb.createCollection(this.collectionName);
}
this.mongoDbCollection = await this.smartdataDb.mongoDb.collection(this.collectionName);
// console.log(`Successfully initiated Collection ${this.collectionName}`);
}
}
/**
* mark unique index
*/
public markUniqueIndexes(keyArrayArg: string[] = []) {
for (const key of keyArrayArg) {
if (!this.uniqueIndexes.includes(key)) {
this.mongoDbCollection.createIndex(key, {
unique: true
});
// make sure we only call this once and not for every doc we create
this.uniqueIndexes.push(key);
}
}
}
/**
* adds a validation function that all newly inserted and updated objects have to pass
*/
public addDocValidation(funcArg: IDocValidationFunc<T>) {
this.objectValidation = funcArg;
}
/**
* finds an object in the DbCollection
*/
public async find(filterObject: any): Promise<any> {
await this.init();
const result = await this.mongoDbCollection.find(filterObject).toArray();
return result;
}
/**
* create an object in the database
*/
public async insert(dbDocArg: T & SmartDataDbDoc<T, unknown>): Promise<any> {
await this.init();
await this.checkDoc(dbDocArg);
this.markUniqueIndexes(dbDocArg.uniqueIndexes);
const saveableObject = await dbDocArg.createSavableObject();
const result = await this.mongoDbCollection.insertOne(saveableObject);
return result;
}
/**
* inserts object into the DbCollection
*/
public async update(dbDocArg: T & SmartDataDbDoc<T, unknown>): Promise<any> {
await this.init();
await this.checkDoc(dbDocArg);
const identifiableObject = await dbDocArg.createIdentifiableObject();
const saveableObject = await dbDocArg.createSavableObject();
const updateableObject: any = {};
for (const key of Object.keys(saveableObject)) {
if (identifiableObject[key]) {
continue;
}
updateableObject[key] = saveableObject[key];
}
this.mongoDbCollection.updateOne(
identifiableObject,
{ $set: updateableObject },
{ upsert: true }
);
}
public async delete(dbDocArg: T & SmartDataDbDoc<T, unknown>): Promise<any> {
await this.init();
await this.checkDoc(dbDocArg);
const identifiableObject = await dbDocArg.createIdentifiableObject();
await this.mongoDbCollection.deleteOne(identifiableObject, {
w: 1
});
}
/**
* checks a Doc for constraints
* if this.objectValidation is not set it passes.
*/
private checkDoc(docArg: T): Promise<void> {
const done = plugins.smartq.defer<void>();
let validationResult = true;
if (this.objectValidation) {
validationResult = this.objectValidation(docArg);
}
if (validationResult) {
done.resolve();
} else {
done.reject('validation of object did not pass');
}
return done.promise;
}
}

View File

@ -1,33 +1,92 @@
import * as plugins from './smartdata.plugins'
import * as plugins from './smartdata.plugins';
import { ObjectMap } from '@pushrocks/lik';
export type TConnectionStatus = 'disconnected' | 'connected' | 'failed'
import { SmartdataCollection } from './smartdata.classes.collection';
export class Db {
dbUrl: string
db: plugins.mongodb.Db
status: TConnectionStatus
import * as mongoHelpers from './smartdata.mongohelpers';
import { logger } from './smartdata.logging';
constructor(dbUrl: string) {
this.dbUrl = dbUrl
}
/**
* interface - indicates the connection status of the db
*/
export type TConnectionStatus = 'initial' | 'disconnected' | 'connected' | 'failed';
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
}
export interface ISmartdataOptions {
/**
* the URL to connect to
*/
mongoDbUrl: string;
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
}
/**
* the db to use for the project
*/
mongoDbName: string;
/**
* an optional password that will be replace <PASSWORD> in the connection string
*/
mongoDbPass?: string;
}
export class SmartdataDb {
smartdataOptions: ISmartdataOptions;
mongoDbClient: plugins.mongodb.MongoClient;
mongoDb: plugins.mongodb.Db;
status: TConnectionStatus;
smartdataCollectionMap = new ObjectMap<SmartdataCollection<any>>();
constructor(smartdataOptions: ISmartdataOptions) {
this.smartdataOptions = smartdataOptions;
this.status = 'initial';
}
// basic connection stuff ----------------------------------------------
/**
* connects to the database that was specified during instance creation
*/
public async init(): Promise<any> {
let finalConnectionUrl = this.smartdataOptions.mongoDbUrl;
if (this.smartdataOptions.mongoDbPass) {
finalConnectionUrl = mongoHelpers.addPassword(
this.smartdataOptions.mongoDbUrl,
this.smartdataOptions.mongoDbPass
);
}
console.log(`connection Url: ${finalConnectionUrl}`);
this.mongoDbClient = await plugins.mongodb.MongoClient.connect(finalConnectionUrl, {
useNewUrlParser: true,
useUnifiedTopology: true
});
this.mongoDb = this.mongoDbClient.db(this.smartdataOptions.mongoDbName);
this.status = 'connected';
console.log(`Connected to database ${this.smartdataOptions.mongoDbName}`);
}
/**
* closes the connection to the databse
*/
public async close(): Promise<any> {
await this.mongoDbClient.close();
this.status = 'disconnected';
logger.log('info', `disconnected from database ${this.smartdataOptions.mongoDbName}`);
}
// handle table to class distribution
public addTable(SmartdataCollectionArg: SmartdataCollection<any>) {
this.smartdataCollectionMap.add(SmartdataCollectionArg);
}
/**
* Gets a collection's name and returns a SmartdataCollection instance
* @param nameArg
* @returns DbTable
*/
public async getSmartdataCollectionByName<T>(nameArg: string): Promise<SmartdataCollection<T>> {
const resultCollection = this.smartdataCollectionMap.find(dbTableArg => {
return dbTableArg.collectionName === nameArg;
});
return resultCollection;
}
}

View File

@ -1,60 +0,0 @@
import * as plugins from './smartdata.plugins'
import { Db } from './smartdata.classes.db'
export class DbCollection<T> {
collection: plugins.mongodb.Collection
constructor(nameArg: string, dbArg: Db) {
this.collection = dbArg.db.collection(nameArg)
}
/**
* adds a validation function that all newly inserted and updated objects have to pass
*/
addObjectValidation(funcArg) { }
/**
* finds an object in the DbCollection
*/
find(docMatchArg: T | any): plugins.q.Promise<T[]> {
let done = plugins.q.defer<T[]>()
this.collection.find(docMatchArg).toArray((err, docs) => {
if (err) { throw err }
done.resolve(docs)
})
return done.promise
}
/**
* inserts object into the DbCollection
*/
insertOne(docArg: T): plugins.q.Promise<void> {
let done = plugins.q.defer<void>()
this.checkDoc(docArg).then(() => {
this.collection.insertOne(docArg)
.then(() => { done.resolve() })
})
return done.promise
}
/**
* inserts many objects at once into the DbCollection
*/
insertMany(docArrayArg: T[]): plugins.q.Promise<void> {
let done = plugins.q.defer<void>()
let checkDocPromiseArray: plugins.q.Promise<void>[] = []
for (let docArg of docArrayArg){
checkDocPromiseArray.push(this.checkDoc(docArg))
}
plugins.q.all(checkDocPromiseArray).then(() => {
this.collection.insertMany(docArrayArg)
.then(() => { done.resolve() })
})
return done.promise
}
private checkDoc(doc: T): plugins.q.Promise<void> {
let done = plugins.q.defer<void>()
done.resolve()
return done.promise
}
}

188
ts/smartdata.classes.doc.ts Normal file
View File

@ -0,0 +1,188 @@
import * as plugins from './smartdata.plugins';
import { ObjectMap } from '@pushrocks/lik';
import { SmartdataDb } from './smartdata.classes.db';
import { SmartdataCollection } from './smartdata.classes.collection';
export type TDocCreation = 'db' | 'new' | 'mixed';
/**
* saveable - saveable decorator to be used on class properties
*/
export function svDb() {
return (target: SmartDataDbDoc<unknown, unknown>, key: string) => {
console.log(`called svDb() on ${key}`);
if (!target.saveableProperties) {
target.saveableProperties = [];
}
target.saveableProperties.push(key);
};
}
/**
* unique index - decorator to mark a unique index
*/
export function unI() {
return (target: SmartDataDbDoc<unknown, unknown>, key: string) => {
console.log('called unI');
// mark the index as unique
if (!target.uniqueIndexes) {
target.uniqueIndexes = [];
}
target.uniqueIndexes.push(key);
// and also save it
if (!target.saveableProperties) {
target.saveableProperties = [];
}
target.saveableProperties.push(key);
};
}
export class SmartDataDbDoc<T, TImplements> {
/**
* the collection object an Doc belongs to
*/
public collection: SmartdataCollection<T>;
/**
* how the Doc in memory was created, may prove useful later.
*/
public creationStatus: TDocCreation = 'new';
/**
* unique indexes
*/
public uniqueIndexes: string[];
/**
* an array of saveable properties of a doc
*/
public saveableProperties: string[];
/**
* name
*/
public name: string;
/**
* primary id in the database
*/
public dbDocUniqueId: string;
/**
* class constructor
*/
constructor() {
this.name = this.constructor['name'];
if (this.constructor['smartdataCollection']) {
// tslint:disable-next-line: no-string-literal
this.collection = this.constructor['smartdataCollection'];
// tslint:disable-next-line: no-string-literal
} else if (typeof this.constructor['smartdataDelayedCollection'] === 'function') {
// tslint:disable-next-line: no-string-literal
this.collection = this.constructor['smartdataDelayedCollection']();
} else {
console.error('Could not determine collection for DbDoc');
}
}
public static async getInstances<T>(filterArg): Promise<T[]> {
const self: any = this; // fool typesystem
let referenceMongoDBCollection: SmartdataCollection<T>;
if (self.smartdataCollection) {
referenceMongoDBCollection = self.smartdataCollection;
} else if (self.smartdataDelayedCollection) {
referenceMongoDBCollection = self.smartdataDelayedCollection();
}
const foundDocs = await referenceMongoDBCollection.find(filterArg);
const returnArray = [];
for (const item of foundDocs) {
const newInstance = new this();
newInstance.creationStatus = 'db';
for (const key of Object.keys(item)) {
newInstance[key] = item[key];
}
returnArray.push(newInstance);
}
return returnArray;
}
public static async getInstance<T>(filterArg): Promise<T> {
const result = await this.getInstances<T>(filterArg);
if (result && result.length > 0) {
return result[0];
}
}
/**
* saves this instance but not any connected items
* may lead to data inconsistencies, but is faster
*/
public async save() {
// tslint:disable-next-line: no-this-assignment
const self: any = this;
switch (this.creationStatus) {
case 'db':
await this.collection.update(self);
break;
case 'new':
const writeResult = await this.collection.insert(self);
this.creationStatus = 'db';
break;
default:
console.error('neither new nor in db?');
}
}
/**
* deletes a document from the database
*/
public async delete() {
const self: any = this;
await this.collection.delete(self);
}
/**
* also store any referenced objects to DB
* better for data consistency
*/
public saveDeep(savedMapArg: ObjectMap<SmartDataDbDoc<any, any>> = null) {
if (!savedMapArg) {
savedMapArg = new ObjectMap<SmartDataDbDoc<any, any>>();
}
savedMapArg.add(this);
this.save();
for (const propertyKey of Object.keys(this)) {
const property: any = this[propertyKey];
if (property instanceof SmartDataDbDoc && !savedMapArg.checkForObject(property)) {
property.saveDeep(savedMapArg);
}
}
}
/**
* creates a saveable object so the instance can be persisted as json in the database
*/
public async createSavableObject(): Promise<TImplements> {
const saveableObject: unknown = {}; // is not exposed to outside, so any is ok here
for (const propertyNameString of this.saveableProperties) {
saveableObject[propertyNameString] = this[propertyNameString];
}
return saveableObject as TImplements;
}
/**
* creates an identifiable object for operations that require filtering
*/
public async createIdentifiableObject() {
const identifiableObject: any = {}; // is not exposed to outside, so any is ok here
for (const propertyNameString of this.uniqueIndexes) {
identifiableObject[propertyNameString] = this[propertyNameString];
}
return identifiableObject;
}
}

3
ts/smartdata.logging.ts Normal file
View File

@ -0,0 +1,3 @@
import * as plugins from './smartdata.plugins';
export const logger = new plugins.smartlog.ConsoleLog();

View File

@ -0,0 +1,7 @@
export const addUsername = (mongoUrlArg: string, usernameArg: string): string => {
return mongoUrlArg.replace('<USERNAME>', usernameArg);
};
export const addPassword = (mongoUrlArg: string, passwordArg: string): string => {
return mongoUrlArg.replace('<PASSWORD>', passwordArg);
};

View File

@ -1,5 +1,9 @@
import 'typings-global'
export import assert = require('assert')
export import beautylog = require('beautylog')
export import mongodb = require('mongodb')
export import q = require('q')
import * as assert from 'assert';
import * as smartlog from '@pushrocks/smartlog';
import * as lodash from 'lodash';
import * as mongodb from 'mongodb';
import * as smartq from '@pushrocks/smartpromise';
import * as smartstring from '@pushrocks/smartstring';
import * as smartunique from '@pushrocks/smartunique';
export { assert, smartlog, lodash, smartq, mongodb, smartstring, smartunique };

7
tsconfig.json Normal file
View File

@ -0,0 +1,7 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"target": "es2017",
"module": "commonjs"
}
}

View File

@ -1,3 +1,17 @@
{
"extends": "tslint-config-standard"
}
"extends": ["tslint:latest", "tslint-config-prettier"],
"rules": {
"semicolon": [true, "always"],
"no-console": false,
"ordered-imports": false,
"object-literal-sort-keys": false,
"member-ordering": {
"options":{
"order": [
"static-method"
]
}
}
},
"defaultSeverity": "warning"
}