import { FunctionAppVersion , Regex } from './../models/constants' ; export interface FunctionsVersionInfo { runtimeStable : string [ ] ; runtimeDefault : string ; } export function runtimeIsV1 ( runtimeVersion ) { return runtimeVersion === FunctionAppVersion . v1 ; } export function runtimeIsV2 ( runtimeVersion ) { return runtimeVersion === FunctionAppVersion . v2 ; } export function runtimeIsV3 ( runtimeVersion ) { return runtimeVersion === FunctionAppVersion . v3 ; } export class FunctionsVersionInfoHelper { public static needToUpdateRuntime ( version , extensionVersion ) { const match = version . runtimeStable . find ( v => { return extensionVersion . toLowerCase ( ) === v ; } ) ; return ! match ; } public static getFunctionGeneration ( runtimeVersion ) { if ( ! runtimeVersion ) { return FunctionAppVersion . v1 ; } else if ( runtimeVersion . startsWith ( '~2' ) || runtimeVersion . startsWith ( '2' ) || runtimeVersion . startsWith ( 'beta' ) ) { return FunctionAppVersion . v2 ; } else if ( runtimeVersion . startsWith ( '~3' ) || runtimeVersion . startsWith ( '3' ) ) { return FunctionAppVersion . v3 ; } return FunctionAppVersion . v1 ; } public static getEventGridUri ( generation , mainSiteUrl , functionName , code ) { const path = generation === FunctionAppVersion . v1 ? 'admin/extensions/EventGridExtensionConfig' : 'runtime/webhooks/EventGrid' ; return `${ mainSiteUrl . toLowerCase ( ) }/${ path }?functionName=${ functionName }&code=${ code }` ; } public static getRuntimeVersionString ( exactVersion ) { if ( Regex . runtimeVersion . test ( exactVersion ) ) { const versionElements = exactVersion . split ( '.' ) ; return `~${ versionElements [ 0 ] }` ; } return exactVersion ; } }