Compare commits

..

33 Commits

Author SHA1 Message Date
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
16 changed files with 1818 additions and 500 deletions

View File

@ -26,6 +26,7 @@ mirror:
snyk:
stage: security
script:
- npmci npm prepare
- npmci command npm install -g snyk
- npmci command npm install --ignore-scripts
- npmci command snyk test
@ -33,24 +34,39 @@ snyk:
- docker
- notpriv
sast:
stage: security
image: registry.gitlab.com/hosttoday/ht-docker-dbase:npmci
variables:
DOCKER_DRIVER: overlay2
allow_failure: true
services:
- docker:stable-dind
script:
- npmci npm prepare
- npmci npm install
- npmci command npm run build
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
- docker run
--env SAST_CONFIDENCE_LEVEL="${SAST_CONFIDENCE_LEVEL:-3}"
--volume "$PWD:/code"
--volume /var/run/docker.sock:/var/run/docker.sock
"registry.gitlab.com/gitlab-org/security-products/sast:$SP_VERSION" /app/bin/run /code
artifacts:
reports:
sast: gl-sast-report.json
tags:
- docker
- priv
# ====================
# test stage
# ====================
testLEGACY:
stage: test
script:
- npmci node install legacy
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- notpriv
allow_failure: true
testLTS:
stage: test
script:
- npmci npm prepare
- npmci node install lts
- npmci npm install
- npmci npm test
@ -62,6 +78,7 @@ testLTS:
testSTABLE:
stage: test
script:
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci npm test
@ -117,8 +134,10 @@ pages:
image: hosttoday/ht-docker-node:npmci
stage: metadata
script:
- npmci command npm install -g npmpage
- npmci command npmpage
- npmci command npm install -g typedoc typescript
- npmci npm prepare
- npmci npm install
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
tags:
- docker
- notpriv
@ -129,13 +148,3 @@ pages:
paths:
- public
allow_failure: true
windowsCompatibility:
image: stefanscherer/node-windows:10-build-tools
stage: metadata
script:
- npm install & npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- windows
allow_failure: true

View File

@ -1,25 +1,19 @@
# @pushrocks/smartdata
do more with data
do more with data and RethinkDB
## Availabililty
[![npm](https://pushrocks.gitlab.io/assets/repo-button-npm.svg)](https://www.npmjs.com/package/smartdata)
[![git](https://pushrocks.gitlab.io/assets/repo-button-git.svg)](https://GitLab.com/pushrocks/smartdata)
[![git](https://pushrocks.gitlab.io/assets/repo-button-mirror.svg)](https://github.com/pushrocks/smartdata)
[![docs](https://pushrocks.gitlab.io/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/smartdata/)
## 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
[![build status](https://GitLab.com/pushrocks/smartdata/badges/master/build.svg)](https://GitLab.com/pushrocks/smartdata/commits/master)
[![coverage report](https://GitLab.com/pushrocks/smartdata/badges/master/coverage.svg)](https://GitLab.com/pushrocks/smartdata/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/smartdata.svg)](https://www.npmjs.com/package/smartdata)
[![Dependency Status](https://david-dm.org/pushrocks/smartdata.svg)](https://david-dm.org/pushrocks/smartdata)
[![bitHound Dependencies](https://www.bithound.io/github/pushrocks/smartdata/badges/dependencies.svg)](https://www.bithound.io/github/pushrocks/smartdata/master/dependencies/npm)
[![bitHound Code](https://www.bithound.io/github/pushrocks/smartdata/badges/code.svg)](https://www.bithound.io/github/pushrocks/smartdata)
[![Known Vulnerabilities](https://snyk.io/test/npm/smartdata/badge.svg)](https://snyk.io/test/npm/smartdata)
[![TypeScript](https://img.shields.io/badge/TypeScript-2.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%206.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![build status](https://gitlab.com/pushrocks/smartdata/badges/master/build.svg)](https://gitlab.com/pushrocks/smartdata/commits/master)
[![coverage report](https://gitlab.com/pushrocks/smartdata/badges/master/coverage.svg)](https://gitlab.com/pushrocks/smartdata/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/@pushrocks/smartdata.svg)](https://www.npmjs.com/package/@pushrocks/smartdata)
[![Known Vulnerabilities](https://snyk.io/test/npm/@pushrocks/smartdata/badge.svg)](https://snyk.io/test/npm/@pushrocks/smartdata)
[![TypeScript](https://img.shields.io/badge/TypeScript->=%203.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
## Usage
@ -37,11 +31,11 @@ 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 |
| MongoDb term | smartdata class |
| ------------ | ----------------------------- |
| Database | smartdata.SmartdataDb |
| Collection | smartdata.SmartdataCollection |
| Document | smartdata.SmartadataDoc |
### class Db
@ -121,9 +115,9 @@ you should get all the Intellisense and type checking you love when using smartd
smartdata itself also bundles typings.
So you don't need to install any additional types when importing smartdata.
For further information read the linked docs at the top of this README.
For further information read the linked docs at the top of this readme.
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://push.rocks)
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://maintainedby.lossless.com)

View File

@ -1,29 +0,0 @@
# smartdata
do more with data
## Availabililty
[![npm](https://pushrocks.gitlab.io/assets/repo-button-npm.svg)](https://www.npmjs.com/package/smartdata)
[![git](https://pushrocks.gitlab.io/assets/repo-button-git.svg)](https://GitLab.com/pushrocks/smartdata)
[![git](https://pushrocks.gitlab.io/assets/repo-button-mirror.svg)](https://github.com/pushrocks/smartdata)
[![docs](https://pushrocks.gitlab.io/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/smartdata/)
## Status for master
[![build status](https://GitLab.com/pushrocks/smartdata/badges/master/build.svg)](https://GitLab.com/pushrocks/smartdata/commits/master)
[![coverage report](https://GitLab.com/pushrocks/smartdata/badges/master/coverage.svg)](https://GitLab.com/pushrocks/smartdata/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/smartdata.svg)](https://www.npmjs.com/package/smartdata)
[![Dependency Status](https://david-dm.org/pushrocks/smartdata.svg)](https://david-dm.org/pushrocks/smartdata)
[![bitHound Dependencies](https://www.bithound.io/github/pushrocks/smartdata/badges/dependencies.svg)](https://www.bithound.io/github/pushrocks/smartdata/master/dependencies/npm)
[![bitHound Code](https://www.bithound.io/github/pushrocks/smartdata/badges/code.svg)](https://www.bithound.io/github/pushrocks/smartdata)
[![TypeScript](https://img.shields.io/badge/TypeScript-2.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%206.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
For further information read the linked docs at the top of this README.
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://push.rocks)

View File

@ -5,14 +5,18 @@
"dockerSock": false
},
"npmci": {
"npmGlobalTools": [
"npmts"
],
"npmAccessLevel": "public"
"npmGlobalTools": [],
"npmAccessLevel": "public",
"npmRegistryUrl": "registry.npmjs.org"
},
"npmts": {
"testConfig": {
"parallel": false
"gitzone": {
"module": {
"githost": "gitlab.com",
"gitscope": "pushrocks",
"gitrepo": "smartdata",
"shortDescription": "do more with data",
"npmPackagename": "@pushrocks/smartdata",
"license": "MIT"
}
}
}
}

1945
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,14 +1,14 @@
{
"name": "@pushrocks/smartdata",
"version": "3.0.2",
"version": "3.1.14",
"private": false,
"description": "do more with data",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"scripts": {
"test": "tsrun test/test.ts",
"test": "(tstest test/)",
"testLocal": "(npmdocker)",
"build": "(npmts)"
"build": "(tsbuild)"
},
"repository": {
"type": "git",
@ -21,20 +21,26 @@
},
"homepage": "https://gitlab.com/pushrocks/smartdata#README",
"dependencies": {
"@pushrocks/smartlog": "^1.0.6",
"@pushrocks/lik": "^3.0.4",
"@pushrocks/smartlog": "^2.0.9",
"@pushrocks/smartpromise": "^2.0.5",
"@types/lodash": "^4.14.110",
"@types/mongodb": "^3.1.1",
"lik": "^2.0.5",
"lodash": "^4.17.10",
"mongodb": "^3.1.1",
"runtime-type-checks": "0.0.4",
"smartstring": "^2.0.28"
"@pushrocks/smartstring": "^3.0.5",
"@types/lodash": "^4.14.119",
"@types/mongodb": "^3.1.18",
"lodash": "^4.17.11",
"mongodb": "^3.1.10",
"runtime-type-checks": "0.0.4"
},
"devDependencies": {
"@gitzone/tsrun": "^1.1.2",
"@types/node": "^10.5.2",
"qenv": "^1.1.7",
"tapbundle": "^2.0.2"
"@gitzone/tsbuild": "^2.1.4",
"@gitzone/tstest": "^1.0.18",
"@pushrocks/qenv": "^3.0.2",
"@pushrocks/tapbundle": "^3.0.7",
"@types/node": "^10.12.18",
"@types/shortid": "0.0.29",
"mongodb-memory-server": "^2.9.1",
"shortid": "^2.2.14",
"tslint": "^5.12.0",
"tslint-config-prettier": "^1.17.0"
}
}

View File

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

View File

@ -1,12 +1,13 @@
import { tap, expect } from 'tapbundle';
import { tap, expect } from '@pushrocks/tapbundle';
import * as smartpromise from '@pushrocks/smartpromise';
import { Qenv } from 'qenv';
import { Qenv } from '@pushrocks/qenv';
let testQenv = new Qenv(process.cwd(), process.cwd() + '/.nogit/');
// the tested module
import * as smartdata from '../ts';
import * as smartdata from '../ts/index';
import { smartstring } from '../ts/smartdata.plugins';
import * as shortid from 'shortid';
// =======================================
// Connecting to the database server
@ -19,7 +20,7 @@ let testDb = new smartdata.SmartdataDb({
});
tap.test('should establish a connection to the rethink Db cluster', async () => {
await testDb.connect();
await testDb.init();
});
// =======================================
@ -32,6 +33,7 @@ tap.test('should establish a connection to the rethink Db cluster', async () =>
@smartdata.Collection(testDb)
class Car extends smartdata.SmartDataDbDoc<Car> {
@smartdata.unI() index: string = shortid();
@smartdata.svDb() color: string;
@smartdata.svDb() brand: string;
constructor(colorArg: string, brandArg: string) {
@ -60,4 +62,4 @@ tap.test('should close the database connection', async tools => {
await testDb.close();
});
tap.start();
tap.start({ throwOnError: true });

View File

@ -1,3 +1,5 @@
export * from './smartdata.classes.db';
export * from './smartdata.classes.collection';
export * from './smartdata.classes.doc';
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

@ -13,13 +13,22 @@ 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['smartdataDelayedCollection'] = () => {
return new SmartdataCollection(constructor, dbArg());
};
}
};
}
@ -31,6 +40,7 @@ export class SmartdataCollection<T> {
objectValidation: IDocValidationFunc<T> = null;
collectionName: string;
smartdataDb: SmartdataDb;
uniqueIndexes: string[] = [];
constructor(collectedClassArg: T & SmartDataDbDoc<T>, smartDataDbArg: SmartdataDb) {
// tell the collection where it belongs
@ -55,7 +65,22 @@ export class SmartdataCollection<T> {
await this.smartdataDb.mongoDb.createCollection(this.collectionName);
}
this.mongoDbCollection = await this.smartdataDb.mongoDb.collection(this.collectionName);
console.log(`Successfully initiated Collection ${this.collectionName}`)
console.log(`Successfully initiated Collection ${this.collectionName}`);
}
}
/**
* mark unique index
*/
markUniqueIndexes(keyArrayArg: string[] = []) {
for (let 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);
}
}
}
@ -81,8 +106,8 @@ export class SmartdataCollection<T> {
async insert(dbDocArg: T & SmartDataDbDoc<T>): Promise<any> {
await this.init();
await this.checkDoc(dbDocArg);
this.markUniqueIndexes(dbDocArg.uniqueIndexes);
const saveableObject = await dbDocArg.createSavableObject();
console.log(saveableObject);
const result = await this.mongoDbCollection.insertOne(saveableObject);
return result;
}
@ -90,11 +115,19 @@ export class SmartdataCollection<T> {
/**
* inserts object into the DbCollection
*/
async update(dbDocArg: T & SmartDataDbDoc<T>): Promise<any> {
public async update(dbDocArg: T & SmartDataDbDoc<T>): Promise<any> {
await this.init();
await this.checkDoc(dbDocArg);
const identifiableObject = await dbDocArg.createIdentifiableObject();
const saveableObject = await dbDocArg.createSavableObject();
this.mongoDbCollection.updateOne(saveableObject.dbDocUniqueId, saveableObject);
this.mongoDbCollection.updateOne(identifiableObject, saveableObject);
}
public async delete(dbDocArg: T & SmartDataDbDoc<T>): Promise<any> {
await this.init();
await this.checkDoc(dbDocArg);
const identifiableObject = await dbDocArg.createIdentifiableObject();
this.mongoDbCollection.deleteOne(identifiableObject);
}
/**
@ -102,7 +135,7 @@ export class SmartdataCollection<T> {
* if this.objectValidation is not set it passes.
*/
private checkDoc(docArg: T): Promise<void> {
let done = plugins.smartq.defer<void>();
const done = plugins.smartq.defer<void>();
let validationResult = true;
if (this.objectValidation) {
validationResult = this.objectValidation(docArg);

View File

@ -1,5 +1,5 @@
import * as plugins from './smartdata.plugins';
import { Objectmap } from 'lik';
import { Objectmap } from '@pushrocks/lik';
import { SmartdataCollection } from './smartdata.classes.collection';
@ -44,7 +44,7 @@ export class SmartdataDb {
/**
* connects to the database that was specified during instance creation
*/
async connect(): Promise<any> {
async init(): Promise<any> {
let finalConnectionUrl = this.smartdataOptions.mongoDbUrl;
if (this.smartdataOptions.mongoDbPass) {
finalConnectionUrl = mongoHelpers.addPassword(
@ -53,12 +53,9 @@ export class SmartdataDb {
);
}
console.log(finalConnectionUrl);
this.mongoDbClient = await plugins.mongodb.MongoClient.connect(
finalConnectionUrl,
{
useNewUrlParser: true
}
);
this.mongoDbClient = await plugins.mongodb.MongoClient.connect(finalConnectionUrl, {
useNewUrlParser: true
});
this.mongoDb = this.mongoDbClient.db(this.smartdataOptions.mongoDbName);
this.status = 'connected';
console.log(`Connected to database ${this.smartdataOptions.mongoDbName}`);
@ -70,9 +67,10 @@ export class SmartdataDb {
async close(): Promise<any> {
await this.mongoDbClient.close();
this.status = 'disconnected';
plugins.smartlog
.getDefaultLogger()
.info(`disconnected from database ${this.smartdataOptions.mongoDbName}`);
plugins.smartlog.defaultLogger.log(
'info',
`disconnected from database ${this.smartdataOptions.mongoDbName}`
);
}
// handle table to class distribution

View File

@ -1,6 +1,6 @@
import * as plugins from './smartdata.plugins';
import { Objectmap } from 'lik';
import { Objectmap } from '@pushrocks/lik';
import { SmartdataDb } from './smartdata.classes.db';
import { SmartdataCollection } from './smartdata.classes.collection';
@ -12,7 +12,28 @@ export type TDocCreation = 'db' | 'new' | 'mixed';
*/
export function svDb() {
return (target: SmartDataDbDoc<any>, key: string) => {
console.log('called sva');
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<any>, 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 = [];
}
@ -31,6 +52,11 @@ export class SmartDataDbDoc<T> {
*/
creationStatus: TDocCreation = 'new';
/**
* unique indexes
*/
uniqueIndexes: string[];
/**
* an array of saveable properties of a doc
*/
@ -51,12 +77,27 @@ 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['smartdataDelayedCollection'] === 'function') {
// tslint:disable-next-line: no-string-literal
this.collection = this.constructor['smartdataDelayedCollection']();
} else {
console.error('Could not determine collection for DbDoc');
}
}
static async getInstances<T>(filterArg): Promise<T[]> {
let self: any = this; // fool typesystem
let referenceMongoDBCollection: SmartdataCollection<T> = self.smartdataCollection;
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 (let item of foundDocs) {
@ -83,6 +124,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':
@ -97,6 +139,11 @@ export class SmartDataDbDoc<T> {
}
}
/**
* deletes a document from the database
*/
async delete() {}
/**
* also store any referenced objects to DB
* better for data consistency
@ -115,11 +162,25 @@ export class SmartDataDbDoc<T> {
}
}
async createSavableObject() {
let saveableObject: any = {}; // is not exposed to outside, so any is ok here
for (let propertyNameString of this.saveableProperties) {
/**
* creates a saveable object so the instance can be persisted as json in the database
*/
public async createSavableObject() {
const saveableObject: any = {}; // is not exposed to outside, so any is ok here
for (const propertyNameString of this.saveableProperties) {
saveableObject[propertyNameString] = this[propertyNameString];
}
return saveableObject;
}
/**
* 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;
}
}

View File

@ -2,7 +2,7 @@ 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 'smartq';
import * as smartstring from 'smartstring';
import * as smartq from '@pushrocks/smartpromise';
import * as smartstring from '@pushrocks/smartstring';
export { assert, smartlog, lodash, smartq, mongodb, smartstring };

17
tslint.json Normal file
View File

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