Compare commits
18 Commits
Author | SHA1 | Date | |
---|---|---|---|
3674d7d9a5 | |||
fe2a622488 | |||
f092eefbf3 | |||
8d0aa361f9 | |||
692a1223a8 | |||
ae7d101ab9 | |||
3825b15a65 | |||
3fc41678d2 | |||
39f1b7ada1 | |||
f763de2403 | |||
cba1d031b6 | |||
d31e6a5931 | |||
46514a2743 | |||
1cf02157c4 | |||
72efa14da8 | |||
a73c2084c0 | |||
5ed557a21a | |||
2b6c30ff55 |
@ -26,6 +26,7 @@ mirror:
|
|||||||
snyk:
|
snyk:
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
- npmci command npm install -g snyk
|
- npmci command npm install -g snyk
|
||||||
- npmci command npm install --ignore-scripts
|
- npmci command npm install --ignore-scripts
|
||||||
- npmci command snyk test
|
- npmci command snyk test
|
||||||
@ -33,24 +34,39 @@ snyk:
|
|||||||
- docker
|
- docker
|
||||||
- notpriv
|
- 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
|
# 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:
|
testLTS:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
- npmci node install lts
|
- npmci node install lts
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci npm test
|
- npmci npm test
|
||||||
@ -62,6 +78,7 @@ testLTS:
|
|||||||
testSTABLE:
|
testSTABLE:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
- npmci node install stable
|
- npmci node install stable
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci npm test
|
- npmci npm test
|
||||||
@ -117,8 +134,10 @@ pages:
|
|||||||
image: hosttoday/ht-docker-node:npmci
|
image: hosttoday/ht-docker-node:npmci
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g npmpage
|
- npmci command npm install -g typedoc typescript
|
||||||
- npmci command npmpage
|
- npmci npm prepare
|
||||||
|
- npmci npm install
|
||||||
|
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
@ -129,13 +148,3 @@ pages:
|
|||||||
paths:
|
paths:
|
||||||
- public
|
- public
|
||||||
allow_failure: true
|
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
|
|
||||||
|
10
README.md
10
README.md
@ -37,11 +37,11 @@ This is why we started smartdata.
|
|||||||
|
|
||||||
How RethinkDB's terms map to the ones of smartdata:
|
How RethinkDB's terms map to the ones of smartdata:
|
||||||
|
|
||||||
| MongoDb term | smartdata class |
|
| MongoDb term | smartdata class |
|
||||||
| -------------- | ------------------------------|
|
| ------------ | ----------------------------- |
|
||||||
| Database | smartdata.SmartdataDb |
|
| Database | smartdata.SmartdataDb |
|
||||||
| Collection | smartdata.SmartdataCollection |
|
| Collection | smartdata.SmartdataCollection |
|
||||||
| Document | smartdata.SmartadataDoc |
|
| Document | smartdata.SmartadataDoc |
|
||||||
|
|
||||||
### class Db
|
### class Db
|
||||||
|
|
||||||
|
@ -1,29 +0,0 @@
|
|||||||
# smartdata
|
|
||||||
|
|
||||||
do more with data
|
|
||||||
|
|
||||||
## Availabililty
|
|
||||||
|
|
||||||
[](https://www.npmjs.com/package/smartdata)
|
|
||||||
[](https://GitLab.com/pushrocks/smartdata)
|
|
||||||
[](https://github.com/pushrocks/smartdata)
|
|
||||||
[](https://pushrocks.gitlab.io/smartdata/)
|
|
||||||
|
|
||||||
## Status for master
|
|
||||||
|
|
||||||
[](https://GitLab.com/pushrocks/smartdata/commits/master)
|
|
||||||
[](https://GitLab.com/pushrocks/smartdata/commits/master)
|
|
||||||
[](https://www.npmjs.com/package/smartdata)
|
|
||||||
[](https://david-dm.org/pushrocks/smartdata)
|
|
||||||
[](https://www.bithound.io/github/pushrocks/smartdata/master/dependencies/npm)
|
|
||||||
[](https://www.bithound.io/github/pushrocks/smartdata)
|
|
||||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
|
||||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
|
||||||
[](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)
|
|
||||||
|
|
||||||
[](https://push.rocks)
|
|
@ -5,14 +5,8 @@
|
|||||||
"dockerSock": false
|
"dockerSock": false
|
||||||
},
|
},
|
||||||
"npmci": {
|
"npmci": {
|
||||||
"npmGlobalTools": [
|
"npmGlobalTools": [],
|
||||||
"npmts"
|
"npmAccessLevel": "public",
|
||||||
],
|
"npmRegistryUrl": "registry.npmjs.org"
|
||||||
"npmAccessLevel": "public"
|
|
||||||
},
|
|
||||||
"npmts": {
|
|
||||||
"testConfig": {
|
|
||||||
"parallel": false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
1945
package-lock.json
generated
1945
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
36
package.json
36
package.json
@ -1,14 +1,14 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartdata",
|
"name": "@pushrocks/smartdata",
|
||||||
"version": "3.0.2",
|
"version": "3.1.6",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "do more with data",
|
"description": "do more with data",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist/index.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "tsrun test/test.ts",
|
"test": "(tstest test/)",
|
||||||
"testLocal": "(npmdocker)",
|
"testLocal": "(npmdocker)",
|
||||||
"build": "(npmts)"
|
"build": "(tsbuild)"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -21,20 +21,26 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/smartdata#README",
|
"homepage": "https://gitlab.com/pushrocks/smartdata#README",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartlog": "^1.0.6",
|
"@pushrocks/lik": "^3.0.4",
|
||||||
|
"@pushrocks/smartlog": "^2.0.9",
|
||||||
"@pushrocks/smartpromise": "^2.0.5",
|
"@pushrocks/smartpromise": "^2.0.5",
|
||||||
"@types/lodash": "^4.14.110",
|
"@pushrocks/smartstring": "^3.0.5",
|
||||||
"@types/mongodb": "^3.1.1",
|
"@types/lodash": "^4.14.119",
|
||||||
"lik": "^2.0.5",
|
"@types/mongodb": "^3.1.18",
|
||||||
"lodash": "^4.17.10",
|
"lodash": "^4.17.11",
|
||||||
"mongodb": "^3.1.1",
|
"mongodb": "^3.1.10",
|
||||||
"runtime-type-checks": "0.0.4",
|
"runtime-type-checks": "0.0.4"
|
||||||
"smartstring": "^2.0.28"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsrun": "^1.1.2",
|
"@gitzone/tsbuild": "^2.1.4",
|
||||||
"@types/node": "^10.5.2",
|
"@gitzone/tstest": "^1.0.18",
|
||||||
"qenv": "^1.1.7",
|
"@pushrocks/qenv": "^3.0.2",
|
||||||
"tapbundle": "^2.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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
2
qenv.yml
2
qenv.yml
@ -1,4 +1,4 @@
|
|||||||
vars:
|
required:
|
||||||
- MONGO_URL
|
- MONGO_URL
|
||||||
- MONGO_DBNAME
|
- MONGO_DBNAME
|
||||||
- MONGO_PASS
|
- MONGO_PASS
|
||||||
|
10
test/test.ts
10
test/test.ts
@ -1,12 +1,13 @@
|
|||||||
import { tap, expect } from 'tapbundle';
|
import { tap, expect } from '@pushrocks/tapbundle';
|
||||||
import * as smartpromise from '@pushrocks/smartpromise';
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
import { Qenv } from 'qenv';
|
import { Qenv } from '@pushrocks/qenv';
|
||||||
|
|
||||||
let testQenv = new Qenv(process.cwd(), process.cwd() + '/.nogit/');
|
let testQenv = new Qenv(process.cwd(), process.cwd() + '/.nogit/');
|
||||||
|
|
||||||
// the tested module
|
// the tested module
|
||||||
import * as smartdata from '../ts';
|
import * as smartdata from '../ts/index';
|
||||||
import { smartstring } from '../ts/smartdata.plugins';
|
import { smartstring } from '../ts/smartdata.plugins';
|
||||||
|
import * as shortid from 'shortid';
|
||||||
|
|
||||||
// =======================================
|
// =======================================
|
||||||
// Connecting to the database server
|
// Connecting to the database server
|
||||||
@ -32,6 +33,7 @@ tap.test('should establish a connection to the rethink Db cluster', async () =>
|
|||||||
|
|
||||||
@smartdata.Collection(testDb)
|
@smartdata.Collection(testDb)
|
||||||
class Car extends smartdata.SmartDataDbDoc<Car> {
|
class Car extends smartdata.SmartDataDbDoc<Car> {
|
||||||
|
@smartdata.unI() index: string = shortid();
|
||||||
@smartdata.svDb() color: string;
|
@smartdata.svDb() color: string;
|
||||||
@smartdata.svDb() brand: string;
|
@smartdata.svDb() brand: string;
|
||||||
constructor(colorArg: string, brandArg: string) {
|
constructor(colorArg: string, brandArg: string) {
|
||||||
@ -60,4 +62,4 @@ tap.test('should close the database connection', async tools => {
|
|||||||
await testDb.close();
|
await testDb.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.start();
|
tap.start({ throwOnError: true });
|
||||||
|
@ -31,6 +31,7 @@ export class SmartdataCollection<T> {
|
|||||||
objectValidation: IDocValidationFunc<T> = null;
|
objectValidation: IDocValidationFunc<T> = null;
|
||||||
collectionName: string;
|
collectionName: string;
|
||||||
smartdataDb: SmartdataDb;
|
smartdataDb: SmartdataDb;
|
||||||
|
uniqueIndexes: string[] = [];
|
||||||
|
|
||||||
constructor(collectedClassArg: T & SmartDataDbDoc<T>, smartDataDbArg: SmartdataDb) {
|
constructor(collectedClassArg: T & SmartDataDbDoc<T>, smartDataDbArg: SmartdataDb) {
|
||||||
// tell the collection where it belongs
|
// tell the collection where it belongs
|
||||||
@ -55,7 +56,22 @@ export class SmartdataCollection<T> {
|
|||||||
await this.smartdataDb.mongoDb.createCollection(this.collectionName);
|
await this.smartdataDb.mongoDb.createCollection(this.collectionName);
|
||||||
}
|
}
|
||||||
this.mongoDbCollection = await this.smartdataDb.mongoDb.collection(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,6 +97,7 @@ export class SmartdataCollection<T> {
|
|||||||
async insert(dbDocArg: T & SmartDataDbDoc<T>): Promise<any> {
|
async insert(dbDocArg: T & SmartDataDbDoc<T>): Promise<any> {
|
||||||
await this.init();
|
await this.init();
|
||||||
await this.checkDoc(dbDocArg);
|
await this.checkDoc(dbDocArg);
|
||||||
|
this.markUniqueIndexes(dbDocArg.uniqueIndexes);
|
||||||
const saveableObject = await dbDocArg.createSavableObject();
|
const saveableObject = await dbDocArg.createSavableObject();
|
||||||
console.log(saveableObject);
|
console.log(saveableObject);
|
||||||
const result = await this.mongoDbCollection.insertOne(saveableObject);
|
const result = await this.mongoDbCollection.insertOne(saveableObject);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import * as plugins from './smartdata.plugins';
|
import * as plugins from './smartdata.plugins';
|
||||||
import { Objectmap } from 'lik';
|
import { Objectmap } from '@pushrocks/lik';
|
||||||
|
|
||||||
import { SmartdataCollection } from './smartdata.classes.collection';
|
import { SmartdataCollection } from './smartdata.classes.collection';
|
||||||
|
|
||||||
@ -70,9 +70,10 @@ export class SmartdataDb {
|
|||||||
async close(): Promise<any> {
|
async close(): Promise<any> {
|
||||||
await this.mongoDbClient.close();
|
await this.mongoDbClient.close();
|
||||||
this.status = 'disconnected';
|
this.status = 'disconnected';
|
||||||
plugins.smartlog
|
plugins.smartlog.defaultLogger.log(
|
||||||
.getDefaultLogger()
|
'info',
|
||||||
.info(`disconnected from database ${this.smartdataOptions.mongoDbName}`);
|
`disconnected from database ${this.smartdataOptions.mongoDbName}`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle table to class distribution
|
// handle table to class distribution
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import * as plugins from './smartdata.plugins';
|
import * as plugins from './smartdata.plugins';
|
||||||
|
|
||||||
import { Objectmap } from 'lik';
|
import { Objectmap } from '@pushrocks/lik';
|
||||||
|
|
||||||
import { SmartdataDb } from './smartdata.classes.db';
|
import { SmartdataDb } from './smartdata.classes.db';
|
||||||
import { SmartdataCollection } from './smartdata.classes.collection';
|
import { SmartdataCollection } from './smartdata.classes.collection';
|
||||||
@ -12,7 +12,28 @@ export type TDocCreation = 'db' | 'new' | 'mixed';
|
|||||||
*/
|
*/
|
||||||
export function svDb() {
|
export function svDb() {
|
||||||
return (target: SmartDataDbDoc<any>, key: string) => {
|
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) {
|
if (!target.saveableProperties) {
|
||||||
target.saveableProperties = [];
|
target.saveableProperties = [];
|
||||||
}
|
}
|
||||||
@ -31,6 +52,11 @@ export class SmartDataDbDoc<T> {
|
|||||||
*/
|
*/
|
||||||
creationStatus: TDocCreation = 'new';
|
creationStatus: TDocCreation = 'new';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* unique indexes
|
||||||
|
*/
|
||||||
|
uniqueIndexes: string[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* an array of saveable properties of a doc
|
* an array of saveable properties of a doc
|
||||||
*/
|
*/
|
||||||
|
@ -2,7 +2,7 @@ import * as assert from 'assert';
|
|||||||
import * as smartlog from '@pushrocks/smartlog';
|
import * as smartlog from '@pushrocks/smartlog';
|
||||||
import * as lodash from 'lodash';
|
import * as lodash from 'lodash';
|
||||||
import * as mongodb from 'mongodb';
|
import * as mongodb from 'mongodb';
|
||||||
import * as smartq from 'smartq';
|
import * as smartq from '@pushrocks/smartpromise';
|
||||||
import * as smartstring from 'smartstring';
|
import * as smartstring from '@pushrocks/smartstring';
|
||||||
|
|
||||||
export { assert, smartlog, lodash, smartq, mongodb, smartstring };
|
export { assert, smartlog, lodash, smartq, mongodb, smartstring };
|
||||||
|
17
tslint.json
Normal file
17
tslint.json
Normal 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"
|
||||||
|
}
|
Reference in New Issue
Block a user