Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: typescript enhancements #337

Merged
merged 2 commits into from
Dec 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 1 addition & 32 deletions src/consumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
import Debug from 'debug';
import { EventEmitter } from 'events';

import { AWSError } from './types';
import { AWSError, ConsumerOptions, Events } from './types';
import { autoBind } from './bind';
import { SQSError, TimeoutError } from './errors';

Expand Down Expand Up @@ -95,37 +95,6 @@ function hasMessages(response: ReceiveMessageCommandOutput): boolean {
return response.Messages && response.Messages.length > 0;
}

export interface ConsumerOptions {
queueUrl?: string;
attributeNames?: string[];
messageAttributeNames?: string[];
stopped?: boolean;
batchSize?: number;
visibilityTimeout?: number;
waitTimeSeconds?: number;
authenticationErrorTimeout?: number;
pollingWaitTimeMs?: number;
terminateVisibilityTimeout?: boolean;
heartbeatInterval?: number;
sqs?: SQSClient;
region?: string;
handleMessageTimeout?: number;
shouldDeleteMessages?: boolean;
handleMessage?(message: Message): Promise<void>;
handleMessageBatch?(messages: Message[]): Promise<Message[] | void>;
}

interface Events {
response_processed: [];
empty: [];
message_received: [Message];
message_processed: [Message];
error: [Error, void | Message | Message[]];
timeout_error: [Error, Message];
processing_error: [Error, Message];
stopped: [];
}

export class Consumer extends EventEmitter {
private queueUrl: string;
private handleMessage: (message: Message) => Promise<void>;
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { Consumer, ConsumerOptions } from './consumer';
export { Consumer } from './consumer';
export * from './types';
33 changes: 33 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,36 @@
import { SQSClient, Message } from '@aws-sdk/client-sqs';

export interface ConsumerOptions {
queueUrl: string;
attributeNames?: string[];
messageAttributeNames?: string[];
stopped?: boolean;
batchSize?: number;
visibilityTimeout?: number;
waitTimeSeconds?: number;
authenticationErrorTimeout?: number;
pollingWaitTimeMs?: number;
terminateVisibilityTimeout?: boolean;
heartbeatInterval?: number;
sqs?: SQSClient;
region?: string;
handleMessageTimeout?: number;
shouldDeleteMessages?: boolean;
handleMessage?(message: Message): Promise<void>;
handleMessageBatch?(messages: Message[]): Promise<Message[] | void>;
}

export interface Events {
response_processed: [];
empty: [];
message_received: [Message];
message_processed: [Message];
error: [Error, void | Message | Message[]];
timeout_error: [Error, Message];
processing_error: [Error, Message];
stopped: [];
}

export type AWSError = {
/**
* Name, eg. ConditionalCheckFailedException
Expand Down
9 changes: 0 additions & 9 deletions test/consumer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,6 @@ describe('Consumer', () => {
sandbox.restore();
});

it('requires a queueUrl to be set', () => {
assert.throws(() => {
Consumer.create({
region: REGION,
handleMessage
});
});
});

it('requires a handleMessage or handleMessagesBatch function to be set', () => {
assert.throws(() => {
new Consumer({
Expand Down