fix(core): update

This commit is contained in:
Philipp Kunz 2024-03-27 17:30:14 +01:00
parent 00ec2e57c2
commit 4cd284eaa9
4 changed files with 13 additions and 4 deletions

View File

@ -72,6 +72,11 @@ class Car extends smartdata.SmartDataDbDoc<Car, Car> {
} }
} }
tap.test('should create a new id', async () => {
const newid = await Car.getNewId();
console.log(newid);
})
tap.test('should save the car to the db', async (toolsArg) => { tap.test('should save the car to the db', async (toolsArg) => {
const myCar = new Car('red', 'Volvo'); const myCar = new Car('red', 'Volvo');
await myCar.save(); await myCar.save();

View File

@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@push.rocks/smartdata', name: '@push.rocks/smartdata',
version: '5.0.38', version: '5.0.39',
description: 'do more with data' description: 'do more with data'
} }

View File

@ -26,7 +26,8 @@ const collectionFactory = new CollectionFactory();
*/ */
export function Collection(dbArg: SmartdataDb | TDelayed<SmartdataDb>) { export function Collection(dbArg: SmartdataDb | TDelayed<SmartdataDb>) {
return function classDecorator<T extends { new (...args: any[]): {} }>(constructor: T) { return function classDecorator<T extends { new (...args: any[]): {} }>(constructor: T) {
return class extends constructor { const decoratedClass = class extends constructor {
public static className = constructor.name;
public static get collection() { public static get collection() {
if (!(dbArg instanceof SmartdataDb)) { if (!(dbArg instanceof SmartdataDb)) {
dbArg = dbArg(); dbArg = dbArg();
@ -40,6 +41,7 @@ export function Collection(dbArg: SmartdataDb | TDelayed<SmartdataDb>) {
return collectionFactory.getCollection(constructor.name, dbArg); return collectionFactory.getCollection(constructor.name, dbArg);
} }
}; };
return decoratedClass;
}; };
} }
@ -58,7 +60,8 @@ export const setDefaultManagerForDoc = <T>(managerArg: IManager, dbDocArg: T): T
*/ */
export function managed<TManager extends IManager>(managerArg?: TManager | TDelayed<TManager>) { export function managed<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 { const decoratedClass = class extends constructor {
public static className = constructor.name;
public static get collection() { public static get collection() {
let dbArg: SmartdataDb; let dbArg: SmartdataDb;
if (!managerArg) { if (!managerArg) {
@ -106,6 +109,7 @@ export function managed<TManager extends IManager>(managerArg?: TManager | TDela
return manager; return manager;
} }
}; };
return decoratedClass;
}; };
} }

View File

@ -131,7 +131,7 @@ export class SmartDataDbDoc<T extends TImplements, TImplements, TManager extends
* get a unique id prefixed with the class name * get a unique id prefixed with the class name
*/ */
public static async getNewId<T = any>(this: plugins.tsclass.typeFest.Class<T>, lengthArg: number = 20) { public static async getNewId<T = any>(this: plugins.tsclass.typeFest.Class<T>, lengthArg: number = 20) {
return `${this.name}:${plugins.smartunique.shortId(lengthArg)}`; return `${(this as any).className}:${plugins.smartunique.shortId(lengthArg)}`;
} }
/** /**