Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
9c81257101 | |||
f7342962f4 | |||
bcd10205d3 | |||
6cab20f32d | |||
5aaa6ad2d6 | |||
635256f2f6 | |||
f799d3efa5 | |||
f74020ba96 | |||
f6d6545ff5 | |||
85a196c8c1 |
1244
package-lock.json
generated
1244
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
15
package.json
15
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartdata",
|
"name": "@pushrocks/smartdata",
|
||||||
"version": "3.1.40",
|
"version": "3.1.45",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "do more with data",
|
"description": "do more with data",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
@ -22,13 +22,14 @@
|
|||||||
"homepage": "https://gitlab.com/pushrocks/smartdata#README",
|
"homepage": "https://gitlab.com/pushrocks/smartdata#README",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/lik": "^4.0.17",
|
"@pushrocks/lik": "^4.0.17",
|
||||||
"@pushrocks/smartlog": "^2.0.36",
|
"@pushrocks/smartlog": "^2.0.39",
|
||||||
"@pushrocks/smartpromise": "^3.0.6",
|
"@pushrocks/smartpromise": "^3.0.6",
|
||||||
"@pushrocks/smartstring": "^3.0.18",
|
"@pushrocks/smartstring": "^3.0.18",
|
||||||
"@types/lodash": "^4.14.159",
|
"@tsclass/tsclass": "^3.0.25",
|
||||||
"@types/mongodb": "^3.5.26",
|
"@types/lodash": "^4.14.161",
|
||||||
|
"@types/mongodb": "^3.5.27",
|
||||||
"lodash": "^4.17.20",
|
"lodash": "^4.17.20",
|
||||||
"mongodb": "^3.6.0",
|
"mongodb": "^3.6.1",
|
||||||
"runtime-type-checks": "0.0.4"
|
"runtime-type-checks": "0.0.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@ -38,9 +39,9 @@
|
|||||||
"@pushrocks/smartunique": "^3.0.3",
|
"@pushrocks/smartunique": "^3.0.3",
|
||||||
"@pushrocks/tapbundle": "^3.2.9",
|
"@pushrocks/tapbundle": "^3.2.9",
|
||||||
"@types/mongodb-memory-server": "^2.3.0",
|
"@types/mongodb-memory-server": "^2.3.0",
|
||||||
"@types/node": "^14.6.0",
|
"@types/node": "^14.6.4",
|
||||||
"@types/shortid": "0.0.29",
|
"@types/shortid": "0.0.29",
|
||||||
"mongodb-memory-server": "6.6.3",
|
"mongodb-memory-server": "^6.7.0",
|
||||||
"tslint": "^6.1.3",
|
"tslint": "^6.1.3",
|
||||||
"tslint-config-prettier": "^1.18.0"
|
"tslint-config-prettier": "^1.18.0"
|
||||||
},
|
},
|
||||||
|
40
test/test.ts
40
test/test.ts
@ -18,10 +18,9 @@ let smartdataOptions: smartdata.IMongoDescriptor;
|
|||||||
let mongod: mongoPlugin.MongoMemoryServer;
|
let mongod: mongoPlugin.MongoMemoryServer;
|
||||||
|
|
||||||
tap.skip.test('should create a testinstance as database', async () => {
|
tap.skip.test('should create a testinstance as database', async () => {
|
||||||
mongod = new mongoPlugin.MongoMemoryServer({
|
mongod = new mongoPlugin.MongoMemoryServer({});
|
||||||
});
|
|
||||||
console.log('created mongod instance');
|
console.log('created mongod instance');
|
||||||
await mongod._startUpInstance().catch(err => {
|
await mongod._startUpInstance().catch((err) => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
});
|
});
|
||||||
console.log('mongod started');
|
console.log('mongod started');
|
||||||
@ -38,7 +37,7 @@ tap.test('should connect to atlas', async (tools) => {
|
|||||||
const databaseName = `test-smartdata-${smartunique.shortId()}`;
|
const databaseName = `test-smartdata-${smartunique.shortId()}`;
|
||||||
testDb = new smartdata.SmartdataDb({
|
testDb = new smartdata.SmartdataDb({
|
||||||
mongoDbUrl: testQenv.getEnvVarOnDemand('MONGO_URL'),
|
mongoDbUrl: testQenv.getEnvVarOnDemand('MONGO_URL'),
|
||||||
mongoDbName: databaseName
|
mongoDbName: databaseName,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -67,6 +66,11 @@ class Car extends smartdata.SmartDataDbDoc<Car, Car> {
|
|||||||
@smartdata.svDb()
|
@smartdata.svDb()
|
||||||
public brand: string;
|
public brand: string;
|
||||||
|
|
||||||
|
@smartdata.svDb()
|
||||||
|
deepData = {
|
||||||
|
sodeep: 'yes'
|
||||||
|
};
|
||||||
|
|
||||||
constructor(colorArg: string, brandArg: string) {
|
constructor(colorArg: string, brandArg: string) {
|
||||||
super();
|
super();
|
||||||
this.color = colorArg;
|
this.color = colorArg;
|
||||||
@ -81,15 +85,30 @@ tap.test('should save the car to the db', async () => {
|
|||||||
const myCar2 = new Car('red', 'Volvo');
|
const myCar2 = new Car('red', 'Volvo');
|
||||||
await myCar2.save();
|
await myCar2.save();
|
||||||
|
|
||||||
const myCar3 = new Car('red', 'Renault');
|
|
||||||
await myCar3.save();
|
|
||||||
|
let counter = 0;
|
||||||
|
do {
|
||||||
|
const myCar3 = new Car('red', 'Renault');
|
||||||
|
await myCar3.save();
|
||||||
|
counter++;
|
||||||
|
} while (counter < 2000);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('expect to get instance of Car', async () => {
|
tap.test('expect to get instance of Car', async () => {
|
||||||
const myCars = await Car.getInstances<Car>({
|
let counter = 0;
|
||||||
brand: 'Volvo',
|
do {
|
||||||
});
|
const timeStart = Date.now();
|
||||||
expect(myCars[0].color).to.equal('red');
|
const myCars = await Car.getInstances<Car>({
|
||||||
|
brand: 'Volvo',
|
||||||
|
});
|
||||||
|
const myCars2 = await Car.getInstances<Car>({
|
||||||
|
'deepData.sodeep': 'yes',
|
||||||
|
} as any);
|
||||||
|
expect(myCars[0].color).to.equal('red');
|
||||||
|
console.log(`took ${Date.now() - timeStart}`);
|
||||||
|
counter++;
|
||||||
|
} while (counter < 2000);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('expect to get instance of Car and update it', async () => {
|
tap.test('expect to get instance of Car and update it', async () => {
|
||||||
@ -151,7 +170,6 @@ tap.test('should store a new Truck', async () => {
|
|||||||
tap.test('should close the database connection', async (tools) => {
|
tap.test('should close the database connection', async (tools) => {
|
||||||
await testDb.close();
|
await testDb.close();
|
||||||
try {
|
try {
|
||||||
|
|
||||||
await mongod.stop();
|
await mongod.stop();
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
});
|
});
|
||||||
|
@ -63,9 +63,9 @@ export class SmartdataCollection<T> {
|
|||||||
});
|
});
|
||||||
if (!wantedCollection) {
|
if (!wantedCollection) {
|
||||||
await this.smartdataDb.mongoDb.createCollection(this.collectionName);
|
await this.smartdataDb.mongoDb.createCollection(this.collectionName);
|
||||||
|
console.log(`Successfully initiated Collection ${this.collectionName}`);
|
||||||
}
|
}
|
||||||
this.mongoDbCollection = await this.smartdataDb.mongoDb.collection(this.collectionName);
|
this.mongoDbCollection = this.smartdataDb.mongoDb.collection(this.collectionName);
|
||||||
// console.log(`Successfully initiated Collection ${this.collectionName}`);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,6 +40,8 @@ export class SmartdataDb {
|
|||||||
this.mongoDbClient = await plugins.mongodb.MongoClient.connect(finalConnectionUrl, {
|
this.mongoDbClient = await plugins.mongodb.MongoClient.connect(finalConnectionUrl, {
|
||||||
useNewUrlParser: true,
|
useNewUrlParser: true,
|
||||||
useUnifiedTopology: true,
|
useUnifiedTopology: true,
|
||||||
|
maxPoolSize: 100,
|
||||||
|
maxIdleTimeMS: 10
|
||||||
});
|
});
|
||||||
this.mongoDb = this.mongoDbClient.db(this.smartdataOptions.mongoDbName);
|
this.mongoDb = this.mongoDbClient.db(this.smartdataOptions.mongoDbName);
|
||||||
this.status = 'connected';
|
this.status = 'connected';
|
||||||
|
@ -89,7 +89,9 @@ export class SmartDataDbDoc<T, TImplements> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async getInstances<T>(filterArg: Partial<T>): Promise<T[]> {
|
public static async getInstances<T>(
|
||||||
|
filterArg: plugins.tsclass.typeFest.PartialDeep<T>
|
||||||
|
): Promise<T[]> {
|
||||||
const self: any = this; // fool typesystem
|
const self: any = this; // fool typesystem
|
||||||
let referenceMongoDBCollection: SmartdataCollection<T>;
|
let referenceMongoDBCollection: SmartdataCollection<T>;
|
||||||
|
|
||||||
@ -111,7 +113,9 @@ export class SmartDataDbDoc<T, TImplements> {
|
|||||||
return returnArray;
|
return returnArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async getInstance<T>(filterArg: Partial<T>): Promise<T> {
|
public static async getInstance<T>(
|
||||||
|
filterArg: plugins.tsclass.typeFest.PartialDeep<T>
|
||||||
|
): Promise<T> {
|
||||||
const result = await this.getInstances<T>(filterArg);
|
const result = await this.getInstances<T>(filterArg);
|
||||||
if (result && result.length > 0) {
|
if (result && result.length > 0) {
|
||||||
return result[0];
|
return result[0];
|
||||||
|
@ -1,4 +1,9 @@
|
|||||||
import * as assert from 'assert';
|
// tsclass scope
|
||||||
|
import * as tsclass from '@tsclass/tsclass';
|
||||||
|
|
||||||
|
export { tsclass };
|
||||||
|
|
||||||
|
// @pushrocks scope
|
||||||
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';
|
||||||
@ -6,4 +11,4 @@ import * as smartq from '@pushrocks/smartpromise';
|
|||||||
import * as smartstring from '@pushrocks/smartstring';
|
import * as smartstring from '@pushrocks/smartstring';
|
||||||
import * as smartunique from '@pushrocks/smartunique';
|
import * as smartunique from '@pushrocks/smartunique';
|
||||||
|
|
||||||
export { assert, smartlog, lodash, smartq, mongodb, smartstring, smartunique };
|
export { smartlog, lodash, smartq, mongodb, smartstring, smartunique };
|
||||||
|
Reference in New Issue
Block a user