import BaseEntity from '../models/BaseEntity' ; import getSlothData from '../utils/getSlothData' ; import { join } from 'path' ; import getProtoData from '../utils/getProtoData' ; export template S param { ( doc : S , emit : Function ) => void } fn param { string } docId param { string } viewId returns export default function SlothView < S , V extends string = string > ( fn , viewId ? , docId = 'views' ) { return ( target , key ) => { const desc = Reflect . getOwnPropertyDescriptor ( target , key ) ; if ( desc ) { if ( ! desc . get && ! desc . set ) { throw new Error ( 'Required SlothView on top of another decorator' ) ; } } const fun = `function (__doc) { 
      (${ fn . toString ( ) })(__doc, emit);
    }` ; const { views , fields } = getProtoData ( target , true ) ; const field = fields . find ( field => field . key === key ) ; if ( ! field ) { throw new Error ( 'Required SlothView on top of a SlothField' ) ; } views . push ( { id : docId , name : viewId || `by_${ field . docKey }` , function : fn , code : fun } ) ; } ; }