Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
d08544c782 | |||
bda9ac8a07 | |||
d27dafba2b | |||
b6594de18c | |||
d9246cbeac | |||
9a5864656e | |||
307f0c7277 | |||
62dc897e73 | |||
552b344914 | |||
5a2cc2406c | |||
73a11370b6 |
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@push.rocks/smartdata",
|
"name": "@push.rocks/smartdata",
|
||||||
"version": "5.1.1",
|
"version": "5.2.3",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "An advanced library for NoSQL data organization and manipulation using TypeScript with support for MongoDB, data validation, collections, and custom data types.",
|
"description": "An advanced library for NoSQL data organization and manipulation using TypeScript with support for MongoDB, data validation, collections, and custom data types.",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
@ -13,14 +13,14 @@
|
|||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+ssh://git@gitlab.com/pushrocks/smartdata.git"
|
"url": "https://code.foss.global/push.rocks/smartdata.git"
|
||||||
},
|
},
|
||||||
"author": "Lossless GmbH",
|
"author": "Lossless GmbH",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://gitlab.com/pushrocks/smartdata/issues"
|
"url": "https://gitlab.com/pushrocks/smartdata/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/smartdata#README",
|
"homepage": "https://code.foss.global/push.rocks/smartdata",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@push.rocks/lik": "^6.0.14",
|
"@push.rocks/lik": "^6.0.14",
|
||||||
"@push.rocks/smartdelay": "^3.0.1",
|
"@push.rocks/smartdelay": "^3.0.1",
|
||||||
|
@ -199,12 +199,18 @@ tap.test('should store a new Truck', async () => {
|
|||||||
const truck = new Truck('blue', 'MAN');
|
const truck = new Truck('blue', 'MAN');
|
||||||
await truck.save();
|
await truck.save();
|
||||||
const myTruck2 = await Truck.getInstance({ color: 'blue' });
|
const myTruck2 = await Truck.getInstance({ color: 'blue' });
|
||||||
|
expect(myTruck2.color).toEqual('blue');
|
||||||
myTruck2.color = 'red';
|
myTruck2.color = 'red';
|
||||||
await myTruck2.save();
|
await myTruck2.save();
|
||||||
const myTruck3 = await Truck.getInstance({ color: 'blue' });
|
const myTruck3 = await Truck.getInstance({ color: 'blue' });
|
||||||
console.log(myTruck3);
|
expect(myTruck3).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
tap.test('should return a count', async () => {
|
||||||
|
const truckCount = await Truck.getCount();
|
||||||
|
expect(truckCount).toEqual(1);
|
||||||
|
})
|
||||||
|
|
||||||
tap.test('should use a cursor', async () => {
|
tap.test('should use a cursor', async () => {
|
||||||
const cursor = await Car.getCursor({});
|
const cursor = await Car.getCursor({});
|
||||||
let counter = 0;
|
let counter = 0;
|
||||||
|
@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@push.rocks/smartdata',
|
name: '@push.rocks/smartdata',
|
||||||
version: '5.1.1',
|
version: '5.2.3',
|
||||||
description: 'An advanced library for NoSQL data organization and manipulation using TypeScript with support for MongoDB, data validation, collections, and custom data types.'
|
description: 'An advanced library for NoSQL data organization and manipulation using TypeScript with support for MongoDB, data validation, collections, and custom data types.'
|
||||||
}
|
}
|
||||||
|
@ -273,6 +273,11 @@ export class SmartdataCollection<T> {
|
|||||||
await this.mongoDbCollection.deleteOne(identifiableObject);
|
await this.mongoDbCollection.deleteOne(identifiableObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async getCount(filterObject: any) {
|
||||||
|
await this.init();
|
||||||
|
return this.mongoDbCollection.countDocuments(filterObject);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* checks a Doc for constraints
|
* checks a Doc for constraints
|
||||||
* if this.objectValidation is not set it passes.
|
* if this.objectValidation is not set it passes.
|
||||||
|
@ -7,6 +7,16 @@ import { SmartdataDbWatcher } from './smartdata.classes.watcher.js';
|
|||||||
|
|
||||||
export type TDocCreation = 'db' | 'new' | 'mixed';
|
export type TDocCreation = 'db' | 'new' | 'mixed';
|
||||||
|
|
||||||
|
export function globalSvDb() {
|
||||||
|
return (target: SmartDataDbDoc<unknown, unknown>, key: string) => {
|
||||||
|
console.log(`called svDb() on >${target.constructor.name}.${key}<`);
|
||||||
|
if (!target.globalSaveableProperties) {
|
||||||
|
target.globalSaveableProperties = [];
|
||||||
|
}
|
||||||
|
target.globalSaveableProperties.push(key);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* saveable - saveable decorator to be used on class properties
|
* saveable - saveable decorator to be used on class properties
|
||||||
*/
|
*/
|
||||||
@ -181,6 +191,17 @@ export class SmartDataDbDoc<T extends TImplements, TImplements, TManager extends
|
|||||||
await cursor.forEach(forEachFunction);
|
await cursor.forEach(forEachFunction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns a count of the documents in the collection
|
||||||
|
*/
|
||||||
|
public static async getCount<T>(
|
||||||
|
this: plugins.tsclass.typeFest.Class<T>,
|
||||||
|
filterArg: plugins.tsclass.typeFest.PartialDeep<T> = ({} as any)
|
||||||
|
) {
|
||||||
|
const collection: SmartdataCollection<T> = (this as any).collection;
|
||||||
|
return await collection.getCount(filterArg);
|
||||||
|
}
|
||||||
|
|
||||||
// INSTANCE
|
// INSTANCE
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -191,14 +212,19 @@ export class SmartDataDbDoc<T extends TImplements, TImplements, TManager extends
|
|||||||
/**
|
/**
|
||||||
* updated from db in any case where doc comes from db
|
* updated from db in any case where doc comes from db
|
||||||
*/
|
*/
|
||||||
@svDb()
|
@globalSvDb()
|
||||||
_createdAt: number = Date.now();
|
_createdAt: string = (new Date()).toISOString();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* will be updated everytime the doc is saved
|
* will be updated everytime the doc is saved
|
||||||
*/
|
*/
|
||||||
@svDb()
|
@globalSvDb()
|
||||||
_updatedAt: number = Date.now();
|
_updatedAt: string = (new Date()).toISOString();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* an array of saveable properties of ALL doc
|
||||||
|
*/
|
||||||
|
public globalSaveableProperties: string[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* unique indexes
|
* unique indexes
|
||||||
@ -206,7 +232,7 @@ export class SmartDataDbDoc<T extends TImplements, TImplements, TManager extends
|
|||||||
public uniqueIndexes: string[];
|
public uniqueIndexes: string[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* an array of saveable properties of a doc
|
* an array of saveable properties of a specific doc
|
||||||
*/
|
*/
|
||||||
public saveableProperties: string[];
|
public saveableProperties: string[];
|
||||||
|
|
||||||
@ -234,7 +260,7 @@ export class SmartDataDbDoc<T extends TImplements, TImplements, TManager extends
|
|||||||
const self: any = this;
|
const self: any = this;
|
||||||
let dbResult: any;
|
let dbResult: any;
|
||||||
|
|
||||||
this._updatedAt = Date.now();
|
this._updatedAt = (new Date()).toISOString();
|
||||||
|
|
||||||
switch (this.creationStatus) {
|
switch (this.creationStatus) {
|
||||||
case 'db':
|
case 'db':
|
||||||
|
Reference in New Issue
Block a user