sqs-consumer
Advanced tools
Comparing version 7.1.0-canary.2 to 7.1.0-canary.3
@@ -41,11 +41,6 @@ import { ConsumerOptions, TypedEventEmitter, StopOptions, UpdatableOptions } from './types'; | ||
/** | ||
* Updates visibilityTimeout to the provided value. | ||
* Validates and then updates the provided option to the provided value. | ||
* @param option The option to validate and then update | ||
* @param value The value to set visibilityTimeout to | ||
*/ | ||
private updateVisibilityTimeout; | ||
/** | ||
* Updates the provided option to the provided value. | ||
* @param option The option that you want to update | ||
* @param value The value to set the option to | ||
*/ | ||
updateOption(option: UpdatableOptions, value: ConsumerOptions[UpdatableOptions]): void; | ||
@@ -52,0 +47,0 @@ /** |
@@ -96,30 +96,11 @@ "use strict"; | ||
/** | ||
* Updates visibilityTimeout to the provided value. | ||
* Validates and then updates the provided option to the provided value. | ||
* @param option The option to validate and then update | ||
* @param value The value to set visibilityTimeout to | ||
*/ | ||
updateVisibilityTimeout(value) { | ||
if (typeof value !== 'number') { | ||
throw new Error('visibilityTimeout must be a number'); | ||
} | ||
if (typeof value !== 'number' || | ||
(this.heartbeatInterval && value <= this.heartbeatInterval)) { | ||
throw new Error('heartbeatInterval must be less than visibilityTimeout.'); | ||
} | ||
debug(`Updating the visibilityTimeout option to the value ${value}`); | ||
this.visibilityTimeout = value; | ||
this.emit('option_updated', 'visibilityTimeout', value); | ||
} | ||
/** | ||
* Updates the provided option to the provided value. | ||
* @param option The option that you want to update | ||
* @param value The value to set the option to | ||
*/ | ||
updateOption(option, value) { | ||
switch (option) { | ||
case 'visibilityTimeout': | ||
this.updateVisibilityTimeout(value); | ||
break; | ||
default: | ||
throw new Error(`The update ${option} cannot be updated`); | ||
} | ||
(0, validation_1.validateOption)(option, value, this, true); | ||
debug(`Updating the ${option} option to the value ${value}`); | ||
this[option] = value; | ||
this.emit('option_updated', option, value); | ||
} | ||
@@ -126,0 +107,0 @@ /** |
@@ -108,3 +108,3 @@ /// <reference types="node" /> | ||
} | ||
export type UpdatableOptions = 'visibilityTimeout'; | ||
export type UpdatableOptions = 'visibilityTimeout' | 'batchSize' | 'waitTimeSeconds'; | ||
export interface StopOptions { | ||
@@ -111,0 +111,0 @@ /** |
import { ReceiveMessageCommandOutput } from '@aws-sdk/client-sqs'; | ||
import { ConsumerOptions } from './types'; | ||
declare function validateOption(option: string, value: any, allOptions: { | ||
[key: string]: any; | ||
}, strict?: boolean): void; | ||
/** | ||
@@ -13,2 +16,2 @@ * Ensure that the required options have been set. | ||
declare function hasMessages(response: ReceiveMessageCommandOutput): boolean; | ||
export { hasMessages, assertOptions }; | ||
export { hasMessages, assertOptions, validateOption }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.assertOptions = exports.hasMessages = void 0; | ||
exports.validateOption = exports.assertOptions = exports.hasMessages = void 0; | ||
const requiredOptions = [ | ||
@@ -9,2 +9,34 @@ 'queueUrl', | ||
]; | ||
function validateOption(option, value, allOptions, strict) { | ||
switch (option) { | ||
case 'batchSize': | ||
if (value > 10 || value < 1) { | ||
throw new Error('batchSize must be between 1 and 10.'); | ||
} | ||
break; | ||
case 'heartbeatInterval': | ||
if (!allOptions.visibilityTimeout || | ||
value >= allOptions.visibilityTimeout) { | ||
throw new Error('heartbeatInterval must be less than visibilityTimeout.'); | ||
} | ||
break; | ||
case 'visibilityTimeout': | ||
if (allOptions.heartbeatInterval && | ||
value <= allOptions.heartbeatInterval) { | ||
throw new Error('heartbeatInterval must be less than visibilityTimeout.'); | ||
} | ||
break; | ||
case 'waitTimeSeconds': | ||
if (value < 1 || value > 20) { | ||
throw new Error('waitTimeSeconds must be between 0 and 20.'); | ||
} | ||
break; | ||
default: | ||
if (strict) { | ||
throw new Error(`The update ${option} cannot be updated`); | ||
} | ||
break; | ||
} | ||
} | ||
exports.validateOption = validateOption; | ||
/** | ||
@@ -21,8 +53,7 @@ * Ensure that the required options have been set. | ||
}); | ||
if (options.batchSize > 10 || options.batchSize < 1) { | ||
throw new Error('SQS batchSize option must be between 1 and 10.'); | ||
if (options.batchSize) { | ||
validateOption('batchSize', options.batchSize, options); | ||
} | ||
if (options.heartbeatInterval && | ||
!(options.heartbeatInterval < options.visibilityTimeout)) { | ||
throw new Error('heartbeatInterval must be less than visibilityTimeout.'); | ||
if (options.heartbeatInterval) { | ||
validateOption('heartbeatInterval', options.heartbeatInterval, options); | ||
} | ||
@@ -29,0 +60,0 @@ } |
{ | ||
"name": "sqs-consumer", | ||
"version": "7.1.0-canary.2", | ||
"version": "7.1.0-canary.3", | ||
"description": "Build SQS-based Node applications without the boilerplate", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -33,3 +33,3 @@ import { | ||
} from './errors'; | ||
import { assertOptions, hasMessages } from './validation'; | ||
import { validateOption, assertOptions, hasMessages } from './validation'; | ||
import { abortController } from './controllers'; | ||
@@ -143,29 +143,6 @@ | ||
/** | ||
* Updates visibilityTimeout to the provided value. | ||
* Validates and then updates the provided option to the provided value. | ||
* @param option The option to validate and then update | ||
* @param value The value to set visibilityTimeout to | ||
*/ | ||
private updateVisibilityTimeout(value: ConsumerOptions['visibilityTimeout']) { | ||
if (typeof value !== 'number') { | ||
throw new Error('visibilityTimeout must be a number'); | ||
} | ||
if ( | ||
typeof value !== 'number' || | ||
(this.heartbeatInterval && value <= this.heartbeatInterval) | ||
) { | ||
throw new Error('heartbeatInterval must be less than visibilityTimeout.'); | ||
} | ||
debug(`Updating the visibilityTimeout option to the value ${value}`); | ||
this.visibilityTimeout = value; | ||
this.emit('option_updated', 'visibilityTimeout', value); | ||
} | ||
/** | ||
* Updates the provided option to the provided value. | ||
* @param option The option that you want to update | ||
* @param value The value to set the option to | ||
*/ | ||
public updateOption( | ||
@@ -175,9 +152,9 @@ option: UpdatableOptions, | ||
) { | ||
switch (option) { | ||
case 'visibilityTimeout': | ||
this.updateVisibilityTimeout(value); | ||
break; | ||
default: | ||
throw new Error(`The update ${option} cannot be updated`); | ||
} | ||
validateOption(option, value, this, true); | ||
debug(`Updating the ${option} option to the value ${value}`); | ||
this[option] = value; | ||
this.emit('option_updated', option, value); | ||
} | ||
@@ -184,0 +161,0 @@ |
@@ -109,3 +109,6 @@ import { SQSClient, Message } from '@aws-sdk/client-sqs'; | ||
export type UpdatableOptions = 'visibilityTimeout'; | ||
export type UpdatableOptions = | ||
| 'visibilityTimeout' | ||
| 'batchSize' | ||
| 'waitTimeSeconds'; | ||
@@ -112,0 +115,0 @@ export interface StopOptions { |
@@ -11,2 +11,47 @@ import { ReceiveMessageCommandOutput } from '@aws-sdk/client-sqs'; | ||
function validateOption( | ||
option: string, | ||
value: any, | ||
allOptions: { [key: string]: any }, | ||
strict?: boolean | ||
): void { | ||
switch (option) { | ||
case 'batchSize': | ||
if (value > 10 || value < 1) { | ||
throw new Error('batchSize must be between 1 and 10.'); | ||
} | ||
break; | ||
case 'heartbeatInterval': | ||
if ( | ||
!allOptions.visibilityTimeout || | ||
value >= allOptions.visibilityTimeout | ||
) { | ||
throw new Error( | ||
'heartbeatInterval must be less than visibilityTimeout.' | ||
); | ||
} | ||
break; | ||
case 'visibilityTimeout': | ||
if ( | ||
allOptions.heartbeatInterval && | ||
value <= allOptions.heartbeatInterval | ||
) { | ||
throw new Error( | ||
'heartbeatInterval must be less than visibilityTimeout.' | ||
); | ||
} | ||
break; | ||
case 'waitTimeSeconds': | ||
if (value < 1 || value > 20) { | ||
throw new Error('waitTimeSeconds must be between 0 and 20.'); | ||
} | ||
break; | ||
default: | ||
if (strict) { | ||
throw new Error(`The update ${option} cannot be updated`); | ||
} | ||
break; | ||
} | ||
} | ||
/** | ||
@@ -26,11 +71,7 @@ * Ensure that the required options have been set. | ||
if (options.batchSize > 10 || options.batchSize < 1) { | ||
throw new Error('SQS batchSize option must be between 1 and 10.'); | ||
if (options.batchSize) { | ||
validateOption('batchSize', options.batchSize, options); | ||
} | ||
if ( | ||
options.heartbeatInterval && | ||
!(options.heartbeatInterval < options.visibilityTimeout) | ||
) { | ||
throw new Error('heartbeatInterval must be less than visibilityTimeout.'); | ||
if (options.heartbeatInterval) { | ||
validateOption('heartbeatInterval', options.heartbeatInterval, options); | ||
} | ||
@@ -47,2 +88,2 @@ } | ||
export { hasMessages, assertOptions }; | ||
export { hasMessages, assertOptions, validateOption }; |
Sorry, the diff of this file is not supported yet
97261
1913