From: Justin Wind Date: Fri, 17 Nov 2023 18:35:25 +0000 (-0800) Subject: use log-helper fileScope, minor lint fix X-Git-Tag: v1.0.1~2 X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=b27af23673b86d25c29a82d3774c7a3b046004cb;p=squeep-amqp-helper use log-helper fileScope, minor lint fix --- diff --git a/lib/base.js b/lib/base.js index 87607da..0805d07 100644 --- a/lib/base.js +++ b/lib/base.js @@ -1,9 +1,9 @@ 'use strict'; const amqp = require('amqplib'); const { isFatalError: isFatalAMQPError } = require('amqplib/lib/connection'); -const common = require('./common'); +const { fileScope } = require('@squeep/log-helper'); -const _fileScope = common.fileScope(__filename); +const _fileScope = fileScope(__filename); /** * Base class common to worker publisher and consumer, handling @@ -25,7 +25,7 @@ class Base { */ constructor(logger, options) { this.logger = logger; - this.options = Object.assign({ + this.options = { url: undefined, name: 'messages', prefix: 'squeep', @@ -35,14 +35,16 @@ class Base { queueType: 'quorum', retryDelayMs: 10000, prefetch: 1, - }, options); - this.options.socketOptions = Object.assign({ + ...options, + }; + this.options.socketOptions = { noDelay: undefined, timeout: undefined, keepAlive: undefined, keepAliveDelay: undefined, clientProperties: undefined, - }, options.socketOptions); + ...options.socketOptions, + }; this.connection = undefined; this.channel = undefined; @@ -50,7 +52,7 @@ class Base { /** - * Establish the necessary connections to the queue and lock services. + * Establish the necessary connections to the queue. */ async connect() { const _scope = _fileScope('connect'); diff --git a/lib/common.js b/lib/common.js deleted file mode 100644 index 68b7b5e..0000000 --- a/lib/common.js +++ /dev/null @@ -1,19 +0,0 @@ -'use strict'; -const path = require('path'); -const { name: packageName, version: packageVersion } = require('../package'); - -const libraryIdentifier = `${packageName}@${packageVersion}`; - -/** - * Return a function for decorating logging method scopes. - * @param {String} filename - */ -const fileScope = (filename) => { - const shortFilename = path.basename(filename, '.js'); - const fScope = (shortFilename === 'index') ? path.basename(path.dirname(filename)) : shortFilename; - return (scope) => [libraryIdentifier, fScope, scope].join(':'); -}; - -module.exports = { - fileScope, -}; \ No newline at end of file diff --git a/lib/consumer.js b/lib/consumer.js index bd25b02..f31d5e1 100644 --- a/lib/consumer.js +++ b/lib/consumer.js @@ -1,8 +1,8 @@ 'use strict'; const Base = require('./base'); -const common = require('./common'); +const { fileScope } = require('@squeep/log-helper'); -const _fileScope = common.fileScope(__filename); +const _fileScope = fileScope(__filename); class Consumer extends Base { constructor(logger, options) { diff --git a/lib/publisher.js b/lib/publisher.js index 453b575..19987f1 100644 --- a/lib/publisher.js +++ b/lib/publisher.js @@ -1,8 +1,8 @@ 'use strict'; const Base = require('./base'); -const common = require('./common'); +const { fileScope } = require('@squeep/log-helper'); -const _fileScope = common.fileScope(__filename); +const _fileScope = fileScope(__filename); class Publisher extends Base { constructor(logger, options) { @@ -32,7 +32,11 @@ class Publisher extends Base { } const timestamp = (new Date()).getTime(); - options = Object.assign({ timestamp }, Publisher.publishDefaults, options); + options = { + timestamp, + ...Publisher.publishDefaults, + ...options, + }; return new Promise((resolve, reject) => { if (!this.keepSending) { diff --git a/package-lock.json b/package-lock.json index f2534fa..6983c86 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "1.0.0", "license": "ISC", "dependencies": { + "@squeep/log-helper": "^1.0.0", "amqplib": "^0.10.3" }, "devDependencies": { @@ -830,6 +831,14 @@ "integrity": "sha512-sXXKG+uL9IrKqViTtao2Ws6dy0znu9sOaP1di/jKGW1M6VssO8vlpXCQcpZ+jisQ1tTFAC5Jo/EOzFbggBagFQ==", "dev": true }, + "node_modules/@squeep/log-helper": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@squeep/log-helper/-/log-helper-1.0.0.tgz", + "integrity": "sha512-i61ECZLWQI2rhkXj9pDzH1Md5ICghL9zvh5QFVo0BTayuSrdS9SWkJ6gV1qWki/Xz6SuE0y0y145NyHlvOuVaw==", + "engines": { + "node": ">=14" + } + }, "node_modules/@squeep/test-helper": { "version": "1.0.1", "resolved": "git+https://git.squeep.com/squeep-test-helper#cc0f69b40de9ae3342f1b7a1784d37769e7f1e84", @@ -4494,6 +4503,11 @@ "integrity": "sha512-sXXKG+uL9IrKqViTtao2Ws6dy0znu9sOaP1di/jKGW1M6VssO8vlpXCQcpZ+jisQ1tTFAC5Jo/EOzFbggBagFQ==", "dev": true }, + "@squeep/log-helper": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@squeep/log-helper/-/log-helper-1.0.0.tgz", + "integrity": "sha512-i61ECZLWQI2rhkXj9pDzH1Md5ICghL9zvh5QFVo0BTayuSrdS9SWkJ6gV1qWki/Xz6SuE0y0y145NyHlvOuVaw==" + }, "@squeep/test-helper": { "version": "git+https://git.squeep.com/squeep-test-helper#cc0f69b40de9ae3342f1b7a1784d37769e7f1e84", "dev": true, diff --git a/package.json b/package.json index 83812f3..a921e23 100644 --- a/package.json +++ b/package.json @@ -16,9 +16,10 @@ "eslint": "eslint *.js lib", "test": "mocha --recursive" }, - "author": "", + "author": "Justin Wind ", "license": "ISC", "dependencies": { + "@squeep/log-helper": "^1.0.0", "amqplib": "^0.10.3" }, "devDependencies": {