import { Export } from "../decorators" ; import { PermissionMetadata , ServiceMetadata } from "../metadata" ; import { Roles } from "../types" ; export function Public ( ) { return Permission ( Public . name , { Public : true } ) ; } export function Debug ( ) { return Permission ( Debug . name , { Debug : true } ) ; } export function Private ( ) { return Permission ( Private . name , { Internal : false , Remote : false } ) ; } export function Internal ( ) { return Permission ( Internal . name , { Internal : true , Remote : false } ) ; } export function Remote ( ) { return Permission ( Remote . name , { Internal : true , Remote : true } ) ; } export function Invoke < R extends Roles > ( roles ) { return Permission ( Invoke . name , roles ) ; } export function Query < R extends Roles > ( roles ) { return Permission ( Query . name , roles ) ; } export function Command < R extends Roles > ( roles ) { return Permission ( Command . name , roles ) ; } function Permission ( name , roles ) { name = name . toLowerCase ( ) ; return function ( type , propertyKey , descriptor ) { roles . Internal = roles . Internal === undefined ? true : ! ! roles . Internal ; roles . Remote = roles . Remote === undefined ? true : ! ! roles . Internal ; let permission = { service : undefined , method : propertyKey , name : name . toLowerCase ( ) , roles } ; let metadata = ServiceMetadata . get ( type ) ; metadata . permissions [ propertyKey ] = permission ; if ( roles . Internal || roles . Remote ) Export ( ) ( type , propertyKey , descriptor ) ; } ; }