import QueueStorageContext from "../context/QueueStorageContext" ; import StorageErrorFactory from "../errors/StorageErrorFactory" ; import * as Models from "../generated/artifacts/models" ; import Context from "../generated/Context" ; import IMessageIdHandler from "../generated/handlers/IMessageIdHandler" ; import { MessageUpdateProperties } from "../persistence/IQueueMetadataStore" ; import { DEFUALT_UPDATE_VISIBILITYTIMEOUT , MESSAGETEXT_LENGTH_MAX , QUEUE_API_VERSION , UPDATE_VISIBILITYTIMEOUT_MAX , UPDATE_VISIBILITYTIMEOUT_MIN } from "../utils/constants" ; import { getPopReceipt , getUTF8ByteSize , parseXMLwithEmpty } from "../utils/utils" ; import BaseHandler from "./BaseHandler" ; export class implements IMessageIdHandler export default class MessageIdHandler extends BaseHandler implements IMessageIdHandler { param { Models . QueueMessage } queueMessage param { string } popReceipt param { number } visibilitytimeout param { Models . MessageIdUpdateOptionalParams } options param { Context } context returns { Promise < Models . MessageIdUpdateResponse > } memberof public async update ( queueMessage , popReceipt , visibilitytimeout , options , context ) { const queueCtx = new QueueStorageContext ( context ) ; const accountName = queueCtx . account ! ; const queueName = queueCtx . queue ! ; const messageId = queueCtx . messageId ! ; if ( queueMessage . messageText === undefined ) { const body = queueCtx . request ! . getBody ( ) ; const parsedBody = await parseXMLwithEmpty ( body || "" ) ; for ( const text in parsedBody ) { if ( parsedBody . hasOwnProperty ( text ) && text . toLowerCase ( ) === "messagetext" ) { queueMessage . messageText = parsedBody [ text ] ; break ; } } } if ( queueMessage . messageText !== undefined && getUTF8ByteSize ( queueMessage . messageText ) > MESSAGETEXT_LENGTH_MAX ) { throw StorageErrorFactory . getRequestBodyTooLarge ( queueCtx . contextID ! , { MaxLimit : "65536" } ) ; } const newPopReceipt = getPopReceipt ( context . startTime ! ) ; const timeNextVisible = new Date ( context . startTime ! . getTime ( ) + DEFUALT_UPDATE_VISIBILITYTIMEOUT * 1000 ) ; if ( visibilitytimeout !== undefined ) { if ( visibilitytimeout < UPDATE_VISIBILITYTIMEOUT_MIN || visibilitytimeout > UPDATE_VISIBILITYTIMEOUT_MAX ) { throw StorageErrorFactory . getOutOfRangeQueryParameterValue ( context . contextID , { QueryParameterName : "visibilitytimeout" , QueryParameterValue : `${ visibilitytimeout }` , MinimumAllowed : `${ UPDATE_VISIBILITYTIMEOUT_MIN }` , MaximumAllowed : `${ UPDATE_VISIBILITYTIMEOUT_MAX }` } ) ; } timeNextVisible . setTime ( context . startTime ! . getTime ( ) + visibilitytimeout * 1000 ) ; } const message = { accountName , queueName , messageId , popReceipt : newPopReceipt , timeNextVisible , persistency : undefined } ; if ( queueMessage . messageText !== undefined ) { message . persistency = await this . extentStore . appendExtent ( Buffer . from ( queueMessage . messageText ) , context . contextID ) ; } await this . metadataStore . updateMessage ( message , popReceipt , context ) ; const response = { popReceipt : newPopReceipt , timeNextVisible , date : context . startTime , requestId : context . contextID , version : QUEUE_API_VERSION , statusCode : 204 , clientRequestId : options . requestId } ; return response ; } param { string } popReceipt param { Models . MessageIdDeleteMethodOptionalParams } options param { Context } context returns { Promise < Models . MessageIdDeleteResponse > } memberof public async delete ( popReceipt , options , context ) { const queueCtx = new QueueStorageContext ( context ) ; const accountName = queueCtx . account ! ; const queueName = queueCtx . queue ! ; const messageId = queueCtx . messageId ! ; await this . metadataStore . deleteMessage ( accountName , queueName , messageId , popReceipt , context ) ; const response = { date : context . startTime , requestId : context . contextID , version : QUEUE_API_VERSION , statusCode : 204 , clientRequestId : options . requestId } ; return response ; } }