Compare commits

...

17 Commits

Author SHA1 Message Date
57d2d56d00 5.2.6 2024-06-18 20:12:15 +02:00
90751002aa fix(core): update 2024-06-18 20:12:14 +02:00
7606e074a5 5.2.5 2024-06-18 20:11:41 +02:00
7ec39e397e fix(core): update 2024-06-18 20:11:40 +02:00
21d8d3dc32 5.2.4 2024-05-31 18:47:49 +02:00
6d456955d8 fix(core): update 2024-05-31 18:47:48 +02:00
d08544c782 5.2.3 2024-05-31 18:39:34 +02:00
bda9ac8a07 fix(saveableProperties): fix issue where _createdAt and _updatedAt registered saveableProperties for all document types 2024-05-31 18:39:33 +02:00
d27dafba2b 5.2.2 2024-05-31 18:25:52 +02:00
b6594de18c fix(core): update 2024-05-31 18:25:51 +02:00
d9246cbeac update description 2024-05-29 14:12:26 +02:00
9a5864656e 5.2.1 2024-04-16 07:47:25 +02:00
307f0c7277 fix(core): update 2024-04-16 07:47:24 +02:00
62dc897e73 5.2.0 2024-04-15 18:34:14 +02:00
552b344914 feat(SmartDataDbDoc): add static .getCount({}) method 2024-04-15 18:34:13 +02:00
5a2cc2406c 5.1.2 2024-04-15 14:26:22 +02:00
73a11370b6 fix(_createdAt/_updatedAt): fields are now ISO format 2024-04-15 14:26:21 +02:00
5 changed files with 53 additions and 12 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@push.rocks/smartdata",
"version": "5.1.1",
"version": "5.2.6",
"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.",
"main": "dist_ts/index.js",
@ -13,14 +13,14 @@
},
"repository": {
"type": "git",
"url": "git+ssh://git@gitlab.com/pushrocks/smartdata.git"
"url": "https://code.foss.global/push.rocks/smartdata.git"
},
"author": "Lossless GmbH",
"license": "MIT",
"bugs": {
"url": "https://gitlab.com/pushrocks/smartdata/issues"
},
"homepage": "https://gitlab.com/pushrocks/smartdata#README",
"homepage": "https://code.foss.global/push.rocks/smartdata",
"dependencies": {
"@push.rocks/lik": "^6.0.14",
"@push.rocks/smartdelay": "^3.0.1",

View File

@ -199,12 +199,18 @@ tap.test('should store a new Truck', async () => {
const truck = new Truck('blue', 'MAN');
await truck.save();
const myTruck2 = await Truck.getInstance({ color: 'blue' });
expect(myTruck2.color).toEqual('blue');
myTruck2.color = 'red';
await myTruck2.save();
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 () => {
const cursor = await Car.getCursor({});
let counter = 0;

View File

@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@push.rocks/smartdata',
version: '5.1.1',
version: '5.2.6',
description: 'An advanced library for NoSQL data organization and manipulation using TypeScript with support for MongoDB, data validation, collections, and custom data types.'
}

View File

@ -273,6 +273,11 @@ export class SmartdataCollection<T> {
await this.mongoDbCollection.deleteOne(identifiableObject);
}
public async getCount(filterObject: any) {
await this.init();
return this.mongoDbCollection.countDocuments(filterObject);
}
/**
* checks a Doc for constraints
* if this.objectValidation is not set it passes.

View File

@ -7,6 +7,16 @@ import { SmartdataDbWatcher } from './smartdata.classes.watcher.js';
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
*/
@ -181,6 +191,17 @@ export class SmartDataDbDoc<T extends TImplements, TImplements, TManager extends
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
/**
@ -191,14 +212,19 @@ export class SmartDataDbDoc<T extends TImplements, TImplements, TManager extends
/**
* updated from db in any case where doc comes from db
*/
@svDb()
_createdAt: number = Date.now();
@globalSvDb()
_createdAt: string = (new Date()).toISOString();
/**
* will be updated everytime the doc is saved
*/
@svDb()
_updatedAt: number = Date.now();
@globalSvDb()
_updatedAt: string = (new Date()).toISOString();
/**
* an array of saveable properties of ALL doc
*/
public globalSaveableProperties: string[];
/**
* unique indexes
@ -206,7 +232,7 @@ export class SmartDataDbDoc<T extends TImplements, TImplements, TManager extends
public uniqueIndexes: string[];
/**
* an array of saveable properties of a doc
* an array of saveable properties of a specific doc
*/
public saveableProperties: string[];
@ -234,7 +260,7 @@ export class SmartDataDbDoc<T extends TImplements, TImplements, TManager extends
const self: any = this;
let dbResult: any;
this._updatedAt = Date.now();
this._updatedAt = (new Date()).toISOString();
switch (this.creationStatus) {
case 'db':
@ -290,7 +316,11 @@ export class SmartDataDbDoc<T extends TImplements, TImplements, TManager extends
*/
public async createSavableObject(): Promise<TImplements> {
const saveableObject: unknown = {}; // is not exposed to outside, so any is ok here
for (const propertyNameString of this.saveableProperties) {
const saveableProperties = [
...this.globalSaveableProperties,
...this.saveableProperties
]
for (const propertyNameString of saveableProperties) {
saveableObject[propertyNameString] = this[propertyNameString];
}
return saveableObject as TImplements;