import { SchemaType , AllSchemaTypes } from "@autorest/codemodel" ; import { isNil , isEmpty } from "lodash" ; import { MapperType , SequenceMapperType } from "@azure/core-http" ; export enum MapperTypes { Base64Url = "Base64Url" , Boolean = "Boolean" , ByteArray = "ByteArray" , Date = "Date" , DateTime = "DateTime" , DateTimeRfc1123 = "DateTimeRfc1123" , Enum = "Enum" , Object = "Object" , Stream = "Stream" , String = "String" , TimeSpan = "TimeSpan" , UnixTime = "UnixTime" , Uuid = "Uuid" , Number = "Number" , Sequence = "Sequence" , any = "any" } param value param valueType param quotedStrings export function getStringForValue ( value , valueType , quotedStrings = true , mapperType ? ) { switch ( valueType ) { case SchemaType . ByteArray : case MapperTypes . ByteArray : const byteArrayValue = isNil ( value ) || isEmpty ( value ) ? 0 : `"${ value }"` ; return `new Uint8Array(${ byteArrayValue })` ; case SchemaType . Number : case MapperTypes . Number : case SchemaType . Integer : case SchemaType . Boolean : case MapperTypes . Boolean : return value ; case SchemaType . Uuid : case MapperTypes . Uuid : case SchemaType . Date : case MapperTypes . Date : case SchemaType . DateTime : case MapperTypes . DateTime : case SchemaType . Duration : case SchemaType . String : case MapperTypes . String : case MapperTypes . TimeSpan : case SchemaType . Choice : case SchemaType . SealedChoice : case MapperTypes . Enum : const valueString = ! ! value ? value . toString ( ) : "" ; return quotedStrings ? `"${ valueString }"` : `${ valueString }` ; case MapperTypes . Sequence : if ( mapperType ) { return getStringForValue ( value , ( mapperType as SequenceMapperType ) . element . type . name ) ; } default : throw new Error ( `Unexpected value type: ${ valueType }` ) ; } }