diff --git a/.codeclimate.yml b/.codeclimate.yml index 59be980..bff80e2 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -1,7 +1,7 @@ engines: eslint: enabled: true - channel: "eslint-6" + channel: "eslint-8" config: config: ".eslintrc.yaml" diff --git a/.eslintrc.yaml b/.eslintrc.yaml index f19411f..91a4c2e 100644 --- a/.eslintrc.yaml +++ b/.eslintrc.yaml @@ -2,9 +2,7 @@ env: node: true es6: true mocha: true - -parserOptions: - ecmaVersion: 2019 + es2020: true plugins: - haraka diff --git a/.github/workflows/ci-test.yml b/.github/workflows/ci-test.yml index 83cc104..4392618 100644 --- a/.github/workflows/ci-test.yml +++ b/.github/workflows/ci-test.yml @@ -2,6 +2,9 @@ name: CI Tests on: [ push ] +env: + CI: true + jobs: ci-test: @@ -16,19 +19,16 @@ jobs: strategy: matrix: os: [ ubuntu-latest ] - node-version: [ 12, 14, 16 ] + node-version: [ 14, 16, 18 ] fail-fast: false - env: - CI: true - steps: - uses: actions/checkout@v2 name: git checkout with: fetch-depth: 1 - - uses: actions/setup-node@v2 + - uses: actions/setup-node@v3 name: Use Node.js ${{ matrix.node-version }} with: node-version: ${{ matrix.node-version }} diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 66f1323..f1ae1ba 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -2,6 +2,9 @@ name: Lint on: [ push ] +env: + CI: true + jobs: lint: @@ -10,7 +13,7 @@ jobs: strategy: matrix: - node-version: [ 14 ] + node-version: [ 16 ] steps: - uses: actions/checkout@v2 @@ -18,16 +21,12 @@ jobs: with: fetch-depth: 1 - - uses: actions/setup-node@v2 + - uses: actions/setup-node@v3 name: Use Node.js ${{ matrix.node-version }} with: node-version: ${{ matrix.node-version }} - - name: Install - run: npm install + - run: npm install - name: Lint run: npm run lint - - env: - CI: true diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index df4a67c..0000000 --- a/.travis.yml +++ /dev/null @@ -1,19 +0,0 @@ -language: node_js -node_js: - - "12" - -services: - - redis-server - -before_script: - -script: - - npm run lint - - npm test - -after_success: - - npm install istanbul codecov - - npm run cover - - npx codecov - -sudo: false diff --git a/Changes.md b/Changes.md index 04add9f..76e1832 100644 --- a/Changes.md +++ b/Changes.md @@ -1,4 +1,14 @@ +## 2.2.0 - 2022-05-23 + +- dep(node): require 14+ +- dep(redis): bump 3 -> 4 +- dep(eslint): bump 7 -> 8 +- test: update redis test syntax for v4 +- doc(README): deprecate usage of 'plugin' +- doc(README): update badges + + ## 2.1.0 - 2021-10-14 - bump redis dep 2.8.0 -> 3.1.2 @@ -7,33 +17,39 @@ - use es6 classes - es6: use "for item of array" syntax for array iterator + ## 2.0.3 - 2017-08-26 - add redis_publish boolean to disable redis results publishing + ## 2.0.2 - 2017-06-26 - revert #4, until a proper and tested fix is available + ## 2.0.1 - 2017-05-26 - eslint 4 compat + ## 2.0.0 - 2017-05-26 - Disable Redis pub/sub by default + ## 1.0.2 - 2017-02-13 - publish incr operations - update eslint to inherit eslint-plugin-haraka - added AppVeyor (windows) testing + ## 1.0.1 - 2017-01-26 - update eslint to inherit eslint-plugin-haraka * depend on haraka-config * vs ./config, which doesn't work for npm packaged plugin tests -## 1.0.0 - initial release +## 1.0.0 - initial release diff --git a/README.md b/README.md index 14fda7e..2dc5fcd 100644 --- a/README.md +++ b/README.md @@ -21,26 +21,25 @@ Use results in your plugins like so: ```js exports.my_first_hook = function (next, connection) { - let plugin = this // run a test ...... // store the results - connection.results.add(plugin, {pass: 'my great test' }) + connection.results.add(this, {pass: 'my great test' }) // run another test ..... // store the results - connection.results.add(plugin, {fail: 'gotcha!', msg: 'show this'}) + connection.results.add(this, {fail: 'gotcha!', msg: 'show this'}) } ``` Store the results in the transaction (vs connection): ```js - connection.transaction.results.add(plugin, {...});` + connection.transaction.results.add(this, {...});` ``` ### Config options @@ -83,18 +82,18 @@ Examples: ```js const results = connection.results - results.add(plugin, {pass: 'null_sender'}) - results.add(plugin, {fail: 'single_recipient'}) - results.add(plugin, {skip: 'valid_bounce'} - results.add(plugin, {err: 'timed out looking in couch cushions'}) - results.add(plugin, {msg: 'I found a nickel!', emit: true}) + results.add(this, {pass: 'null_sender'}) + results.add(this, {fail: 'single_recipient'}) + results.add(this, {skip: 'valid_bounce'} + results.add(this, {err: 'timed out looking in couch cushions'}) + results.add(this, {msg: 'I found a nickel!', emit: true}) ``` In addition to appending values to the predefined lists, arbitrary results can be stored in the cache: ```js - results.add(plugin, {my_result: 'anything I want'}) + results.add(this, {my_result: 'anything I want'}) ``` When arbirary values are stored, they are listed first in the log output. Their @@ -107,10 +106,10 @@ Increment counters. The argument to incr is an object with counter names and increment values. Examples: ```js - results.incr(plugin, {unrecognized_commands: 1}) + results.incr(this, {unrecognized_commands: 1}) - results.incr(plugin, {karma: -1}) - results.incr(plugin, {karma: 2}) + results.incr(this, {karma: -1}) + results.incr(this, {karma: 2}) ``` @@ -120,14 +119,14 @@ Append items onto arrays. The argument to push is an object with array names and the new value to be appended to the array. Examples: ```js - results.push(plugin, {dns_recs: 'name1'}) - results.push(plugin, {dns_recs: 'name2'}) + results.push(this, {dns_recs: 'name1'}) + results.push(this, {dns_recs: 'name2'}) ``` #### collate ```js - const summary = results.collate(plugin) + const summary = results.collate(this) ``` Formats the contents of the result cache and returns them. This function is @@ -174,8 +173,8 @@ Syntax: #### Store Results: ```js - results.add(plugin, {pass: 'some_test'}) - results.add(plugin, {pass: 'some_test(with reason)'}) + results.add(this, {pass: 'some_test'}) + results.add(this, {pass: 'some_test(with reason)'}) ``` #### Retrieve exact match with **get**: @@ -215,7 +214,7 @@ human_html output, prefix the name of the key with an underscore. Example: ```js - results.add(plugin, { _hidden: 'some data' }) + results.add(this, { _hidden: 'some data' }) ``` ## Redis Pub/Sub @@ -237,9 +236,8 @@ exports.register = function (next, server) { } exports.redis_subscribe = function (next, connection) { - const plugin = this - plugin.redis_subscribe(connection, function () { + this.redis_subscribe(connection, function () { connection.notes.redis.on('pmessage', (pattern, channel, message) => { // do stuff with messages that look like this // {"plugin":"karma","result":{"fail":"spamassassin.hits"}} diff --git a/index.js b/index.js index b90f22b..ae4d2fc 100644 --- a/index.js +++ b/index.js @@ -66,7 +66,6 @@ class ResultStore { if (!this.conn.server.notes.redis) return; const channel = `result-${this.conn.transaction ? this.conn.transaction.uuid : this.conn.uuid}`; - this.conn.server.notes.redis.publish(channel, JSON.stringify({ plugin: name, result: obj })); } diff --git a/package.json b/package.json index 97e06cf..1ef73ef 100644 --- a/package.json +++ b/package.json @@ -1,15 +1,18 @@ { "name": "haraka-results", - "version": "2.1.0", + "version": "2.2.0", "description": "Haraka results store for connections and transactions", "main": "index.js", "directories": { "test": "test" }, + "engines": { + "node": ">=14" + }, "scripts": { + "cover": "npx istanbul cover npm run test", "lint": "npx eslint *.js test/*.js", "lintfix": "npx eslint --fix *.js test/*.js", - "cover": "npx istanbul cover ./run_tests", "test": "npx mocha" }, "repository": { @@ -29,16 +32,15 @@ }, "homepage": "https://github.com/haraka/haraka-results#readme", "devDependencies": { - "eslint": ">=7", + "eslint": ">=8", "eslint-plugin-haraka": "*", "haraka-test-fixtures": "*", - "redis": "*", "mocha": "*" }, "dependencies": { "haraka-config": "*" }, "optionalDependencies": { - "redis": "^3.1.2" + "redis": "^4.1.0" } } diff --git a/test/result_store.js b/test/result_store.js index 6e1ea03..8b6a020 100644 --- a/test/result_store.js +++ b/test/result_store.js @@ -173,26 +173,24 @@ describe('redis_publish', () => { redis: require('redis').createClient(), } }; + await server.notes.redis.connect() this.connection = new fixtures.connection.createConnection(null, server); this.connection.results = new Results(this.connection); }) - it('redis_publish', function (done) { + it('redis_publish', async function () { const conn = this.connection; - // this redis client is subscribed - const sub_db = redis.createClient(); - sub_db.on('pmessage', function (pattern, channel, message) { - // console.log(arguments); + const sub_db = redis.createClient() + + await sub_db.connect() + + await sub_db.pSubscribe('*', (message, channel) => { assert.equal(JSON.parse(message).result.pass, 'the test'); conn.server.notes.redis.quit() sub_db.quit() - done() }) - .on('psubscribe', function (pattern, count) { - // console.log(`psubscribed to ${pattern}`); - conn.results.add({ name: 'pi'}, { pass: 'the test'}); - }) - .psubscribe('*'); + + conn.results.add({ name: 'pi'}, { pass: 'the test'}) }) })