bump package version to 1.0.1
[squeep-amqp-helper] / lib / publisher.js
index 453b575734ff6a83529689681c716e376e8f9649..0c7ac3d743d77679e51e334fdc26a9cdbc04e1ef 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) {
@@ -16,11 +16,17 @@ class Publisher extends Base {
     persistent: true,
   };
 
+  /**
+   * @typedef {object} PublishOptions
+   * @property {number} timestamp timestamp in ms, defaults to current
+   * @property {boolean} persistent defaults to true
+   */
   /**
    * Send a message to an exchange.
-   * @param {String} name
-   * @param {*} content
-   * @param {Object} options
+   * @param {string} name name
+   * @param {*} content message content
+   * @param {PublishOptions} options options
+   * @returns {Promise<void>}
    */
   async publish(name, content, options) {
     const _scope = _fileScope('publish');
@@ -31,8 +37,12 @@ class Publisher extends Base {
       content = Buffer.from(typeof(content) === 'object' ? JSON.stringify(content) : content);
     }
 
-    const timestamp = (new Date()).getTime();
-    options = Object.assign({ timestamp }, Publisher.publishDefaults, options);
+    const timestamp = Date.now();
+    options = {
+      timestamp,
+      ...Publisher.publishDefaults,
+      ...options,
+    };
 
     return new Promise((resolve, reject) => {
       if (!this.keepSending) {
@@ -82,8 +92,7 @@ class Publisher extends Base {
 
   /**
    * Producer only needs to plumb the exchange it sends to.
-   * 
-   * @param {String} name
+   * @param {string} name name
    */
   async establishAMQPPlumbing(name) {
     const _scope = _fileScope('establishAMQPPlumbing');