Compare commits

..

14 Commits

Author SHA1 Message Date
df02e5bb71 4.0.26 2021-11-12 19:16:11 +01:00
38e438c54f fix(core): update 2021-11-12 19:16:11 +01:00
11bc1ac6dc 4.0.25 2021-11-12 19:03:06 +01:00
3431e94ddd fix(core): update 2021-11-12 19:03:06 +01:00
739e040776 4.0.24 2021-11-12 19:02:29 +01:00
28d57efd9e fix(core): update 2021-11-12 19:02:29 +01:00
f50a61308c 4.0.23 2021-11-12 18:12:59 +01:00
42aa9f9f8a fix(core): update 2021-11-12 18:12:59 +01:00
3f591ff9d8 4.0.22 2021-11-12 18:04:08 +01:00
7b33347b4c fix(core): update 2021-11-12 18:04:08 +01:00
3f11cbf595 4.0.21 2021-11-12 17:32:43 +01:00
cf1ec7f9eb fix(core): update 2021-11-12 17:32:43 +01:00
54060deb8f 4.0.20 2021-11-12 17:22:32 +01:00
48cffb5ac2 fix(core): update 2021-11-12 17:22:31 +01:00
10 changed files with 5035 additions and 3355 deletions

View File

@ -13,7 +13,6 @@ stages:
- metadata
before_script:
- apt-get update && apt-get install -y libcurl3 libssl-dev openssl libssl1.0.0 mongodb
- npm install -g @shipzone/npmci
# ====================

8244
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartdata",
"version": "4.0.19",
"version": "4.0.26",
"private": false,
"description": "do more with data",
"main": "dist_ts/index.js",
@ -21,27 +21,27 @@
},
"homepage": "https://gitlab.com/pushrocks/smartdata#README",
"dependencies": {
"@pushrocks/lik": "^4.0.20",
"@pushrocks/smartlog": "^2.0.39",
"@pushrocks/lik": "^5.0.0",
"@pushrocks/smartlog": "^2.0.44",
"@pushrocks/smartpromise": "^3.1.5",
"@pushrocks/smartstring": "^3.0.24",
"@pushrocks/smartunique": "^3.0.3",
"@tsclass/tsclass": "^3.0.33",
"@types/lodash": "^4.14.169",
"@types/mongodb": "^3.6.12",
"@tsclass/tsclass": "^3.0.36",
"@types/lodash": "^4.14.176",
"@types/mongodb": "^4.0.7",
"lodash": "^4.17.21",
"mongodb": "^3.6.6",
"mongodb": "^4.1.4",
"runtime-type-checks": "0.0.4"
},
"devDependencies": {
"@gitzone/tsbuild": "^2.1.25",
"@gitzone/tstest": "^1.0.54",
"@gitzone/tsbuild": "^2.1.28",
"@gitzone/tstest": "^1.0.60",
"@pushrocks/qenv": "^4.0.10",
"@pushrocks/tapbundle": "^3.2.14",
"@types/mongodb-memory-server": "^2.3.0",
"@types/node": "^15.3.0",
"@types/node": "^16.11.7",
"@types/shortid": "0.0.29",
"mongodb-memory-server": "^6.9.6",
"mongodb-memory-server": "^8.0.2",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0"
},

View File

@ -20,22 +20,26 @@ let smartdataOptions: smartdata.IMongoDescriptor;
let mongod: mongoPlugin.MongoMemoryServer;
tap.test('should create a testinstance as database', async () => {
mongod = new mongoPlugin.MongoMemoryServer({});
mongod = await mongoPlugin.MongoMemoryServer.create();
console.log('created mongod instance');
await mongod._startUpInstance().catch((err) => {
console.log(err);
});
console.log('mongod started');
smartdataOptions = {
mongoDbName: await mongod.getDbName(),
mongoDbPass: '',
mongoDbUrl: await mongod.getUri(),
mongoDbUrl: mongod.getUri(),
};
console.log(smartdataOptions);
testDb = new smartdata.SmartdataDb(smartdataOptions);
await testDb.init();
});
tap.skip.test('should connect to atlas', async (tools) => {
const databaseName = `test-smartdata-${smartunique.shortId()}`;
testDb = new smartdata.SmartdataDb({
mongoDbUrl: testQenv.getEnvVarOnDemand('MONGO_URL'),
mongoDbName: databaseName,
});
await testDb.init();
});
let easyStore: smartdata.EasyStore<{
key1: string;
key2: string;
@ -49,11 +53,12 @@ tap.test('should create an easystore', async () => {
});
tap.test('close', async () => {
testDb.close();
mongod.stop();
setTimeout(() => {
process.exit(0);
}, 1000);
if (mongod) {
await mongod.stop();
} else {
await testDb.mongoDb.dropDatabase();
}
await testDb.close();
});
tap.start();

View File

@ -21,31 +21,24 @@ let mongod: mongoPlugin.MongoMemoryServer;
const totalCars = 2000;
tap.skip.test('should create a testinstance as database', async () => {
mongod = new mongoPlugin.MongoMemoryServer({});
tap.test('should create a testinstance as database', async () => {
mongod = await mongoPlugin.MongoMemoryServer.create();
console.log('created mongod instance');
await mongod._startUpInstance().catch((err) => {
console.log(err);
});
console.log('mongod started');
smartdataOptions = {
mongoDbName: await mongod.getDbName(),
mongoDbPass: '',
mongoDbUrl: await mongod.getUri(),
mongoDbUrl: mongod.getUri(),
};
console.log(smartdataOptions);
testDb = new smartdata.SmartdataDb(smartdataOptions);
await testDb.init();
});
tap.test('should connect to atlas', async (tools) => {
tap.skip.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();
});
@ -209,7 +202,7 @@ tap.test('should store a new Truck', async () => {
tap.test('should use a cursor', async () => {
const cursor = await Truck.getCursor({});
cursor.forEach(async truckArg => {
cursor.forEach(async (truckArg) => {
console.log(truckArg.id);
});
});
@ -217,12 +210,13 @@ tap.test('should use a cursor', async () => {
// =======================================
// close the database connection
// =======================================
tap.test('should drop the db and close the database connection', async (tools) => {
await testDb.mongoDb.dropDatabase();
await testDb.close();
try {
tap.test('close', async () => {
if (mongod) {
await mongod.stop();
} catch (e) {}
} else {
await testDb.mongoDb.dropDatabase();
}
await testDb.close();
});
tap.start({ throwOnError: true });

View File

@ -21,31 +21,24 @@ let mongod: mongoPlugin.MongoMemoryServer;
const totalCars = 2000;
tap.skip.test('should create a testinstance as database', async () => {
mongod = new mongoPlugin.MongoMemoryServer({});
tap.test('should create a testinstance as database', async () => {
mongod = await mongoPlugin.MongoMemoryServer.create();
console.log('created mongod instance');
await mongod._startUpInstance().catch((err) => {
console.log(err);
});
console.log('mongod started');
smartdataOptions = {
mongoDbName: await mongod.getDbName(),
mongoDbPass: '',
mongoDbUrl: await mongod.getUri(),
mongoDbUrl: mongod.getUri(),
};
console.log(smartdataOptions);
testDb = new smartdata.SmartdataDb(smartdataOptions);
await testDb.init();
});
tap.test('should connect to atlas', async (tools) => {
tap.skip.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();
});
@ -99,12 +92,13 @@ tap.test('should get a car', async () => {
// =======================================
// close the database connection
// =======================================
tap.test('should close the database connection', async (tools) => {
await testDb.mongoDb.dropDatabase();
await testDb.close();
try {
tap.test('close', async () => {
if (mongod) {
await mongod.stop();
} catch (e) {}
} else {
await testDb.mongoDb.dropDatabase();
}
await testDb.close();
});
tap.start({ throwOnError: true });

View File

@ -85,7 +85,7 @@ export function Manager<TManager extends IManager>(managerArg?: TManager | TDela
public static get manager() {
let manager: TManager;
if (!managerArg) {
manager = this.prototype.defaultManager
manager = this.prototype.defaultManager;
} else if (managerArg['db']) {
manager = managerArg as TManager;
} else {
@ -96,7 +96,7 @@ export function Manager<TManager extends IManager>(managerArg?: TManager | TDela
public get manager() {
let manager: TManager;
if (!managerArg) {
manager = this.defaultManager
manager = this.defaultManager;
} else if (managerArg['db']) {
manager = managerArg as TManager;
} else {
@ -171,7 +171,7 @@ export class SmartdataCollection<T> {
/**
* finds an object in the DbCollection
*/
public async findOne(filterObject: any): Promise<any> {
public async findOne(filterObject: any): Promise<any> {
await this.init();
const cursor = this.mongoDbCollection.find(filterObject);
const result = await cursor.next();
@ -235,9 +235,7 @@ export class SmartdataCollection<T> {
await this.init();
await this.checkDoc(dbDocArg);
const identifiableObject = await dbDocArg.createIdentifiableObject();
await this.mongoDbCollection.deleteOne(identifiableObject, {
w: 1,
});
await this.mongoDbCollection.deleteOne(identifiableObject);
}
/**

View File

@ -7,18 +7,18 @@ export class SmartdataDbCursor<T = any> {
// STATIC
// INSTANCE
public mongodbCursor: plugins.mongodb.Cursor<T>;
constructor(cursorArg: plugins.mongodb.Cursor<T>) {
this.mongodbCursor = cursorArg
};
public mongodbCursor: plugins.mongodb.FindCursor<T>;
constructor(cursorArg: plugins.mongodb.FindCursor<T>) {
this.mongodbCursor = cursorArg;
}
public async next(closeAtEnd = true) {
const result = await this.mongodbCursor.next();
if (!result && closeAtEnd) {
await this.close();
};
}
return result;
};
}
public async forEach(forEachFuncArg: (itemArg: T) => Promise<any>, closeCursorAtEnd = true) {
let currentValue: T;

View File

@ -47,8 +47,6 @@ export class SmartdataDb {
.replace('<dbname>', this.smartdataOptions.mongoDbName);
this.mongoDbClient = await plugins.mongodb.MongoClient.connect(finalConnectionUrl, {
useNewUrlParser: true,
useUnifiedTopology: true,
maxPoolSize: 100,
maxIdleTimeMS: 10,
});
@ -78,7 +76,7 @@ export class SmartdataDb {
* @returns DbTable
*/
public async getSmartdataCollectionByName<T>(nameArg: string): Promise<SmartdataCollection<T>> {
const resultCollection = this.smartdataCollectionMap.find((dbTableArg) => {
const resultCollection = await this.smartdataCollectionMap.find(async (dbTableArg) => {
return dbTableArg.collectionName === nameArg;
});
return resultCollection;

View File

@ -165,7 +165,9 @@ export class SmartDataDbDoc<T extends TImplements, TImplements, TManager extends
this: plugins.tsclass.typeFest.Class<T>,
filterArg: plugins.tsclass.typeFest.PartialDeep<T>
) {
const cursor: SmartdataDbCursor<T> = await (this as any).collection.getCursor(convertFilterForMongoDb(filterArg));
const cursor: SmartdataDbCursor<T> = await (this as any).collection.getCursor(
convertFilterForMongoDb(filterArg)
);
return cursor;
}
@ -179,7 +181,7 @@ export class SmartDataDbDoc<T extends TImplements, TImplements, TManager extends
forEachFunction: (itemArg: T) => Promise<any>
) {
const cursor: SmartdataDbCursor<T> = await (this as any).getCursor(filterArg);
await cursor.forEach(forEachFunction)
await cursor.forEach(forEachFunction);
}
/**