Skip to content

Commit

Permalink
V5 - drop old node versions and move to new AWS sdk (#129)
Browse files Browse the repository at this point in the history
\
  • Loading branch information
regevbr authored Apr 12, 2023
1 parent 2774421 commit 525a3ed
Show file tree
Hide file tree
Showing 30 changed files with 2,553 additions and 1,527 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
node-version: [6.x, 8.x, 10.x, 12.x, 14.x, 16.x, 18.x]
node-version: [16.x, 18.x, 19.x]

steps:

Expand Down Expand Up @@ -87,7 +87,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
node-version: [16.x]
node-version: [18.x]
needs: [test]
if: github.event_name == 'release' && github.event.action == 'published'
steps:
Expand Down
9 changes: 9 additions & 0 deletions .mocharc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require:
- 'ts-node/register'
- 'source-map-support/register'
- 'src/test/setup.ts'
recursive: true
reporter: 'spec'
exit: true
spec:
- 'src/test/**/*.ts'
6 changes: 0 additions & 6 deletions .nycrc

This file was deleted.

12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@
[![Test Coverage](https://api.codeclimate.com/v1/badges/177b18abdb55fdf90cf8/test_coverage)](https://codeclimate.com/github/PruvoNet/squiss-ts/test_coverage)
[![Maintainability](https://api.codeclimate.com/v1/badges/177b18abdb55fdf90cf8/maintainability)](https://codeclimate.com/github/PruvoNet/squiss-ts/maintainability)
[![Known Vulnerabilities](https://snyk.io/test/github/PruvoNet/squiss-ts/badge.svg?targetFile=package.json)](https://snyk.io/test/github/PruvoNet/squiss-ts?targetFile=package.json)
[![dependencies Status](https://david-dm.org/PruvoNet/squiss-ts/status.svg)](https://david-dm.org/PruvoNet/squiss-ts)
[![devDependencies Status](https://david-dm.org/PruvoNet/squiss-ts/dev-status.svg)](https://david-dm.org/PruvoNet/squiss-ts?type=dev)

<p align="center">
<a href="https://squiss-ts.pruvo.com"><img src="https://github.com/PruvoNet/squiss-ts/blob/docs/source/images/logo.png?raw=true" /></a>
</p>

# Squiss-TS
High-volume Amazon SQS Poller and single-queue client for Node.js 6 and up with full typescript support
High-volume Amazon SQS Poller and single-queue client for Node.js 16 and up with full typescript support
The library is production ready and is being stress used in a full blown production environment

## Main features
Expand All @@ -33,8 +31,10 @@ Please see full documentation <a href="https://squiss-ts.pruvo.com">here</a>
import {Squiss, Message} from 'squiss-ts';

const awsConfig = {
accessKeyId: '<accessKeyId>',
secretAccessKey: '<secretAccessKey>',
credentials: {
accessKeyId: 'accessKeyId',
secretAccessKey: 'secretAccessKey',
},
region: '<region>',
};

Expand All @@ -58,7 +58,7 @@ const messageToSend = {
a: 1,
b: 2,
},
}
};

const propsToSend = {
p1: 1,
Expand Down
16 changes: 16 additions & 0 deletions e2e/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: '3'
services:
queue:
image: softwaremill/elasticmq
ports:
- "9324:9324"
- "9325:9325"

s3:
image: scireum/s3-ninja
ports:
- "9000:9000"
environment:
root: elasticmq
initialBuckets: test

64 changes: 64 additions & 0 deletions e2e/flow.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import {Squiss, Message} from '../src';
import {SQSClientConfig} from '@aws-sdk/client-sqs';
import {S3} from '@aws-sdk/client-s3';

const awsConfig: SQSClientConfig = {
region: 'elasticmq',
endpoint: 'http://localhost:9324',
credentials: {
accessKeyId: 'dummy',
secretAccessKey: 'dummy',
},
};

const s3 = new S3({
endpoint: 'http://localhost:9000/s3',
credentials: {
accessKeyId: 'AKIAIOSFODNN7EXAMPLE',
secretAccessKey: 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY',
},
})

const squiss = new Squiss({
awsConfig,
queueName: 'my-sqs-queue',
bodyFormat: 'json',
maxInFlight: 15,
S3: s3,
gzip: true,
minGzipSize: 1,
s3Fallback: true,
s3Bucket: 'test',
minS3Size: 1,
correctQueueUrl: true,
});

(async () => {
await await s3.createBucket({
Bucket: 'test',
});
await squiss.createQueue();
squiss.on('message', async (message: Message) => {
console.log(`${message.body.name} says: ${JSON.stringify(message.body.message)} and has attripute p1 with value ${message.attributes.p1}`);
await message.del();
});
squiss.on('error', (error: Error) => {
console.log(`squiss error`, error);
});
await squiss.start();

const messageToSend = {
name: 'messageName',
message: {
a: 1,
b: 2,
},
};

const propsToSend = {
p1: 1,
p2: 2,
};

await squiss.sendMessage(messageToSend, 0, propsToSend);
})();
71 changes: 44 additions & 27 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
{
"name": "squiss-ts",
"version": "4.4.1",
"version": "5.0.0",
"description": "High-volume SQS poller",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"engines": {
"node": "^6 || ^8 || ^10 || ^12 || ^14 || ^16 || ^18"
"node": "^16 || ^18|| ^19"
},
"scripts": {
"postinstall": " node -e \"const semver = require('semver');const relevant = semver.lt(process.version, '10.16.0');if (relevant == false) {process.exit(0);}try {require('iltorb'); process.exit(0);} catch (err){process.exit(1);}\" || yarn add --pure-lockfile --ignore-engines [email protected]",
"clean": "rm -rf node_modules build coverage dist",
"clean": "rm -rf .nyc_output coverage dist",
"build": "yarn lint && yarn compile",
"compile": "tsc",
"test": "yarn lint && yarn mocha",
"mocha": "_mocha --opts src/test/mocha.opts",
"cover": "nyc --reporter=lcov --reporter=text-summary npm run mocha",
"cover": "yarn clean && yarn nyc yarn mocha",
"lint": "tslint -c tslint.json \"src/**/*.ts\" \"test/**/*.ts\"",
"benchmark": "tsc --extendedDiagnostics --incremental false"
"benchmark": "tsc --extendedDiagnostics --incremental false",
"e2e:start": "docker compose -f e2e/docker-compose.yml up &",
"e2e:stop": "docker compose -f e2e/docker-compose.yml down &"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -48,34 +48,51 @@
},
"homepage": "https://github.com/PruvoNet/squiss-ts#readme",
"dependencies": {
"aws-sdk": "2.814.0",
"@aws-sdk/client-s3": "^3.310.0",
"@aws-sdk/client-sqs": "^3.310.0",
"@aws-sdk/types": "^3.310.0",
"linked-list": "^2.1.0",
"semver": "6.3.0",
"semver": "7.4.0",
"ts-type-guards": "^0.7.0",
"uuid": "^8.3.2"
"uuid": "^9.0.0"
},
"devDependencies": {
"@istanbuljs/nyc-config-typescript": "0.1.3",
"@types/chai": "^4.2.12",
"@types/chai-as-promised": "^7.1.3",
"@types/iltorb": "^2.3.2",
"@types/mocha": "^8.0.0",
"@types/node": "^14.0.26",
"@istanbuljs/nyc-config-typescript": "1.0.2",
"@types/chai": "^4.3.4",
"@types/chai-as-promised": "^7.1.5",
"@types/mocha": "^10.0.1",
"@types/node": "^14.18.42",
"@types/proxyquire": "^1.3.28",
"@types/semver": "7.3.1",
"@types/uuid": "^8.0.0",
"chai": "^4.2.0",
"@types/semver": "^7.3.13",
"@types/uuid": "^9.0.1",
"chai": "^4.3.7",
"chai-as-promised": "^7.1.1",
"delay": "^4.4.0",
"delay": "^5.0.0",
"dirty-chai": "^2.0.1",
"mocha": "6.2.2",
"nyc": "14.1.1",
"mocha": "^10.2.0",
"nyc": "^15.1.0",
"proxyquire": "^2.1.3",
"sinon": "^7.5.0",
"sinon-chai": "^3.5.0",
"source-map-support": "^0.5.19",
"ts-node": "^8.10.2",
"sinon": "^15.0.3",
"sinon-chai": "^3.7.0",
"source-map-support": "^0.5.21",
"ts-node": "^10.9.1",
"tslint": "^6.1.3",
"typescript": "4.6.4"
"typescript": "^5.0.4"
},
"nyc": {
"extends": "@istanbuljs/nyc-config-typescript",
"check-coverage": true,
"all": true,
"exclude": [
"src/test/**",
"e2e**"
],
"reporter": [
"html",
"lcov",
"text",
"text-summary"
],
"report-dir": "coverage"
}
}
2 changes: 0 additions & 2 deletions src/EventEmitterTypesHelper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

// https://github.com/bterlson/strict-event-emitter-types

declare const assignmentCompatibilityHack: unique symbol;
Expand Down
18 changes: 7 additions & 11 deletions src/Message.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
'use strict';

import * as SQS from 'aws-sdk/clients/sqs'
import * as S3 from 'aws-sdk/clients/s3'
import {AWSError} from 'aws-sdk/lib/error'
import {BatchResultErrorEntry, Message as SQSMessage, SQSServiceException} from '@aws-sdk/client-sqs'
import {S3} from '@aws-sdk/client-s3'
import {BodyFormat, Squiss} from '.';
import {IMessageAttributes, parseMessageAttributes} from './attributeUtils';
import {EventEmitter} from 'events';
import {GZIP_MARKER, decompressMessage} from './gzipUtils';
import {deleteBlob, getBlob, IS3Upload, S3_MARKER} from './s3Utils';
import {BatchResultErrorEntry} from 'aws-sdk/clients/sqs';
import {StrictEventEmitter} from './EventEmitterTypesHelper';

const EMPTY_BODY = '{}';

export interface IMessageOpts {
msg: SQS.Message;
msg: SQSMessage;
unwrapSns?: boolean;
bodyFormat?: BodyFormat;
squiss: Squiss;
Expand All @@ -38,8 +34,8 @@ interface IMessageEvents {
keep: void;
delError: BatchResultErrorEntry;
deleted: string;
autoExtendFail: AWSError;
autoExtendError: AWSError;
autoExtendFail: SQSServiceException;
autoExtendError: SQSServiceException;
s3Download: IS3Upload;
s3Delete: IS3Upload;
}
Expand All @@ -56,7 +52,7 @@ export class Message extends (EventEmitter as new() => MessageEmitter) {
}
}

public raw: SQS.Message;
public raw: SQSMessage;
public body?: string | any;
public subject?: string;
public topicArn?: string;
Expand Down Expand Up @@ -152,7 +148,7 @@ export class Message extends (EventEmitter as new() => MessageEmitter) {
if (!this._handled) {
this._handled = true;
return this._squiss.releaseMessage(this)
.catch((e) => {
.catch(() => {
this._handled = false;
});
}
Expand Down
Loading

0 comments on commit 525a3ed

Please sign in to comment.