import { InvalidFormatError } from '../common' ; export enum TriggerType { OnPersist = 0x01 , PostPersist = 0x02 , Verification = 0x20 , Application = 0x40 , System = OnPersist | PostPersist , All = OnPersist | PostPersist | Verification | Application } export type TriggerTypeJSON = keyof typeof TriggerType ; export const isTriggerTypeJSON = ( type ) : type is TriggerTypeJSON => TriggerType [ type as any ] !== undefined ; export const assertTriggerTypeJSON = ( type ) : TriggerTypeJSON => { if ( isTriggerTypeJSON ( type ) ) { return type ; } throw new InvalidFormatError ( ) ; } ; export const toTriggerTypeJSON = ( type ) => assertTriggerTypeJSON ( TriggerType [ type ] ) ; export const isTriggerType = ( type ) : type is TriggerType => TriggerType [ type ] !== undefined ; export const assertTriggerType = ( type ) : TriggerType => { if ( isTriggerType ( type ) ) { return type ; } throw new InvalidFormatError ( ) ; } ; export const triggerTypeFromJSON = ( json ) => assertTriggerType ( TriggerType [ json ] ) ;