UNPKG

@athenna/database

Version:

The Athenna database handler for SQL/NoSQL.

78 lines (77 loc) 3.21 kB
/** * @athenna/database * * (c) João Lenon <lenon@athenna.io> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ import { COLUMNS_KEY, HAS_ONE_KEY, HAS_MANY_KEY, HAS_ONE_THROUGH_KEY, HAS_MANY_THROUGH_KEY, BELONGS_TO_KEY, BELONGS_TO_MANY_KEY } from '#src/constants/MetadataKeys'; export class Annotation { static getColumnsMeta(target) { return Reflect.getMetadata(COLUMNS_KEY, target) || []; } static defineColumnMeta(target, options) { const columns = Reflect.getMetadata(COLUMNS_KEY, target) || []; columns.push(options); Reflect.defineMetadata(COLUMNS_KEY, columns, target); } static getRelationsMeta(target) { return [ ...this.getHasOnesMeta(target), ...this.getHasManyMeta(target), ...this.getHasOneThroughMeta(target), ...this.getHasManyThroughMeta(target), ...this.getBelongsToMeta(target), ...this.getBelongsToManyMeta(target) ]; } static getHasOnesMeta(target) { return Reflect.getMetadata(HAS_ONE_KEY, target) || []; } static defineHasOneMeta(target, options) { const hasOne = Reflect.getMetadata(HAS_ONE_KEY, target) || []; hasOne.push(options); Reflect.defineMetadata(HAS_ONE_KEY, hasOne, target); } static getHasManyMeta(target) { return Reflect.getMetadata(HAS_MANY_KEY, target) || []; } static defineHasManyMeta(target, options) { const hasMany = Reflect.getMetadata(HAS_MANY_KEY, target) || []; hasMany.push(options); Reflect.defineMetadata(HAS_MANY_KEY, hasMany, target); } static getHasOneThroughMeta(target) { return Reflect.getMetadata(HAS_ONE_THROUGH_KEY, target) || []; } static defineHasOneThroughMeta(target, options) { const hasOneThrough = Reflect.getMetadata(HAS_ONE_THROUGH_KEY, target) || []; hasOneThrough.push(options); Reflect.defineMetadata(HAS_ONE_THROUGH_KEY, hasOneThrough, target); } static getHasManyThroughMeta(target) { return Reflect.getMetadata(HAS_MANY_THROUGH_KEY, target) || []; } static defineHasManyThroughMeta(target, options) { const hasManyThrough = Reflect.getMetadata(HAS_MANY_THROUGH_KEY, target) || []; hasManyThrough.push(options); Reflect.defineMetadata(HAS_MANY_THROUGH_KEY, hasManyThrough, target); } static getBelongsToMeta(target) { return Reflect.getMetadata(BELONGS_TO_KEY, target) || []; } static defineBelongsToMeta(target, options) { const belongsTo = Reflect.getMetadata(BELONGS_TO_KEY, target) || []; belongsTo.push(options); Reflect.defineMetadata(BELONGS_TO_KEY, belongsTo, target); } static getBelongsToManyMeta(target) { return Reflect.getMetadata(BELONGS_TO_MANY_KEY, target) || []; } static defineBelongsToManyMeta(target, options) { const belongsToMany = Reflect.getMetadata(BELONGS_TO_MANY_KEY, target) || []; belongsToMany.push(options); Reflect.defineMetadata(BELONGS_TO_MANY_KEY, belongsToMany, target); } }