import { Node , ts } from 'ts-morph' ; export function extractActionType ( actionReference ) { const fullQualifiedImport = actionReference . getType ( ) . getText ( ) ; const [ , typedAction = '' ] = /.+TypedAction<"(.*?)">.+/ . exec ( fullQualifiedImport ) || [ ] ; return typedAction ; } export function extractAllActionTypes ( actionReference ? ) { const fullQualifiedImport = actionReference ?. getType ( ) . getText ( ) || '' ; return Array . from ( fullQualifiedImport . matchAll ( /TypedAction<"(.*?)">/g ) , m => m [ 1 ] ) ; } export function extractActionPayload ( actionReference ) { const fullQualifiedImport = actionReference . getType ( ) . getText ( ) ; const [ , payloadDefinedByProps ] = /.+\(props: ({.+})\).+/ . exec ( fullQualifiedImport ) || [ ] ; const [ , payloadDefinedByFunctionWithParameters ] = /.+FunctionWithParametersType<\[.+\], ({.+}).+/ . exec ( fullQualifiedImport ) || [ ] ; return payloadDefinedByProps || payloadDefinedByFunctionWithParameters || null ; } export function segmentAction ( actionType ) { const [ , typeScope , typeDescription ] = /(\[[\w \/]+\])([\w ]+)/ . exec ( actionType ) || [ ] ; return { typeFull : actionType , typeScope , typeDescription : typeDescription || actionType } ; } export function isTypedAction ( declaration ) { return /^import.+\.TypedAction</ . test ( declaration . getType ( ) . getText ( ) ) ; }