fix(core): update
This commit is contained in:
parent
236c8c6551
commit
aeb35705d4
24
.vscode/launch.json
vendored
24
.vscode/launch.json
vendored
@ -2,28 +2,10 @@
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "current file",
|
||||
"type": "node",
|
||||
"command": "npm test",
|
||||
"name": "Run npm test",
|
||||
"request": "launch",
|
||||
"args": [
|
||||
"${relativeFile}"
|
||||
],
|
||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"protocol": "inspector",
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
},
|
||||
{
|
||||
"name": "test.ts",
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"args": [
|
||||
"test/test.ts"
|
||||
],
|
||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"protocol": "inspector",
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
"type": "node-terminal"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -56,7 +56,8 @@ tap.test('should establish a connection to mongod', async () => {
|
||||
// ------
|
||||
// Collections
|
||||
// ------
|
||||
class CarTemplate extends smartdata.SmartDataDbDoc<CarTemplate, CarTemplate> {
|
||||
@smartdata.Manager()
|
||||
class Car extends smartdata.SmartDataDbDoc<Car, Car> {
|
||||
@smartdata.unI()
|
||||
public index: string = smartunique.shortId();
|
||||
|
||||
@ -79,20 +80,22 @@ class CarTemplate extends smartdata.SmartDataDbDoc<CarTemplate, CarTemplate> {
|
||||
}
|
||||
|
||||
const createCarClass = (dbArg: smartdata.SmartdataDb) => {
|
||||
console.log(this);
|
||||
@smartdata.Collection(() => {
|
||||
return dbArg;
|
||||
})
|
||||
class Car extends CarTemplate {};
|
||||
smartdata.setDefaultManagerForDoc({db: dbArg}, Car);
|
||||
return Car;
|
||||
};
|
||||
|
||||
tap.test('should prodice a car', async () => {
|
||||
tap.test('should produce a car', async () => {
|
||||
const CarClass = createCarClass(testDb);
|
||||
const carInstance = new CarClass('red', 'Mercedes');
|
||||
await carInstance.save();
|
||||
});
|
||||
|
||||
tap.test('should get a car', async () => {
|
||||
const car = Car.getInstance({
|
||||
color: 'red'
|
||||
})
|
||||
})
|
||||
|
||||
// =======================================
|
||||
// close the database connection
|
||||
// =======================================
|
||||
|
@ -45,16 +45,22 @@ export interface IManager {
|
||||
db: SmartdataDb
|
||||
}
|
||||
|
||||
export const setDefaultManagerForDoc = (managerArg: IManager, dbDoc: any) => {
|
||||
dbDoc.prototype.defaultManager = managerArg;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a decorator that will tell the decorated class what dbTable to use
|
||||
* @param dbArg
|
||||
*/
|
||||
export function Manager<TManager extends IManager>(managerArg?: TManager | TDelayed<TManager>) {
|
||||
return function classDecorator<T extends { new (...args: any[]): {} }>(constructor: T) {
|
||||
return function classDecorator<T extends { new (...args: any[]): any }>(constructor: T) {
|
||||
return class extends constructor {
|
||||
public static get collection() {
|
||||
let dbArg: SmartdataDb;
|
||||
if (managerArg['db']) {
|
||||
if (!managerArg) {
|
||||
dbArg = this.prototype.defaultManager.db;
|
||||
} else if (managerArg['db']) {
|
||||
dbArg = (managerArg as TManager).db
|
||||
} else {
|
||||
dbArg = (managerArg as TDelayed<TManager>)().db;
|
||||
@ -63,7 +69,11 @@ export interface IManager {
|
||||
}
|
||||
public get collection() {
|
||||
let dbArg: SmartdataDb;
|
||||
if (managerArg['db']) {
|
||||
if (!managerArg) {
|
||||
//console.log(this.defaultManager.db);
|
||||
//process.exit(0)
|
||||
dbArg = this.defaultManager.db;
|
||||
} else if (managerArg['db']) {
|
||||
dbArg = (managerArg as TManager).db
|
||||
} else {
|
||||
dbArg = (managerArg as TDelayed<TManager>)().db;
|
||||
|
@ -47,6 +47,7 @@ export class SmartDataDbDoc<T extends TImplements, TImplements, TManager extends
|
||||
*/
|
||||
public static collection: SmartdataCollection<any>;
|
||||
public collection: SmartdataCollection<any>;
|
||||
public static defaultManager;
|
||||
public static manager;
|
||||
public manager: TManager;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user