import { ArtifactCustomProperties , ArtifactProperties , ExecutionCustomProperties , ExecutionProperties , } from './Api' ; import { ArtifactTypeMap } from './LineageApi' ; import { Artifact , Execution , Value } from 'src/third_party/mlmd' ; import { LineageTypedResource } from './LineageTypes' ; import { Struct } from 'google-protobuf/google/protobuf/struct_pb' ; import { ArtifactHelpers , ExecutionHelpers } from './MlmdUtils' ; const ARTIFACT_FIELD_REPOS = [ ArtifactProperties , ArtifactCustomProperties ] ; const EXECUTION_FIELD_REPOS = [ ExecutionProperties , ExecutionCustomProperties ] ; type RepoType = typeof ArtifactCustomProperties | typeof ArtifactProperties | typeof ExecutionCustomProperties | typeof ExecutionProperties ; export function getResourceProperty ( resource , propertyName , fromCustomProperties = false ) { const props = fromCustomProperties ? resource . getCustomPropertiesMap ( ) : resource . getPropertiesMap ( ) ; return ( props && props . get ( propertyName ) && getMetadataValue ( props . get ( propertyName ) ) ) || null ; } export function getResourcePropertyViaFallBack ( res , fieldRepos , fields ) { const prop = fields . reduce ( ( value , field ) => value || fieldRepos . reduce ( ( v , repo , isCustomProp ) => v || ( ( field in repo && getResourceProperty ( res , repo [ field ] , ! ! isCustomProp ) ) as string ) , '' ) , '' ) || '' ; return prop as string ; } export function getResourceName ( typedResource ) { return typedResource . type === 'artifact' ? ArtifactHelpers . getName ( typedResource . resource ) : ExecutionHelpers . getName ( typedResource . resource ) ; } param t export const sleep = ( t ) : Promise < void > => new Promise ( res => setTimeout ( res , t ) ) ; export function getResourceDescription ( typedResource ) { return getResourcePropertyViaFallBack ( typedResource . resource , typedResource . type === 'artifact' ? ARTIFACT_FIELD_REPOS : EXECUTION_FIELD_REPOS , [ 'RUN_ID' , 'RUN' , 'PIPELINE_NAME' , 'WORKSPACE' ] ) ; } export function getTypeName ( typeId , artifactTypes ) { return artifactTypes && artifactTypes . get ( typeId ! ) ? artifactTypes . get ( typeId ! ) ! . getName ( ) : String ( typeId ) ; } export function getMetadataValue ( value ? ) { if ( ! value ) { return '' ; } switch ( value . getValueCase ( ) ) { case Value . ValueCase . DOUBLE_VALUE : return value . getDoubleValue ( ) ; case Value . ValueCase . INT_VALUE : return value . getIntValue ( ) ; case Value . ValueCase . STRING_VALUE : return value . getStringValue ( ) ; case Value . ValueCase . STRUCT_VALUE : return value . getStructValue ( ) ; case Value . ValueCase . VALUE_NOT_SET : return '' ; } }