use log-helper fileScope, minor lint fix
authorJustin Wind <justin.wind+git@gmail.com>
Fri, 17 Nov 2023 18:35:25 +0000 (10:35 -0800)
committerJustin Wind <justin.wind+git@gmail.com>
Fri, 17 Nov 2023 19:43:58 +0000 (11:43 -0800)
lib/base.js
lib/common.js [deleted file]
lib/consumer.js
lib/publisher.js
package-lock.json
package.json

index 87607daeb6e7c1402feb490c5a0fc5c513ea6f1a..0805d07dff2b4ccf4f30a03e404f8a1bb1eba0d7 100644 (file)
@@ -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 (file)
index 68b7b5e..0000000
+++ /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
index bd25b02ea6097a222b36c6bc63282c42e8e5957e..f31d5e1e5458e4ba8c8c7b5426c1d04eca2d6ed0 100644 (file)
@@ -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) {
index 453b575734ff6a83529689681c716e376e8f9649..19987f1fb37abc76d0f02dcbf9d666112242c0b4 100644 (file)
@@ -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) {
index f2534fafa49e82b7d1548c2e81b0674299e1b5f3..6983c86eae8d21127f71f8c3b483bcba498e3304 100644 (file)
@@ -9,6 +9,7 @@
       "version": "1.0.0",
       "license": "ISC",
       "dependencies": {
+        "@squeep/log-helper": "^1.0.0",
         "amqplib": "^0.10.3"
       },
       "devDependencies": {
       "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",
       "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,
index 83812f3f0f40a5ed00b908467968d4a723250d41..a921e236caf864e2d1423c57a894c81579b95fe3 100644 (file)
     "eslint": "eslint *.js lib",
     "test": "mocha --recursive"
   },
-  "author": "",
+  "author": "Justin Wind <jwind-npm@squeep.com>",
   "license": "ISC",
   "dependencies": {
+    "@squeep/log-helper": "^1.0.0",
     "amqplib": "^0.10.3"
   },
   "devDependencies": {