From 43898cdd317a127bc45e8b3cb2f160df386760a1 Mon Sep 17 00:00:00 2001 From: Justin Wind Date: Mon, 19 Sep 2022 11:01:10 -0700 Subject: [PATCH] clean up lint issues --- .eslintrc.json | 4 ++++ src/common.js | 8 ++++---- src/communication.js | 8 ++++---- src/db/base.js | 2 +- src/db/postgres/index.js | 2 +- src/db/sqlite/index.js | 7 ++++--- src/enum.js | 10 ++++++++++ src/template/template-helper.js | 19 ++++++++++--------- 8 files changed, 38 insertions(+), 22 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index e6c6f89..e5277a1 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -83,6 +83,10 @@ "error", "single" ], + "semi": [ + "error", + "always" + ], "strict": "error", "vars-on-top": "error" } diff --git a/src/common.js b/src/common.js index 55a0807..4ed310f 100644 --- a/src/common.js +++ b/src/common.js @@ -57,7 +57,7 @@ const freezeDeep = (o) => { } }); return o; -} +}; /** @@ -111,7 +111,7 @@ const attemptRetrySeconds = (attempt, retryBackoffSeconds = [60, 120, 360, 1440, let seconds = retryBackoffSeconds[attempt]; seconds += Math.floor(Math.random() * seconds * jitter); return seconds; -} +}; /** @@ -122,7 +122,7 @@ const attemptRetrySeconds = (attempt, retryBackoffSeconds = [60, 120, 360, 1440, const arrayChunk = (array, per = 1) => { const nChunks = Math.ceil(array.length / per); return Array.from(Array(nChunks), (_, i) => array.slice(i * per, (i + 1) * per)); -} +}; /** @@ -135,7 +135,7 @@ const stackSafePush = (dst, src) => { arrayChunk(src, jsEngineMaxArguments).forEach((items) => { Array.prototype.push.apply(dst, items); }); -} +}; /** diff --git a/src/communication.js b/src/communication.js index 3b43678..feda588 100644 --- a/src/communication.js +++ b/src/communication.js @@ -220,8 +220,8 @@ class Communication { const topic = await this.db.topicGetById(dbCtx, verification.topicId); if (!topic) { - this.logger.error(_scope, 'no such topic id', { verification, requestId }); - throw new Errors.InternalInconsistencyError('no such topic id'); + this.logger.error(_scope, Enum.Message.NoSuchTopicId, { verification, requestId }); + throw new Errors.InternalInconsistencyError(Enum.Message.NoSuchTopicId); } if (!topic.isActive) { @@ -438,8 +438,8 @@ class Communication { const topic = await this.db.topicGetById(dbCtx, topicId); if (topic === undefined) { - this.logger.error(_scope, 'no such topic id', logInfoData); - throw new Errors.InternalInconsistencyError('no such topic id'); + this.logger.error(_scope, Enum.Message.NoSuchTopicId, logInfoData); + throw new Errors.InternalInconsistencyError(Enum.Message.NoSuchTopicId); } // Cull any expired subscriptions diff --git a/src/db/base.js b/src/db/base.js index c5ea237..205b814 100644 --- a/src/db/base.js +++ b/src/db/base.js @@ -137,7 +137,7 @@ class Database { * @param {Object} data */ _leaseDurationsValidate(data) { - const leaseProperties = Object.keys(this.topicLeaseDefaults) + const leaseProperties = Object.keys(this.topicLeaseDefaults); this._ensureTypes(data, leaseProperties, ['number', 'undefined', 'null']); // Populate defaults on a copy of values so we can check proper numerical ordering diff --git a/src/db/postgres/index.js b/src/db/postgres/index.js index 2eca12f..e70aeb7 100644 --- a/src/db/postgres/index.js +++ b/src/db/postgres/index.js @@ -377,7 +377,7 @@ class DatabasePostgres extends Database { throw new DBErrors.UnexpectedResult('did not upsert authentication'); } } catch (e) { - this.logger.error(_scope, 'failed', { error: e, identifier, scrubbedCredential }) + this.logger.error(_scope, 'failed', { error: e, identifier, scrubbedCredential }); throw e; } } diff --git a/src/db/sqlite/index.js b/src/db/sqlite/index.js index 76309d6..a30c9b4 100644 --- a/src/db/sqlite/index.js +++ b/src/db/sqlite/index.js @@ -302,7 +302,7 @@ class DatabaseSQLite extends Database { throw new DBErrors.UnexpectedResult('did not upsert authentication'); } } catch (e) { - this.logger.error(_scope, 'failed', { error: e, identifier, scrubbedCredential }) + this.logger.error(_scope, 'failed', { error: e, identifier, scrubbedCredential }); throw e; } } @@ -558,7 +558,7 @@ class DatabaseSQLite extends Database { httpRemoteAddr: null, httpFrom: null, ...data, - } + }; this._subscriptionUpsertDataValidate(subscriptionData); let result; @@ -827,10 +827,11 @@ class DatabaseSQLite extends Database { topicPublishHistory(dbCtx, topicId, days) { const _scope = _fileScope('topicPublishHistory'); - this.logger.debug(_scope, 'called', { topicId, days }) + this.logger.debug(_scope, 'called', { topicId, days }); const events = this.statement.topicPublishHistory.all({ topicId, daysAgo: days }); const history = Array.from({ length: days }, () => 0); + // eslint-disable-next-line security/detect-object-injection events.forEach(({ daysAgo, contentUpdates }) => history[daysAgo] = Number(contentUpdates)); return history; diff --git a/src/enum.js b/src/enum.js index b8eaf3e..0b4978d 100644 --- a/src/enum.js +++ b/src/enum.js @@ -36,6 +36,16 @@ const Enum = common.mergeDeep(DingusEnum, { ImageSVG: 'image/svg+xml', TextXML: 'text/xml', }, + + Message : { + BeginningOfTime: 'Beginning of Time', + EndOfTime: 'End of Time', + Never: 'Never', + NextPublish: 'Next Publish', + NoSuchTopicId: 'no such topic id', + Pending: 'Pending', + Unknown: 'Unknown', + }, }); module.exports = common.freezeDeep(Enum); \ No newline at end of file diff --git a/src/template/template-helper.js b/src/template/template-helper.js index 3fd3710..23b0f12 100644 --- a/src/template/template-helper.js +++ b/src/template/template-helper.js @@ -1,6 +1,7 @@ 'use strict'; const { TemplateHelper } = require('@squeep/html-template-helper'); +const { Message } = require('../enum'); /** * Render a topic as a row of details. @@ -18,17 +19,17 @@ function renderTopicRow(topic, subscribers, detailsLink = true) { return ` ${detailsLink ? '' : ''}${topic.url}${detailsLink ? '' : ''} ${subscribers.length} - ${TemplateHelper.dateFormat(topic.created, 'End of Time', 'Beginning of Time', 'Unknown')} + ${TemplateHelper.dateFormat(topic.created, Message.EndOfTime, Message.BeginningOfTime, Message.Unknown)} ${TemplateHelper.secondsToPeriod(topic.leaseSecondsPreferred)} ${TemplateHelper.secondsToPeriod(topic.leaseSecondsMin)} ${TemplateHelper.secondsToPeriod(topic.leaseSecondsMax)} ${topic.publisherValidationUrl ? topic.publisherValidationUrl : 'None'} ${topic.isActive} ${topic.isDeleted} - ${TemplateHelper.dateFormat(topic.lastPublish, 'End of Time', 'Never', 'Never')} - ${TemplateHelper.dateFormat(topic.contentFetchNextAttempt, 'Next Publish', 'Pending', 'Next Publish')} + ${TemplateHelper.dateFormat(topic.lastPublish, Message.EndOfTime, Message.Never, Message.Never)} + ${TemplateHelper.dateFormat(topic.contentFetchNextAttempt, Message.NextPublish, Message.Pending, Message.NextPublish)} ${topic.contentFetchAttemptsSinceSuccess} - ${TemplateHelper.dateFormat(topic.contentUpdated, 'End of Time', 'Never', 'Never')} + ${TemplateHelper.dateFormat(topic.contentUpdated, Message.EndOfTime, Message.Never, Message.Never)} ${topic.contentType} ${topic.id} `; @@ -73,16 +74,16 @@ function renderSubscriptionRow(subscription) { } return ` ${subscription.callback} - ${TemplateHelper.dateFormat(subscription.created, 'End of Time', 'Beginning of Time', 'Unknown')} - ${TemplateHelper.dateFormat(subscription.verified, 'End of Time', 'Never', 'Never')} - ${TemplateHelper.dateFormat(subscription.expires, 'Never', 'Beginning of Time', 'Never')} + ${TemplateHelper.dateFormat(subscription.created, Message.EndOfTime, Message.BeginningOfTime, Message.Unknown)} + ${TemplateHelper.dateFormat(subscription.verified, Message.EndOfTime, Message.Never, Message.Never)} + ${TemplateHelper.dateFormat(subscription.expires, Message.Never, Message.BeginningOfTime, Message.Never)} ${!!subscription.secret} ${subscription.signatureAlgorithm} ${subscription.httpRemoteAddr} ${subscription.httpFrom} - ${TemplateHelper.dateFormat(subscription.contentDelivered, 'End of Time', 'Never', 'Never')} + ${TemplateHelper.dateFormat(subscription.contentDelivered, Message.EndOfTime, Message.Never, Message.Never)} ${subscription.deliveryAttemptsSinceSuccess} - ${TemplateHelper.dateFormat(subscription.deliveryNextAttempt, 'End of Time', 'Next Publish', 'Next Publish')} + ${TemplateHelper.dateFormat(subscription.deliveryNextAttempt, Message.EndOfTime, Message.NextPublish, Message.NextPublish)} ${subscription.id} `; } -- 2.43.2