From 28de4364128a4b03918a8cbe868009b5d427220a Mon Sep 17 00:00:00 2001 From: Justin Wind Date: Sun, 8 Aug 2021 12:05:24 -0700 Subject: [PATCH] fix and enforce indent rules --- .eslintrc.json | 7 +++++++ .markdownlint.json | 4 ++++ CHANGELOG.md | 12 ++++++++++-- package-lock.json | 20 ++++++++++---------- src/authenticator.js | 2 +- src/common.js | 6 +++--- src/db/base.js | 16 ++++++++-------- src/db/postgres/index.js | 2 +- src/db/sqlite/index.js | 2 +- src/link-helper.js | 8 ++++---- src/manager.js | 2 +- src/service.js | 25 +++++++++++++------------ src/template/root-html.js | 2 +- src/template/template-helper.js | 4 ++-- src/worker.js | 2 +- 15 files changed, 67 insertions(+), 47 deletions(-) create mode 100644 .markdownlint.json diff --git a/.eslintrc.json b/.eslintrc.json index 1a60b64..e6c6f89 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -55,6 +55,13 @@ "error", "last" ], + "indent": [ + "warn", + 2, + { + "SwitchCase": 1 + } + ], "sonarjs/cognitive-complexity": "warn", "sonarjs/no-duplicate-string": "warn", "keyword-spacing": "error", diff --git a/.markdownlint.json b/.markdownlint.json new file mode 100644 index 0000000..18e3c71 --- /dev/null +++ b/.markdownlint.json @@ -0,0 +1,4 @@ +{ + "MD013": false, + "MD024": false +} diff --git a/CHANGELOG.md b/CHANGELOG.md index d299b62..126fab9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,13 +4,21 @@ Releases and notable changes to this project are documented here. ## [Unreleased] +## [v1.1.0] - + +### Added + +- Caching of topic contents for Postfix database backends. This should greatly reduce the db load when many subscribers to a topic are delivered an update. +- Minor cleanup to generated HTML pages. + ## [v1.0.0] - 2021-08-01 ### Added -Everything. MVP first stable release. +- Everything. MVP first stable release. --- -[Unreleased]: https://git.squeep.com/?p=websub-hub;a=commitdiff;h=HEAD;hp=v1.0.0 +[Unreleased]: https://git.squeep.com/?p=websub-hub;a=commitdiff;h=HEAD;hp=v1.1.0 +[v1.1.0]: https://git.squeep.com/?p=websub-hub;a=commitdiff;h=v1.1.0;hp=v1.0.0 [v1.0.0]: https://git.squeep.com/?p=websub-hub;a=commitdiff;h=v1.0.0;hp=v0.0.0 \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 410c0aa..401fffd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -572,18 +572,13 @@ "dev": true }, "@squeep/api-dingus": { - "version": "git+https://git.squeep.com/squeep-api-dingus/#16db6709ab8407b1f696e3d5f92aa6980f182f39", - "from": "git+https://git.squeep.com/squeep-api-dingus/#v1.0.0", + "version": "git+https://git.squeep.com/squeep-api-dingus/#12b96f53e7976b74296c1e024432b88749e6c4b0", + "from": "git+https://git.squeep.com/squeep-api-dingus/#v1.1-dev", "requires": { "mime-db": "^1.49.0", "uuid": "^8.3.2" }, "dependencies": { - "mime-db": { - "version": "1.49.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.49.0.tgz", - "integrity": "sha512-CIc8j9URtOVApSFCQIF+VBkX1RwXp/oMMOrqdyXSBXq5RWNEsRfyj1kiRnQgmNXmHxPoFIxOroKA3zcU9P+nAA==" - }, "uuid": { "version": "8.3.2", "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", @@ -2178,6 +2173,11 @@ } } }, + "mime-db": { + "version": "1.49.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.49.0.tgz", + "integrity": "sha512-CIc8j9URtOVApSFCQIF+VBkX1RwXp/oMMOrqdyXSBXq5RWNEsRfyj1kiRnQgmNXmHxPoFIxOroKA3zcU9P+nAA==" + }, "mimic-response": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-2.1.0.tgz", @@ -3438,9 +3438,9 @@ } }, "tar": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/tar/-/tar-6.1.0.tgz", - "integrity": "sha512-DUCttfhsnLCjwoDoFcI+B2iJgYa93vBnDUATYEeRx6sntCTdN01VnqsIuTlALXla/LWooNg0yEGeB+Y8WdFxGA==", + "version": "6.1.6", + "resolved": "https://registry.npmjs.org/tar/-/tar-6.1.6.tgz", + "integrity": "sha512-oaWyu5dQbHaYcyZCTfyPpC+VmI62/OM2RTUYavTk1MDr1cwW5Boi3baeYQKiZbY2uSQJGr+iMOzb/JFxLrft+g==", "requires": { "chownr": "^2.0.0", "fs-minipass": "^2.0.0", diff --git a/src/authenticator.js b/src/authenticator.js index ed4fc40..7053b56 100644 --- a/src/authenticator.js +++ b/src/authenticator.js @@ -103,7 +103,7 @@ class Authenticator { const authData = req.getHeader(Enum.Header.Authorization); if (authData && await this.isValidAuthorization(authData, ctx)) { - return true; + return true; } return this.requestBasic(res); } diff --git a/src/common.js b/src/common.js index b82b13e..0cacc3b 100644 --- a/src/common.js +++ b/src/common.js @@ -84,7 +84,7 @@ const topicLeaseDefaults = () => { * @param {Number} jitter * @returns {Number} */ - const attemptRetrySeconds = (attempt, retryBackoffSeconds = [60, 120, 360, 1440, 7200, 43200, 86400], jitter = 0.618) => { +const attemptRetrySeconds = (attempt, retryBackoffSeconds = [60, 120, 360, 1440, 7200, 43200, 86400], jitter = 0.618) => { const maxAttempt = retryBackoffSeconds.length - 1; if (typeof attempt !== 'number' || attempt < 0) { attempt = 0; @@ -103,7 +103,7 @@ const topicLeaseDefaults = () => { * @param {Array} array * @param {Number} per */ - const arrayChunk = (array, per = 1) => { +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)); } @@ -114,7 +114,7 @@ const topicLeaseDefaults = () => { * @param {Array} dst * @param {Array} src */ - const stackSafePush = (dst, src) => { +const stackSafePush = (dst, src) => { const jsEngineMaxArguments = 2**16; // Current as of Node 12 arrayChunk(src, jsEngineMaxArguments).forEach((items) => { Array.prototype.push.apply(dst, items); diff --git a/src/db/base.js b/src/db/base.js index 8d72d0f..21e2664 100644 --- a/src/db/base.js +++ b/src/db/base.js @@ -76,7 +76,7 @@ class Database { * @param {String} method * @param {arguments} args */ - _notImplemented(method, args) { + _notImplemented(method, args) { this.logger.error(_fileScope(method), 'abstract method called', Array.from(args)); throw new DBErrors.NotImplemented(method); } @@ -89,7 +89,7 @@ class Database { * Some engines will also perform other initializations or async actions which * are easier handled outside the constructor. */ - async initialize() { + async initialize() { const _scope = _fileScope('initialize'); const currentSchema = await this._currentSchema(); @@ -416,7 +416,7 @@ class Database { * @param {String} callback * @param {*} topicId */ - async subscriptionGet(dbCtx, callback, topicId) { + async subscriptionGet(dbCtx, callback, topicId) { this._notImplemented('subscriptionGet', arguments); } @@ -442,7 +442,7 @@ class Database { * @param {String=} data.httpRemoteAddr * @param {String=} data.httpFrom */ - async subscriptionUpsert(dbCtx, data) { + async subscriptionUpsert(dbCtx, data) { this._notImplemented('subscriptionUpsert', arguments); } @@ -520,7 +520,7 @@ class Database { * @param {*} topicId * @returns {Boolean} */ - async topicFetchRequested(dbCtx, topicId) { + async topicFetchRequested(dbCtx, topicId) { this._notImplemented('topicPublish', arguments); } @@ -679,7 +679,7 @@ class Database { * @param {Boolean} claim * @returns {*} verificationId */ - async verificationInsert(dbCtx, verification) { + async verificationInsert(dbCtx, verification) { this._notImplemented('verificationInsert', arguments); } @@ -704,9 +704,9 @@ class Database { * @param {String} data.reason * @param {Boolean} data.isPublisherValidated */ - async verificationUpdate(dbCtx, verificationId, data) { + async verificationUpdate(dbCtx, verificationId, data) { this._notImplemented('verificationUpdate', arguments); - } + } /** diff --git a/src/db/postgres/index.js b/src/db/postgres/index.js index e6b5f5b..1c5d1d1 100644 --- a/src/db/postgres/index.js +++ b/src/db/postgres/index.js @@ -739,7 +739,7 @@ class DatabasePostgres extends Database { let topics; try { topics = await dbCtx.manyOrNone(this.statement.topicGetInfoAll); - } catch (e) { + } catch (e) { this.logger.error(_scope, 'failed', { error: e, topics }); throw e; } diff --git a/src/db/sqlite/index.js b/src/db/sqlite/index.js index 775708d..a4c3d38 100644 --- a/src/db/sqlite/index.js +++ b/src/db/sqlite/index.js @@ -687,7 +687,7 @@ class DatabaseSQLite extends Database { let topics; try { topics = this.statement.topicGetInfoAll.all(); - } catch (e) { + } catch (e) { this.logger.error(_scope, 'failed', { error: e, topics }); throw e; } diff --git a/src/link-helper.js b/src/link-helper.js index 428f031..1f3cd09 100644 --- a/src/link-helper.js +++ b/src/link-helper.js @@ -117,8 +117,7 @@ class LinkHelper { .map(([name, value]) => ({ name, value })), }; links.push(link); - }); - + }); }); feedParser.on('readable', () => { let _item; @@ -147,8 +146,8 @@ class LinkHelper { const link = { target: attributes.href, attributes: Object.entries(attributes) - .filter(([name]) => name !== 'href') - .map(([name, value]) => ({ name, value })), + .filter(([name]) => name !== 'href') + .map(([name, value]) => ({ name, value })), }; links.push(link); } @@ -159,6 +158,7 @@ class LinkHelper { return links; } + /** * Attempt to resolve a relative target URI * @param {String} uri diff --git a/src/manager.js b/src/manager.js index b3aff45..6fb187c 100644 --- a/src/manager.js +++ b/src/manager.js @@ -40,7 +40,7 @@ class Manager { * @param {http.ServerResponse} res * @param {object} ctx */ - async getHealthcheck(res, ctx) { + async getHealthcheck(res, ctx) { const _scope = _fileScope('getHealthcheck'); const health = 'happy'; diff --git a/src/service.js b/src/service.js index dfba6b8..c69f6fb 100644 --- a/src/service.js +++ b/src/service.js @@ -66,7 +66,7 @@ class Service extends Dingus { * @param {Object} ctx * @param {String} newPath */ - async handlerRedirect(req, res, ctx, newPath) { + async handlerRedirect(req, res, ctx, newPath) { const _scope = _fileScope('handlerRedirect'); this.logger.debug(_scope, 'called', { req: common.requestLogData(req), ctx }); @@ -185,8 +185,9 @@ class Service extends Dingus { await this.manager.getTopicDetails(res, ctx); } + /** - * Same as super.ingestBody, but if no body was send, do not parse (and + * Same as super.ingestBody, but if no body was sent, do not parse (and * thus avoid possible unsupported media type error). * @param {http.ClientRequest} req * @param {http.ServerResponse} res @@ -206,7 +207,7 @@ class Service extends Dingus { * @param {http.ServerResponse} res * @param {Object} ctx */ - async handlerUpdateTopic(req, res, ctx) { + async handlerUpdateTopic(req, res, ctx) { const _scope = _fileScope('handlerUpdateTopic'); this.logger.debug(_scope, 'called', { req: common.requestLogData(req), ctx }); @@ -226,17 +227,17 @@ class Service extends Dingus { * @param {Object} ctx */ async handlerUpdateSubscription(req, res, ctx) { - const _scope = _fileScope('handlerUpdateSubscription'); - this.logger.debug(_scope, 'called', { req: common.requestLogData(req), ctx }); + const _scope = _fileScope('handlerUpdateSubscription'); + this.logger.debug(_scope, 'called', { req: common.requestLogData(req), ctx }); - this.setResponseType(this.responseTypes, req, res, ctx); + this.setResponseType(this.responseTypes, req, res, ctx); - await this.authenticator.required(req, res, ctx); + await this.authenticator.required(req, res, ctx); - await this.maybeIngestBody(req, res, ctx); - ctx.method = req.method; - await this.manager.updateSubscription(res, ctx); -} + await this.maybeIngestBody(req, res, ctx); + ctx.method = req.method; + await this.manager.updateSubscription(res, ctx); + } /** @@ -254,7 +255,7 @@ class Service extends Dingus { this.setResponseType(this.responseTypes, req, res, ctx); await this.serveFile(req, res, ctx, this.staticPath, file || ctx.params.file); - this.logger.info(_scope, 'finished', { ctx }); + this.logger.info(_scope, 'finished', { ctx: { ...ctx, responseBody: common.logTruncate((ctx.responseBody || '').toString(), 100) } }); } diff --git a/src/template/root-html.js b/src/template/root-html.js index 97a1ad9..d1939b8 100644 --- a/src/template/root-html.js +++ b/src/template/root-html.js @@ -83,7 +83,7 @@ function usageSection(isPublicHub, hubURL) { ` - : ` + : `

Private Hub

This hub only serves specific topics. diff --git a/src/template/template-helper.js b/src/template/template-helper.js index eb37917..b48a90a 100644 --- a/src/template/template-helper.js +++ b/src/template/template-helper.js @@ -30,7 +30,7 @@ const dateOrNot = (date, otherwise) => { * @param {Number} seconds * @returns {String} */ - const secondsToPeriod = (seconds) => { +const secondsToPeriod = (seconds) => { let value = seconds; const result = []; @@ -212,7 +212,7 @@ function htmlHeader(pageTitle, navLinks = []) {

    ${navLinks.map((l) => renderNavLink(l)).join('\n')}
` - : '') + ` + : '') + `
`; diff --git a/src/worker.js b/src/worker.js index f956ba1..ca77369 100644 --- a/src/worker.js +++ b/src/worker.js @@ -95,7 +95,7 @@ class Worker { isSettled = true; rejected = rej; throw rej; - }); + }); Object.defineProperties(promise, { isSettled: { get: () => isSettled }, -- 2.43.2