How to take properties of a Decorator in Typescript

0
Hello, I'm implementing a library that should reflect what the Entity Framework Core does (only in typescript ) and created the 2 decorators below:

export function Column(options?: ColumnDecoratorDescriptor) {
  return (target: Object, key: string) => {

    let _val = this[key];

    if (delete this[key])
      Object.defineProperty(target, key, {
        get: () => _val,
        set: (n: any) => _val = n,
        enumerable: true,
        configurable: true,
        __: options
      } as any);

  }
}
export function Table(options: TableDecoratorDescription) {
  return <T extends { new(...args: any[]): {} }>(constructor: T) => {
    return class extends constructor {
      __: TableDecoratorDescription = options;
    }
  }
}

The idea is that I can create class models like this:

@Table({ name:'Person', schema: 'dbo'})
class PersonModel {
    @Column({type: 'int'})
    id: number
}

I just do not know how to capture the properties I passed in these decorators in other classes eg:

class PersonRepository {
    get(ref?:number | object) {

        let temp: new Person();
        let tableName:string = /* como pego s dados do decorator Table ?*/


    }
    find(filters:object) { ... }
    add(...person[]: Person) { ... }
    update(ref: number | object, fields:object) { ... }
    delete(ref:number | object) { ... }
}
    
asked by anonymous 28.12.2018 / 17:07

0 answers