Compare commits

...

4 Commits

Author SHA1 Message Date
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
5 changed files with 29 additions and 9 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartdata",
"version": "3.1.7",
"version": "3.1.9",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartdata",
"version": "3.1.7",
"version": "3.1.9",
"private": false,
"description": "do more with data",
"main": "dist/index.js",

View File

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

View File

@ -13,13 +13,23 @@ 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 db
* @param dbArg
*/
export function Collection(db: SmartdataDb) {
export function Collection(dbArg: SmartdataDb | TDelayedDbCreation) {
return function(constructor) {
constructor['smartdataCollection'] = new SmartdataCollection(constructor, db);
if (dbArg instanceof SmartdataDb) {
// tslint:disable-next-line: no-string-literal
constructor['smartdataCollection'] = new SmartdataCollection(constructor, dbArg);
} else {
constructor['smartdataDelayedDatabase'] = () => {
return new SmartdataCollection(constructor, dbArg());
};
}
};
}

View File

@ -77,7 +77,16 @@ export class SmartDataDbDoc<T> {
*/
constructor() {
this.name = this.constructor['name'];
this.collection = this.constructor['smartdataCollection'];
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['smartdataDelayedDatabase'] === 'function') {
// tslint:disable-next-line: no-string-literal
this.collection = this.constructor['smartdataDelayedDatabase']();
} else {
console.error('Could not determine collection for DbDoc');
}
}
static async getInstances<T>(filterArg): Promise<T[]> {
@ -109,6 +118,7 @@ export class SmartDataDbDoc<T> {
* may lead to data inconsistencies, but is faster
*/
async save() {
// tslint:disable-next-line: no-this-assignment
let self: any = this;
switch (this.creationStatus) {
case 'db':