Compare commits
18 Commits
Author | SHA1 | Date | |
---|---|---|---|
6dce9f3ff8 | |||
2f6a4ce3e5 | |||
0984a1ade4 | |||
804701c96a | |||
a3759fa484 | |||
ef38df62be | |||
c17789e92e | |||
0bf2ba554d | |||
5cbf1a222a | |||
f075530838 | |||
efb83853fb | |||
73300ca4d3 | |||
1e946cdceb | |||
608ff93a41 | |||
6211953f14 | |||
99e520b776 | |||
eda8297356 | |||
ffa52a5883 |
30
package-lock.json
generated
30
package-lock.json
generated
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@pushrocks/smartdata",
|
||||
"version": "3.1.30",
|
||||
"version": "3.1.39",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
@ -2163,6 +2163,7 @@
|
||||
"version": "3.0.3",
|
||||
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartunique/-/smartunique-3.0.3.tgz",
|
||||
"integrity": "sha512-f+c3s2WzzjASoRHyYTLU0kHDVWREg4sZVdi5L42bTA3CTUWNrcGUC62h4wP4U4BiPl3bopTr3LPhClZHJ738oA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/shortid": "0.0.29",
|
||||
"@types/uuid": "^7.0.0",
|
||||
@ -2627,7 +2628,8 @@
|
||||
"@types/shortid": {
|
||||
"version": "0.0.29",
|
||||
"resolved": "https://verdaccio.lossless.one/@types%2fshortid/-/shortid-0.0.29.tgz",
|
||||
"integrity": "sha1-gJPuBBam4r8qpjOBCRFLP7/6Dps="
|
||||
"integrity": "sha1-gJPuBBam4r8qpjOBCRFLP7/6Dps=",
|
||||
"dev": true
|
||||
},
|
||||
"@types/through2": {
|
||||
"version": "2.0.34",
|
||||
@ -2664,7 +2666,8 @@
|
||||
"@types/uuid": {
|
||||
"version": "7.0.4",
|
||||
"resolved": "https://verdaccio.lossless.one/@types%2fuuid/-/uuid-7.0.4.tgz",
|
||||
"integrity": "sha512-WGZCqBZZ0mXN2RxvLHL6/7RCu+OWs28jgQMP04LWfpyJlQUMTR6YU9CNJAKDgbw+EV/u687INXuLUc7FuML/4g=="
|
||||
"integrity": "sha512-WGZCqBZZ0mXN2RxvLHL6/7RCu+OWs28jgQMP04LWfpyJlQUMTR6YU9CNJAKDgbw+EV/u687INXuLUc7FuML/4g==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/which": {
|
||||
"version": "1.3.2",
|
||||
@ -7915,18 +7918,18 @@
|
||||
}
|
||||
},
|
||||
"mongodb-memory-server": {
|
||||
"version": "6.6.4",
|
||||
"resolved": "https://verdaccio.lossless.one/mongodb-memory-server/-/mongodb-memory-server-6.6.4.tgz",
|
||||
"integrity": "sha512-GCtrlUDpq6oPkdlkmIgh0Q6vJYf7njzw8AJnbg/gime2NxuUtqcOK2n+9L3qeDzt6EZxdtP/+1u/80wfjwc5mA==",
|
||||
"version": "6.6.3",
|
||||
"resolved": "https://verdaccio.lossless.one/mongodb-memory-server/-/mongodb-memory-server-6.6.3.tgz",
|
||||
"integrity": "sha512-zx91SQQUBafVfBX8IJjfZa0lIMzdDYs/UB1vnr33e5bSPBwSai+mVV6gW3osF4paLFxOkcvOwx758G9F9HytgA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"mongodb-memory-server-core": "6.6.4"
|
||||
"mongodb-memory-server-core": "6.6.3"
|
||||
}
|
||||
},
|
||||
"mongodb-memory-server-core": {
|
||||
"version": "6.6.4",
|
||||
"resolved": "https://verdaccio.lossless.one/mongodb-memory-server-core/-/mongodb-memory-server-core-6.6.4.tgz",
|
||||
"integrity": "sha512-g4WMmXp2Gg305eKETaE9Nnp2eR3mTMKSTZJsxpXhsx+Mhl2IQoMLa78ny7eFPN7FORnLxQsmLMANv4b0bP+RDA==",
|
||||
"version": "6.6.3",
|
||||
"resolved": "https://verdaccio.lossless.one/mongodb-memory-server-core/-/mongodb-memory-server-core-6.6.3.tgz",
|
||||
"integrity": "sha512-MTs2qCb+5JG4qPCenqo+L0cxQiO09EqTZNk4I5+dz8nRUiVPFLL64tO/oJ1WDuSJ6vcyk8dC+QsNAD1wjZxx8g==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/cross-spawn": "^6.0.2",
|
||||
@ -8071,7 +8074,8 @@
|
||||
"nanoid": {
|
||||
"version": "2.1.11",
|
||||
"resolved": "https://verdaccio.lossless.one/nanoid/-/nanoid-2.1.11.tgz",
|
||||
"integrity": "sha512-s/snB+WGm6uwi0WjsZdaVcuf3KJXlfGl2LcxgwkEwJF0D/BWzVWAZW/XY4bFaiR7s0Jk3FPvlnepg1H1b1UwlA=="
|
||||
"integrity": "sha512-s/snB+WGm6uwi0WjsZdaVcuf3KJXlfGl2LcxgwkEwJF0D/BWzVWAZW/XY4bFaiR7s0Jk3FPvlnepg1H1b1UwlA==",
|
||||
"dev": true
|
||||
},
|
||||
"nanomatch": {
|
||||
"version": "1.2.13",
|
||||
@ -10141,6 +10145,7 @@
|
||||
"version": "2.2.15",
|
||||
"resolved": "https://verdaccio.lossless.one/shortid/-/shortid-2.2.15.tgz",
|
||||
"integrity": "sha512-5EaCy2mx2Jgc/Fdn9uuDuNIIfWBpzY4XIlhoqtXF6qsf+/+SGZ+FxDdX/ZsMZiWupIWNqAEmiNY4RC+LSmCeOw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"nanoid": "^2.1.0"
|
||||
}
|
||||
@ -11268,7 +11273,8 @@
|
||||
"uuid": {
|
||||
"version": "7.0.3",
|
||||
"resolved": "https://verdaccio.lossless.one/uuid/-/uuid-7.0.3.tgz",
|
||||
"integrity": "sha512-DPSke0pXhTZgoF/d+WSt2QaKMCFSfx7QegxEWT+JOuHF5aWrKEn0G+ztjuJg/gG8/ItK+rbPCD/yNv8yyih6Cg=="
|
||||
"integrity": "sha512-DPSke0pXhTZgoF/d+WSt2QaKMCFSfx7QegxEWT+JOuHF5aWrKEn0G+ztjuJg/gG8/ItK+rbPCD/yNv8yyih6Cg==",
|
||||
"dev": true
|
||||
},
|
||||
"v8-compile-cache": {
|
||||
"version": "2.1.1",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@pushrocks/smartdata",
|
||||
"version": "3.1.30",
|
||||
"version": "3.1.39",
|
||||
"private": false,
|
||||
"description": "do more with data",
|
||||
"main": "dist_ts/index.js",
|
||||
@ -25,7 +25,6 @@
|
||||
"@pushrocks/smartlog": "^2.0.36",
|
||||
"@pushrocks/smartpromise": "^3.0.6",
|
||||
"@pushrocks/smartstring": "^3.0.18",
|
||||
"@pushrocks/smartunique": "^3.0.3",
|
||||
"@types/lodash": "^4.14.159",
|
||||
"@types/mongodb": "^3.5.26",
|
||||
"lodash": "^4.17.20",
|
||||
@ -36,11 +35,12 @@
|
||||
"@gitzone/tsbuild": "^2.1.25",
|
||||
"@gitzone/tstest": "^1.0.44",
|
||||
"@pushrocks/qenv": "^4.0.10",
|
||||
"@pushrocks/smartunique": "^3.0.3",
|
||||
"@pushrocks/tapbundle": "^3.2.9",
|
||||
"@types/mongodb-memory-server": "^2.3.0",
|
||||
"@types/node": "^14.6.0",
|
||||
"@types/shortid": "0.0.29",
|
||||
"mongodb-memory-server": "^6.6.4",
|
||||
"mongodb-memory-server": "6.6.3",
|
||||
"tslint": "^6.1.3",
|
||||
"tslint-config-prettier": "^1.18.0"
|
||||
},
|
||||
|
28
test/test.ts
28
test/test.ts
@ -5,21 +5,26 @@ const testQenv = new Qenv(process.cwd(), process.cwd() + '/.nogit/');
|
||||
|
||||
// the tested module
|
||||
import * as smartdata from '../ts/index';
|
||||
import { smartstring } from '../ts/smartdata.plugins';
|
||||
import * as smartunique from '@pushrocks/smartunique';
|
||||
|
||||
import * as mongoPlugin from 'mongodb-memory-server';
|
||||
import { smartunique } from '../ts/smartdata.plugins';
|
||||
|
||||
// =======================================
|
||||
// Connecting to the database server
|
||||
// =======================================
|
||||
|
||||
let testDb: smartdata.SmartdataDb;
|
||||
let smartdataOptions: smartdata.ISmartdataOptions;
|
||||
let smartdataOptions: smartdata.IMongoDescriptor;
|
||||
let mongod: mongoPlugin.MongoMemoryServer;
|
||||
|
||||
tap.test('should create a testinstance as database', async () => {
|
||||
mongod = new mongoPlugin.MongoMemoryServer();
|
||||
tap.skip.test('should create a testinstance as database', async () => {
|
||||
mongod = new mongoPlugin.MongoMemoryServer({
|
||||
});
|
||||
console.log('created mongod instance');
|
||||
await mongod._startUpInstance().catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
console.log('mongod started');
|
||||
smartdataOptions = {
|
||||
mongoDbName: await mongod.getDbName(),
|
||||
mongoDbPass: '',
|
||||
@ -29,7 +34,15 @@ tap.test('should create a testinstance as database', async () => {
|
||||
testDb = new smartdata.SmartdataDb(smartdataOptions);
|
||||
});
|
||||
|
||||
tap.test('should establish a connection to the rethink Db cluster', async () => {
|
||||
tap.test('should connect to atlas', async (tools) => {
|
||||
const databaseName = `test-smartdata-${smartunique.shortId()}`;
|
||||
testDb = new smartdata.SmartdataDb({
|
||||
mongoDbUrl: testQenv.getEnvVarOnDemand('MONGO_URL'),
|
||||
mongoDbName: databaseName
|
||||
});
|
||||
});
|
||||
|
||||
tap.test('should establish a connection to mongod', async () => {
|
||||
await testDb.init();
|
||||
});
|
||||
|
||||
@ -137,7 +150,10 @@ tap.test('should store a new Truck', async () => {
|
||||
// =======================================
|
||||
tap.test('should close the database connection', async (tools) => {
|
||||
await testDb.close();
|
||||
try {
|
||||
|
||||
await mongod.stop();
|
||||
} catch (e) {}
|
||||
});
|
||||
|
||||
tap.start({ throwOnError: true });
|
||||
|
@ -1,5 +1,22 @@
|
||||
export interface IMongoDescriptor {
|
||||
mongoDbName: string;
|
||||
/**
|
||||
* the URL to connect to
|
||||
*/
|
||||
mongoDbUrl: string;
|
||||
mongoDbPass: string;
|
||||
|
||||
/**
|
||||
* the db to use for the project
|
||||
*/
|
||||
mongoDbName?: string;
|
||||
|
||||
/**
|
||||
* a username to use to connect to the database
|
||||
*/
|
||||
|
||||
mongoDbUser?: string;
|
||||
|
||||
/**
|
||||
* an optional password that will be replace <PASSWORD> in the connection string
|
||||
*/
|
||||
mongoDbPass?: string;
|
||||
}
|
||||
|
@ -4,43 +4,21 @@ import { ObjectMap } from '@pushrocks/lik';
|
||||
import { SmartdataCollection } from './smartdata.classes.collection';
|
||||
|
||||
import { logger } from './smartdata.logging';
|
||||
import { IMongoDescriptor } from './interfaces';
|
||||
|
||||
/**
|
||||
* interface - indicates the connection status of the db
|
||||
*/
|
||||
export type TConnectionStatus = 'initial' | 'disconnected' | 'connected' | 'failed';
|
||||
|
||||
export interface ISmartdataOptions {
|
||||
/**
|
||||
* the URL to connect to
|
||||
*/
|
||||
mongoDbUrl: string;
|
||||
|
||||
/**
|
||||
* the db to use for the project
|
||||
*/
|
||||
mongoDbName?: string;
|
||||
|
||||
/**
|
||||
* a username to use to connect to the database
|
||||
*/
|
||||
|
||||
mongoDbUser?: string;
|
||||
|
||||
/**
|
||||
* an optional password that will be replace <PASSWORD> in the connection string
|
||||
*/
|
||||
mongoDbPass?: string;
|
||||
}
|
||||
|
||||
export class SmartdataDb {
|
||||
smartdataOptions: ISmartdataOptions;
|
||||
smartdataOptions: IMongoDescriptor;
|
||||
mongoDbClient: plugins.mongodb.MongoClient;
|
||||
mongoDb: plugins.mongodb.Db;
|
||||
status: TConnectionStatus;
|
||||
smartdataCollectionMap = new ObjectMap<SmartdataCollection<any>>();
|
||||
|
||||
constructor(smartdataOptions: ISmartdataOptions) {
|
||||
constructor(smartdataOptions: IMongoDescriptor) {
|
||||
this.smartdataOptions = smartdataOptions;
|
||||
this.status = 'initial';
|
||||
}
|
||||
|
Reference in New Issue
Block a user