fix(core): update

This commit is contained in:
Philipp Kunz 2021-10-16 21:17:02 +02:00
parent 7cbd0bd99b
commit 7a4d557724
10 changed files with 33 additions and 32 deletions

View File

@ -12,6 +12,10 @@ stages:
- release - release
- metadata - metadata
before_script:
- apt-get update && apt-get install -y libcurl3 libssl-dev openssl libssl1.0.0 mongodb
- npm install -g @shipzone/npmci
# ==================== # ====================
# security stage # security stage
# ==================== # ====================
@ -36,6 +40,7 @@ auditProductionDependencies:
- npmci command npm audit --audit-level=high --only=prod --production - npmci command npm audit --audit-level=high --only=prod --production
tags: tags:
- docker - docker
allow_failure: true
auditDevDependencies: auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci image: registry.gitlab.com/hosttoday/ht-docker-node:npmci

View File

@ -90,7 +90,7 @@ class MyObject extends smartdata.DbDoc<MyObject /* ,[an optional interface to im
const localObject = new MyObject({ const localObject = new MyObject({
property1: 'hi', property1: 'hi',
property2: { property2: {
deep: 3 deep: 3,
}, },
}); });
await localObject.save(); // saves the object to the database await localObject.save(); // saves the object to the database
@ -102,9 +102,9 @@ const myInstance = await MyObject.getInstance({
property1: 'hi', property1: 'hi',
property2: { property2: {
deep: { deep: {
$gt: 2 $gt: 2,
} as any } as any,
} },
}); // outputs a new instance of MyObject with the values from db assigned }); // outputs a new instance of MyObject with the values from db assigned
``` ```

View File

@ -19,7 +19,6 @@ let testDb: smartdata.SmartdataDb;
let smartdataOptions: smartdata.IMongoDescriptor; let smartdataOptions: smartdata.IMongoDescriptor;
let mongod: mongoPlugin.MongoMemoryServer; let mongod: mongoPlugin.MongoMemoryServer;
tap.test('should create a testinstance as database', async () => { tap.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');
@ -47,14 +46,14 @@ tap.test('should create an easystore', async () => {
await easyStore.writeKey('key1', 'hello'); await easyStore.writeKey('key1', 'hello');
const retrievedKey = await easyStore.readKey('key1'); const retrievedKey = await easyStore.readKey('key1');
expect(retrievedKey).to.equal('hello'); expect(retrievedKey).to.equal('hello');
}) });
tap.test('close', async () => { tap.test('close', async () => {
testDb.close(); testDb.close();
mongod.stop(); mongod.stop();
setTimeout(() => { setTimeout(() => {
process.exit(0); process.exit(0);
}, 1000) }, 1000);
}) });
tap.start(); tap.start();

View File

@ -134,7 +134,7 @@ tap.test('expect to get instance of Car with deep match', async () => {
const timeStart = Date.now(); const timeStart = Date.now();
const myCars2 = await Car.getInstances({ const myCars2 = await Car.getInstances({
deepData: { deepData: {
sodeep: 'yes' sodeep: 'yes',
}, },
}); });
if (counter % 10 === 0) { if (counter % 10 === 0) {
@ -207,7 +207,7 @@ tap.test('should store a new Truck', async () => {
console.log(myTruck2); console.log(myTruck2);
}); });
tap.test('should ', async () => {}) tap.test('should ', async () => {});
// ======================================= // =======================================
// close the database connection // close the database connection

View File

@ -80,7 +80,7 @@ class Car extends smartdata.SmartDataDbDoc<Car, Car> {
} }
const createCarClass = (dbArg: smartdata.SmartdataDb) => { const createCarClass = (dbArg: smartdata.SmartdataDb) => {
smartdata.setDefaultManagerForDoc({db: dbArg}, Car); smartdata.setDefaultManagerForDoc({ db: dbArg }, Car);
return Car; return Car;
}; };
@ -92,9 +92,9 @@ tap.test('should produce a car', async () => {
tap.test('should get a car', async () => { tap.test('should get a car', async () => {
const car = Car.getInstance({ const car = Car.getInstance({
color: 'red' color: 'red',
}) });
}) });
// ======================================= // =======================================
// close the database connection // close the database connection

View File

@ -42,19 +42,19 @@ export function Collection(dbArg: SmartdataDb | TDelayed<SmartdataDb>) {
} }
export interface IManager { export interface IManager {
db: SmartdataDb db: SmartdataDb;
} }
export const setDefaultManagerForDoc = <T>(managerArg: IManager, dbDocArg: T): T => { export const setDefaultManagerForDoc = <T>(managerArg: IManager, dbDocArg: T): T => {
(dbDocArg as any).prototype.defaultManager = managerArg; (dbDocArg as any).prototype.defaultManager = managerArg;
return dbDocArg; return dbDocArg;
} };
/** /**
* This is a decorator that will tell the decorated class what dbTable to use * This is a decorator that will tell the decorated class what dbTable to use
* @param dbArg * @param dbArg
*/ */
export function Manager<TManager extends IManager>(managerArg?: TManager | TDelayed<TManager>) { export function Manager<TManager extends IManager>(managerArg?: TManager | TDelayed<TManager>) {
return function classDecorator<T extends { new (...args: any[]): any }>(constructor: T) { return function classDecorator<T extends { new (...args: any[]): any }>(constructor: T) {
return class extends constructor { return class extends constructor {
public static get collection() { public static get collection() {
@ -62,7 +62,7 @@ export const setDefaultManagerForDoc = <T>(managerArg: IManager, dbDocArg: T):
if (!managerArg) { if (!managerArg) {
dbArg = this.prototype.defaultManager.db; dbArg = this.prototype.defaultManager.db;
} else if (managerArg['db']) { } else if (managerArg['db']) {
dbArg = (managerArg as TManager).db dbArg = (managerArg as TManager).db;
} else { } else {
dbArg = (managerArg as TDelayed<TManager>)().db; dbArg = (managerArg as TDelayed<TManager>)().db;
} }
@ -75,7 +75,7 @@ export const setDefaultManagerForDoc = <T>(managerArg: IManager, dbDocArg: T):
//process.exit(0) //process.exit(0)
dbArg = this.defaultManager.db; dbArg = this.defaultManager.db;
} else if (managerArg['db']) { } else if (managerArg['db']) {
dbArg = (managerArg as TManager).db dbArg = (managerArg as TManager).db;
} else { } else {
dbArg = (managerArg as TDelayed<TManager>)().db; dbArg = (managerArg as TDelayed<TManager>)().db;
} }
@ -84,7 +84,7 @@ export const setDefaultManagerForDoc = <T>(managerArg: IManager, dbDocArg: T):
public static get manager() { public static get manager() {
let manager: TManager; let manager: TManager;
if (managerArg['db']) { if (managerArg['db']) {
manager = (managerArg as TManager); manager = managerArg as TManager;
} else { } else {
manager = (managerArg as TDelayed<TManager>)(); manager = (managerArg as TDelayed<TManager>)();
} }
@ -93,7 +93,7 @@ export const setDefaultManagerForDoc = <T>(managerArg: IManager, dbDocArg: T):
public get manager() { public get manager() {
let manager: TManager; let manager: TManager;
if (managerArg['db']) { if (managerArg['db']) {
manager = (managerArg as TManager); manager = managerArg as TManager;
} else { } else {
manager = (managerArg as TDelayed<TManager>)(); manager = (managerArg as TDelayed<TManager>)();
} }

View File

@ -5,10 +5,7 @@ import { SmartdataDb } from './smartdata.classes.db';
export class CollectionFactory { export class CollectionFactory {
public collections: { [key: string]: SmartdataCollection<any> } = {}; public collections: { [key: string]: SmartdataCollection<any> } = {};
public getCollection = ( public getCollection = (nameArg: string, dbArg: SmartdataDb): SmartdataCollection<any> => {
nameArg: string,
dbArg: SmartdataDb
): SmartdataCollection<any> => {
if (!this.collections[nameArg]) { if (!this.collections[nameArg]) {
this.collections[nameArg] = (() => { this.collections[nameArg] = (() => {
if (dbArg instanceof SmartdataDb) { if (dbArg instanceof SmartdataDb) {

View File

@ -100,9 +100,9 @@ export class SmartDataDbDoc<T extends TImplements, TImplements, TManager extends
convertFilterArgument(`${keyPathArg}.${key}`, filterArg2[key]); convertFilterArgument(`${keyPathArg}.${key}`, filterArg2[key]);
} }
} else { } else {
convertedFilter[keyPathArg] = filterArg2 convertedFilter[keyPathArg] = filterArg2;
} }
} };
for (const key of Object.keys(filterArg)) { for (const key of Object.keys(filterArg)) {
convertFilterArgument(key, filterArg[key]); convertFilterArgument(key, filterArg[key]);
} }

View File

@ -30,7 +30,7 @@ export class EasyStore<T> {
public async getEasyStore() { public async getEasyStore() {
let easyStore = await this.easyStoreClass.getInstance({ let easyStore = await this.easyStoreClass.getInstance({
nameId: this.nameId nameId: this.nameId,
}); });
if (!easyStore) { if (!easyStore) {