import type { WebSiteManagementModels } from '@azure/arm-appservice' ; import type { HttpOperationResponse , ServiceClient } from '@azure/ms-rest-js' ; /**
 * Temporary workaround because this isn't in azure sdk yet
 */ export async function listFunctionsSlot ( genericClient , id ) { const response = await genericClient . sendRequest ( { method : 'GET' , url : getUrlPath ( id ) } ) ; const rawResult = < IRawFunctionEnvelopeCollection > response . parsedBody ; const result = rawResult . value . map ( convertRawResource ) ; ( < any > result ) . nextLink = convertPropertyValue ( rawResult . nextLink ) ; return result ; } /**
 * Temporary workaround because this isn't in azure sdk yet
 */ export async function getFunctionSlot ( genericClient , id , functionName ) { const response = await genericClient . sendRequest ( { method : 'GET' , url : getUrlPath ( id , functionName ) } ) ; return convertRawResource ( < IRawAzureResource > response . parsedBody ) ; } /**
 * Temporary workaround because this isn't in azure sdk yet
 */ export async function deleteFunctionSlot ( genericClient , id , functionName ) { await genericClient . sendRequest ( { method : 'DELETE' , url : getUrlPath ( id , functionName ) } ) ; } function getUrlPath ( id , functionName ? ) { return `${ id }/functions${ functionName ? '/' + functionName : '' }?api-version=2016-08-01` ; } interface IRawFunctionEnvelopeCollection { value : IRawAzureResource [ ] ; nextLink : string | null ; } interface IRawAzureResource { properties : { [ key ] : string ; } ; name : string ; type : string ; id : string ; location : string ; } /**
 * Mimics what the azure sdk does under the covers to create the returned object
 */ function convertRawResource ( resource ) { const result = { } ; for ( const key of Object . keys ( resource . properties ) ) { result [ convertPropertyName ( key ) ] = convertPropertyValue ( resource . properties [ key ] ) ; } result . name = resource . name ; result . id = resource . id ; result . type = resource . type ; result . location = resource . location ; return result ; } /**
 * Converts property name like "function_app_id" to "functionAppId"
 */ function convertPropertyName ( name ) { while ( true ) { const match = /_([a-z])/g . exec ( name ) ; if ( match ) { name = name . replace ( match [ 0 ] , match [ 1 ] . toUpperCase ( ) ) ; } else { return name ; } } } /**
 * The azure sdk types all use undefined instead of null, so ensure we align with that
 */ function convertPropertyValue ( value ) { return value === null ? undefined : value ; }