sqs-consumer
Advanced tools
Comparing version 7.0.3 to 7.1.0-canary.1
@@ -1,2 +0,2 @@ | ||
import { ConsumerOptions, TypedEventEmitter, StopOptions } from './types'; | ||
import { ConsumerOptions, TypedEventEmitter, StopOptions, UpdatableOptions } from './types'; | ||
/** | ||
@@ -41,2 +41,13 @@ * [Usage](https://bbc.github.io/sqs-consumer/index.html#usage) | ||
/** | ||
* Updates visibilityTimeout to the provided value. | ||
* @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; | ||
/** | ||
* Emit one of the consumer's error events depending on the error received. | ||
@@ -43,0 +54,0 @@ * @param err The error object to forward on |
@@ -95,2 +95,32 @@ "use strict"; | ||
/** | ||
* Updates visibilityTimeout to the provided value. | ||
* @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`); | ||
} | ||
} | ||
/** | ||
* Emit one of the consumer's error events depending on the error received. | ||
@@ -97,0 +127,0 @@ * @param err The error object to forward on |
@@ -108,2 +108,3 @@ /// <reference types="node" /> | ||
} | ||
export type UpdatableOptions = 'visibilityTimeout'; | ||
export interface StopOptions { | ||
@@ -157,2 +158,6 @@ /** | ||
stopped: []; | ||
/** | ||
* Fired when an option is updated | ||
*/ | ||
option_updated: [UpdatableOptions, ConsumerOptions[UpdatableOptions]]; | ||
} | ||
@@ -159,0 +164,0 @@ export declare class TypedEventEmitter extends EventEmitter { |
{ | ||
"name": "sqs-consumer", | ||
"version": "7.0.3", | ||
"version": "7.1.0-canary.1", | ||
"description": "Build SQS-based Node applications without the boilerplate", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -15,3 +15,3 @@ # sqs-consumer | ||
```bash | ||
npm install --save-dev sqs-consumer | ||
npm install sqs-consumer | ||
``` | ||
@@ -23,3 +23,3 @@ | ||
> ```bash | ||
> npm install sqs-consumer@5.8.0 --save-dev | ||
> npm install sqs-consumer@5.8.0 | ||
> ``` | ||
@@ -132,2 +132,8 @@ | ||
### `consumer.updateOption(option, value)` | ||
Updates the provided option with the provided value. | ||
You can [find out more about this here](https://bbc.github.io/sqs-consumer/public/classes/Consumer.html#updateOption). | ||
### Events | ||
@@ -134,0 +140,0 @@ |
@@ -20,3 +20,8 @@ import { | ||
import { ConsumerOptions, TypedEventEmitter, StopOptions } from './types'; | ||
import { | ||
ConsumerOptions, | ||
TypedEventEmitter, | ||
StopOptions, | ||
UpdatableOptions | ||
} from './types'; | ||
import { autoBind } from './bind'; | ||
@@ -137,2 +142,43 @@ import { | ||
/** | ||
* Updates visibilityTimeout to the provided value. | ||
* @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( | ||
option: UpdatableOptions, | ||
value: ConsumerOptions[UpdatableOptions] | ||
) { | ||
switch (option) { | ||
case 'visibilityTimeout': | ||
this.updateVisibilityTimeout(value); | ||
break; | ||
default: | ||
throw new Error(`The update ${option} cannot be updated`); | ||
} | ||
} | ||
/** | ||
* Emit one of the consumer's error events depending on the error received. | ||
@@ -139,0 +185,0 @@ * @param err The error object to forward on |
@@ -109,2 +109,4 @@ import { SQSClient, Message } from '@aws-sdk/client-sqs'; | ||
export type UpdatableOptions = 'visibilityTimeout'; | ||
export interface StopOptions { | ||
@@ -159,2 +161,6 @@ /** | ||
stopped: []; | ||
/** | ||
* Fired when an option is updated | ||
*/ | ||
option_updated: [UpdatableOptions, ConsumerOptions[UpdatableOptions]]; | ||
} | ||
@@ -161,0 +167,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
96245
46
1870
149
1