@bbc/cloudflare-queue-consumer
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -9,3 +9,2 @@ "use strict"; | ||
const errors_js_1 = require("./errors.js"); | ||
// TODO: Document how to use this in the README | ||
/** | ||
@@ -129,4 +128,4 @@ * [Usage](https://bbc.github.io/cloudflare-queue-consumer/index.html#usage) | ||
/** | ||
* Send a request to CloudFlare Queues to retrieve messages | ||
* @param params The required params to receive messages from CloudFlare Queues | ||
* Send a request to Cloudflare Queues to retrieve messages | ||
* @param params The required params to receive messages from Cloudflare Queues | ||
*/ | ||
@@ -153,5 +152,5 @@ async receiveMessage() { | ||
/** | ||
* Handles the response from CloudFlare, determining if we should proceed to | ||
* Handles the response from Cloudflare, determining if we should proceed to | ||
* the message handler. | ||
* @param response The output from CloudFlare | ||
* @param response The output from Cloudflare | ||
*/ | ||
@@ -178,5 +177,5 @@ async handleQueueResponse(response) { | ||
/** | ||
* Process a message that has been received from CloudFlare Queues. This will execute the message | ||
* Process a message that has been received from Cloudflare Queues. This will execute the message | ||
* handler and delete the message once complete. | ||
* @param message The message that was delivered from CloudFlare | ||
* @param message The message that was delivered from Cloudflare | ||
*/ | ||
@@ -233,3 +232,3 @@ async processMessage(message) { | ||
* Trigger the applications handleMessage function | ||
* @param message The message that was received from CloudFlare | ||
* @param message The message that was received from Cloudflare | ||
*/ | ||
@@ -295,4 +294,3 @@ async executeHandler(message) { | ||
try { | ||
// TODO: this is pretty hacky | ||
// TODO: This doesn't appear to be acknowledging correctly.... | ||
// TODO: this is pretty hacky, is there a better way to do this? | ||
const retriesWithDelay = retries.map((message) => ({ | ||
@@ -299,0 +297,0 @@ ...message, |
@@ -47,4 +47,10 @@ "use strict"; | ||
if (options.batchSize) { | ||
validateOption("batchSize", options.batchSize, false); | ||
validateOption("batchSize", options.batchSize); | ||
} | ||
if (options.visibilityTimeoutMs) { | ||
validateOption("visibilityTimeoutMs", options.visibilityTimeoutMs); | ||
} | ||
if (options.retryMessageDelay) { | ||
validateOption("retryMessageDelay", options.retryMessageDelay); | ||
} | ||
} | ||
@@ -54,3 +60,3 @@ exports.assertOptions = assertOptions; | ||
* Determine if the response has messages in it. | ||
* @param response The response from CloudFlare. | ||
* @param response The response from Cloudflare. | ||
*/ | ||
@@ -57,0 +63,0 @@ function hasMessages(response) { |
@@ -6,3 +6,2 @@ import { TypedEventEmitter } from "./emitter.js"; | ||
import { toProviderError, ProviderError, toStandardError, toTimeoutError, TimeoutError, } from "./errors.js"; | ||
// TODO: Document how to use this in the README | ||
/** | ||
@@ -126,4 +125,4 @@ * [Usage](https://bbc.github.io/cloudflare-queue-consumer/index.html#usage) | ||
/** | ||
* Send a request to CloudFlare Queues to retrieve messages | ||
* @param params The required params to receive messages from CloudFlare Queues | ||
* Send a request to Cloudflare Queues to retrieve messages | ||
* @param params The required params to receive messages from Cloudflare Queues | ||
*/ | ||
@@ -150,5 +149,5 @@ async receiveMessage() { | ||
/** | ||
* Handles the response from CloudFlare, determining if we should proceed to | ||
* Handles the response from Cloudflare, determining if we should proceed to | ||
* the message handler. | ||
* @param response The output from CloudFlare | ||
* @param response The output from Cloudflare | ||
*/ | ||
@@ -175,5 +174,5 @@ async handleQueueResponse(response) { | ||
/** | ||
* Process a message that has been received from CloudFlare Queues. This will execute the message | ||
* Process a message that has been received from Cloudflare Queues. This will execute the message | ||
* handler and delete the message once complete. | ||
* @param message The message that was delivered from CloudFlare | ||
* @param message The message that was delivered from Cloudflare | ||
*/ | ||
@@ -230,3 +229,3 @@ async processMessage(message) { | ||
* Trigger the applications handleMessage function | ||
* @param message The message that was received from CloudFlare | ||
* @param message The message that was received from Cloudflare | ||
*/ | ||
@@ -292,4 +291,3 @@ async executeHandler(message) { | ||
try { | ||
// TODO: this is pretty hacky | ||
// TODO: This doesn't appear to be acknowledging correctly.... | ||
// TODO: this is pretty hacky, is there a better way to do this? | ||
const retriesWithDelay = retries.map((message) => ({ | ||
@@ -296,0 +294,0 @@ ...message, |
@@ -43,8 +43,14 @@ const requiredOptions = [ | ||
if (options.batchSize) { | ||
validateOption("batchSize", options.batchSize, false); | ||
validateOption("batchSize", options.batchSize); | ||
} | ||
if (options.visibilityTimeoutMs) { | ||
validateOption("visibilityTimeoutMs", options.visibilityTimeoutMs); | ||
} | ||
if (options.retryMessageDelay) { | ||
validateOption("retryMessageDelay", options.retryMessageDelay); | ||
} | ||
} | ||
/** | ||
* Determine if the response has messages in it. | ||
* @param response The response from CloudFlare. | ||
* @param response The response from Cloudflare. | ||
*/ | ||
@@ -51,0 +57,0 @@ function hasMessages(response) { |
@@ -57,16 +57,16 @@ /// <reference types="node" resolution-mode="require"/> | ||
/** | ||
* Send a request to CloudFlare Queues to retrieve messages | ||
* @param params The required params to receive messages from CloudFlare Queues | ||
* Send a request to Cloudflare Queues to retrieve messages | ||
* @param params The required params to receive messages from Cloudflare Queues | ||
*/ | ||
private receiveMessage; | ||
/** | ||
* Handles the response from CloudFlare, determining if we should proceed to | ||
* Handles the response from Cloudflare, determining if we should proceed to | ||
* the message handler. | ||
* @param response The output from CloudFlare | ||
* @param response The output from Cloudflare | ||
*/ | ||
private handleQueueResponse; | ||
/** | ||
* Process a message that has been received from CloudFlare Queues. This will execute the message | ||
* Process a message that has been received from Cloudflare Queues. This will execute the message | ||
* handler and delete the message once complete. | ||
* @param message The message that was delivered from CloudFlare | ||
* @param message The message that was delivered from Cloudflare | ||
*/ | ||
@@ -81,3 +81,3 @@ private processMessage; | ||
* Trigger the applications handleMessage function | ||
* @param message The message that was received from CloudFlare | ||
* @param message The message that was received from Cloudflare | ||
*/ | ||
@@ -84,0 +84,0 @@ private executeHandler; |
@@ -6,3 +6,3 @@ /** | ||
/** | ||
* The number of messages to request from CloudFlare when polling (default `10`). | ||
* The number of messages to request from Cloudflare when polling (default `10`). | ||
* @defaultvalue `10` | ||
@@ -23,3 +23,3 @@ */ | ||
/** | ||
* You CloudFlare account id | ||
* You Cloudflare account id | ||
*/ | ||
@@ -73,3 +73,3 @@ accountId: string; | ||
* The duration (in milliseconds) to wait before repolling the queue. | ||
* (Note: As CloudFlare uses short polling, you probably shouldn't set this too low) | ||
* (Note: As Cloudflare uses short polling, you probably shouldn't set this too low) | ||
* @defaultvalue `1000` | ||
@@ -172,3 +172,3 @@ */ | ||
/** | ||
* Fired when requests to CloudFlare were aborted. | ||
* Fired when requests to Cloudflare were aborted. | ||
*/ | ||
@@ -175,0 +175,0 @@ aborted: []; |
@@ -10,5 +10,5 @@ import type { ConsumerOptions, PullMessagesResponse } from "./types.js"; | ||
* Determine if the response has messages in it. | ||
* @param response The response from CloudFlare. | ||
* @param response The response from Cloudflare. | ||
*/ | ||
declare function hasMessages(response: PullMessagesResponse): boolean; | ||
export { assertOptions, validateOption, hasMessages }; |
{ | ||
"name": "@bbc/cloudflare-queue-consumer", | ||
"version": "0.0.4", | ||
"description": "Build CloudFlare Queue applications without the boilerplate", | ||
"version": "0.0.5", | ||
"description": "Build Cloudflare Queue applications without the boilerplate", | ||
"repository": { | ||
@@ -37,5 +37,5 @@ "type": "git", | ||
"compile": "tsc -b ./tsconfig.cjs.json ./tsconfig.esm.json", | ||
"build": "npm run clean && npm run compile", | ||
"build": "pnpm run clean && pnpm run compile", | ||
"watch": "tsc --watch", | ||
"prepublishOnly": "npm run build", | ||
"prepublishOnly": "pnpm run build", | ||
"lint": "eslint . --ext .ts", | ||
@@ -45,6 +45,7 @@ "lint:fix": "eslint . --fix", | ||
"format:check": "prettier --check \"**/*.{js,json,jsx,md,ts,tsx,html}\"", | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"posttest": "npm run lint && npm run format:check", | ||
"test:unit": "node --import tsx --test ./test/unit/*.test.ts", | ||
"test": "pnpm run test:unit && pnpm run lint && pnpm run format:check", | ||
"lcov": "node --import tsx --test --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=test/reports/lcov.info ./test/unit/*.test.ts", | ||
"generate-docs": "typedoc", | ||
"dev": "DEBUG=cloudflare-queue-consumer node ./example/index.js" | ||
"dev": "DEBUG=cloudflare-queue-consumer tsx ./example/index.ts" | ||
}, | ||
@@ -57,2 +58,3 @@ "devDependencies": { | ||
"prettier": "^3.2.5", | ||
"tsx": "^4.7.1", | ||
"typedoc": "^0.25.12", | ||
@@ -59,0 +61,0 @@ "typescript": "^5.4.2" |
@@ -5,6 +5,6 @@ # cloudflare-queue-consumer | ||
[![Build Status](https://github.com/bbc/cloudflare-queue-consumer/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/bbc/cloudflare-queue-consumer/actions/workflows/test.yml) | ||
[![Maintainability](https://api.codeclimate.com/v1/badges/16ec3f59e73bc898b7ff/maintainability)](https://codeclimate.com/github/bbc/cloudflare-queue-consumer/maintainability) | ||
[![Test Coverage](https://api.codeclimate.com/v1/badges/16ec3f59e73bc898b7ff/test_coverage)](https://codeclimate.com/github/bbc/cloudflare-queue-consumer/test_coverage) | ||
[![Maintainability](https://api.codeclimate.com/v1/badges/a0fcd77021e4f54ffdd4/maintainability)](https://codeclimate.com/github/bbc/cloudflare-queue-consumer/maintainability) | ||
[![Test Coverage](https://api.codeclimate.com/v1/badges/a0fcd77021e4f54ffdd4/test_coverage)](https://codeclimate.com/github/bbc/cloudflare-queue-consumer/test_coverage) | ||
Build CloudFlare Queues applications without the boilerplate. Just define an async function that handles the message processing. | ||
Build [Cloudflare Queues](https://developers.cloudflare.com/queues/) applications without the boilerplate. Just define an async function that handles the message processing. | ||
@@ -30,6 +30,6 @@ Based on [sqs-consumer](https://github.com/bbc/sqs-consumer). | ||
```js | ||
import { Consumer } from "cloudflare-queue-consumer"; | ||
import { Consumer } from "@bbc/cloudflare-queue-consumer"; | ||
const consumer = new Consumer({ | ||
accountId: process.env.ACCOUNT_ID, // Your CloudFlare account ID | ||
accountId: process.env.ACCOUNT_ID, // Your Cloudflare account ID | ||
queueId: process.env.QUEUE_ID, // The Queue ID that you want to use. | ||
@@ -41,7 +41,7 @@ handleMessage: async (message) => { | ||
app.on("error", (err) => { | ||
consumer.on("error", (err) => { | ||
console.error(err.message); | ||
}); | ||
app.on("processing_error", (err) => { | ||
consumer.on("processing_error", (err) => { | ||
console.error(err.message); | ||
@@ -55,3 +55,3 @@ }); | ||
- Pull consumers are designed to use a "short polling" approach, this means that the API from CloudFlare will respond immediately with any messages that are available, or an empty response if there are no messages available, this is different from SQS which will wait an amount of time before responding with an empty response. | ||
- [Pull consumers](https://developers.cloudflare.com/queues/reference/pull-consumers/) are designed to use a "short polling" approach, this means that the API from Cloudflare will respond immediately with any messages that are available, or an empty response if there are no messages available, this is different from SQS which will wait an amount of time before responding with an empty response. | ||
- `handleMessage` will send one message to the handler at a time, if you would prefer to receive multiple messages at once, use the `handleMessageBatch` method instead. | ||
@@ -68,3 +68,3 @@ - It is important to await any processing that you are doing to ensure that the next action only happens after your processing has completed. | ||
In order to authenticate with the CloudFlare API, you will need to create an API token with read and write access to CloudFlare Queues, more information can be found [here](https://developers.cloudflare.com/queues/reference/pull-consumers/#create-api-tokens). | ||
In order to authenticate with the Cloudflare API, you will need to create an API token with read and write access to Cloudflare Queues, more information can be found [here](https://developers.cloudflare.com/queues/reference/pull-consumers/#create-api-tokens). | ||
@@ -75,5 +75,4 @@ Copy that token and set it as the value for an environment variable named `QUEUES_API_TOKEN`. | ||
You'll aldo find an example project in the folder `./example`, set the variables `ACCOUNT_ID` and `QUEUE_ID` and then run this with the command `pnpm dev`. | ||
You'll also find an example project in the folder `./example`, set the variables `ACCOUNT_ID` and `QUEUE_ID` and then run this with the command `pnpm dev`. | ||
## API | ||
@@ -91,5 +90,5 @@ | ||
Stop polling the queue for messages. [You can find the options definition here](https://bbc.github.io/cloudflare-queue-consumerinterfaces/StopOptions.html). | ||
Stop polling the queue for messages. [You can find the options definition here](https://bbc.github.io/cloudflare-queue-consumer/interfaces/StopOptions.html). | ||
By default, the value of `abort` is set to `false` which means pre existing requests to CloudFlare will still be made until they have concluded. If you would like to abort these requests instead, pass the abort value as `true`, like so: | ||
By default, the value of `abort` is set to `false` which means pre existing requests to Cloudflare will still be made until they have concluded. If you would like to abort these requests instead, pass the abort value as `true`, like so: | ||
@@ -125,2 +124,2 @@ `consumer.stop({ abort: true })` | ||
CloudFlare Queue Consumer is distributed under the Apache License, Version 2.0, see [LICENSE](https://github.com/bbc/cloudflare-queue-consumer/blob/main/LICENSE) for more information. | ||
Cloudflare Queue Consumer is distributed under the Apache License, Version 2.0, see [LICENSE](https://github.com/bbc/cloudflare-queue-consumer/blob/main/LICENSE) for more information. |
@@ -21,3 +21,2 @@ import { TypedEventEmitter } from "./emitter.js"; | ||
// TODO: Document how to use this in the README | ||
/** | ||
@@ -177,4 +176,4 @@ * [Usage](https://bbc.github.io/cloudflare-queue-consumer/index.html#usage) | ||
/** | ||
* Send a request to CloudFlare Queues to retrieve messages | ||
* @param params The required params to receive messages from CloudFlare Queues | ||
* Send a request to Cloudflare Queues to retrieve messages | ||
* @param params The required params to receive messages from Cloudflare Queues | ||
*/ | ||
@@ -202,5 +201,5 @@ private async receiveMessage(): Promise<PullMessagesResponse> { | ||
/** | ||
* Handles the response from CloudFlare, determining if we should proceed to | ||
* Handles the response from Cloudflare, determining if we should proceed to | ||
* the message handler. | ||
* @param response The output from CloudFlare | ||
* @param response The output from Cloudflare | ||
*/ | ||
@@ -234,5 +233,5 @@ private async handleQueueResponse( | ||
/** | ||
* Process a message that has been received from CloudFlare Queues. This will execute the message | ||
* Process a message that has been received from Cloudflare Queues. This will execute the message | ||
* handler and delete the message once complete. | ||
* @param message The message that was delivered from CloudFlare | ||
* @param message The message that was delivered from Cloudflare | ||
*/ | ||
@@ -299,3 +298,3 @@ private async processMessage(message: Message): Promise<void> { | ||
* Trigger the applications handleMessage function | ||
* @param message The message that was received from CloudFlare | ||
* @param message The message that was received from Cloudflare | ||
*/ | ||
@@ -374,4 +373,3 @@ private async executeHandler(message: Message): Promise<Message> { | ||
try { | ||
// TODO: this is pretty hacky | ||
// TODO: This doesn't appear to be acknowledging correctly.... | ||
// TODO: this is pretty hacky, is there a better way to do this? | ||
const retriesWithDelay = retries.map((message) => ({ | ||
@@ -378,0 +376,0 @@ ...message, |
@@ -6,3 +6,3 @@ /** | ||
/** | ||
* The number of messages to request from CloudFlare when polling (default `10`). | ||
* The number of messages to request from Cloudflare when polling (default `10`). | ||
* @defaultvalue `10` | ||
@@ -23,3 +23,3 @@ */ | ||
/** | ||
* You CloudFlare account id | ||
* You Cloudflare account id | ||
*/ | ||
@@ -73,3 +73,3 @@ accountId: string; | ||
* The duration (in milliseconds) to wait before repolling the queue. | ||
* (Note: As CloudFlare uses short polling, you probably shouldn't set this too low) | ||
* (Note: As Cloudflare uses short polling, you probably shouldn't set this too low) | ||
* @defaultvalue `1000` | ||
@@ -88,3 +88,2 @@ */ | ||
/** | ||
@@ -185,3 +184,3 @@ * The options for the stop method. | ||
/** | ||
* Fired when requests to CloudFlare were aborted. | ||
* Fired when requests to Cloudflare were aborted. | ||
*/ | ||
@@ -188,0 +187,0 @@ aborted: []; |
@@ -50,4 +50,12 @@ import type { ConsumerOptions, PullMessagesResponse } from "./types.js"; | ||
if (options.batchSize) { | ||
validateOption("batchSize", options.batchSize, false); | ||
validateOption("batchSize", options.batchSize); | ||
} | ||
if (options.visibilityTimeoutMs) { | ||
validateOption("visibilityTimeoutMs", options.visibilityTimeoutMs); | ||
} | ||
if (options.retryMessageDelay) { | ||
validateOption("retryMessageDelay", options.retryMessageDelay); | ||
} | ||
} | ||
@@ -57,3 +65,3 @@ | ||
* Determine if the response has messages in it. | ||
* @param response The response from CloudFlare. | ||
* @param response The response from Cloudflare. | ||
*/ | ||
@@ -60,0 +68,0 @@ function hasMessages(response: PullMessagesResponse): boolean { |
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
88116
2388
1
8
118