@clipmx/lambda-utils
Advanced tools
Comparing version 0.7.2 to 0.7.3
@@ -28,3 +28,3 @@ import { Connection } from 'amqplib'; | ||
*/ | ||
private open(); | ||
private open(assert); | ||
/** | ||
@@ -38,3 +38,3 @@ * Closes the existing connection | ||
*/ | ||
addToQueue(payload: string): Promise<any>; | ||
addToQueue(payload: string, assert: boolean): Promise<any>; | ||
} |
@@ -44,7 +44,9 @@ "use strict"; | ||
*/ | ||
open() { | ||
open(assert) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.connection = yield amqplib_1.connect(this.connectionString); | ||
const channel = yield this.connection.createChannel(); | ||
yield channel.assertQueue(this.queue, { durable: true }); | ||
if (assert) { | ||
yield channel.assertQueue(this.queue, { durable: true }); | ||
} | ||
return channel; | ||
@@ -66,7 +68,7 @@ }); | ||
*/ | ||
addToQueue(payload) { | ||
addToQueue(payload, assert) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!TypeGuards_1.default.isString(payload)) | ||
throw new TypeError('Expected a string payload'); | ||
const channel = yield this.open(); | ||
const channel = yield this.open(assert); | ||
const content = Buffer.from(payload); | ||
@@ -73,0 +75,0 @@ channel.sendToQueue(this.queue, content, { persistent: false }); |
{ | ||
"name": "@clipmx/lambda-utils", | ||
"version": "0.7.2", | ||
"version": "0.7.3", | ||
"description": "Common helpers for Node Lambdas", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -42,7 +42,9 @@ import { connect, Connection, Channel } from 'amqplib'; | ||
*/ | ||
private async open() { | ||
private async open(assert: boolean) { | ||
this.connection = await connect(this.connectionString); | ||
const channel: Channel = await this.connection.createChannel(); | ||
await channel.assertQueue(this.queue, { durable: true }); | ||
if (assert) { | ||
await channel.assertQueue(this.queue, { durable: true }); | ||
} | ||
@@ -63,6 +65,6 @@ return channel; | ||
*/ | ||
async addToQueue(payload: string): Promise<any> { | ||
async addToQueue(payload: string, assert: boolean): Promise<any> { | ||
if (!TypeGuards.isString(payload)) throw new TypeError('Expected a string payload'); | ||
const channel = await this.open(); | ||
const channel = await this.open(assert); | ||
const content = Buffer.from(payload); | ||
@@ -69,0 +71,0 @@ channel.sendToQueue(this.queue, content, { persistent: false }); |
Sorry, the diff of this file is not supported yet
151500
3329