X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=src%2Fdb%2Fbase.js;h=36cca60328875280620395ae5a4578ebef3136ee;hb=71efac9dcd7dc219cb83799391e7adc63cd4c662;hp=8a1df74b9bfb344d1457fa4ff3e9df932b27b6c0;hpb=9696c012e6b9a6c58904baa397ca0ebf78112316;p=websub-hub diff --git a/src/db/base.js b/src/db/base.js index 8a1df74..36cca60 100644 --- a/src/db/base.js +++ b/src/db/base.js @@ -76,27 +76,27 @@ 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); } /** - * Validate schema compatibility. - * Ensure this is called immediately after instantiating a DB instance, - * as some engines also finish initialization and validation here, which - * was easier than wrangling async calls in constructor. - * In light of this behavior, this method could be named better. - */ - async schemaCheck() { - const _scope = _fileScope('schemaCheck'); + * Perform tasks needed to prepare database for use. Ensure this is called + * after construction, and before any other database activity. + * At the minimum, this will validate a compatible schema is present and usable. + * Some engines will also perform other initializations or async actions which + * are easier handled outside the constructor. + */ + async initialize() { + const _scope = _fileScope('initialize'); const currentSchema = await this._currentSchema(); const current = svh.schemaVersionObjectToNumber(currentSchema); const min = svh.schemaVersionObjectToNumber(this.schemaVersionsSupported.min); const max = svh.schemaVersionObjectToNumber(this.schemaVersionsSupported.max); - if (min >= current && max <= current) { + if (current >= min && current <= max) { this.logger.debug(_scope, 'schema supported', { currentSchema, schemaVersionsSupported: this.schemaVersionsSupported }); } else { this.logger.error(_scope, 'schema not supported', { currentSchema, schemaVersionsSupported: this.schemaVersionsSupported }); @@ -173,6 +173,8 @@ class Database { this._ensureTypes(data, ['content'], ['string', 'buffer']); this._ensureTypes(data, ['contentHash'], ['string']); this._ensureTypes(data, ['contentType'], ['string', 'null', 'undefined']); + this._ensureTypes(data, ['eTag'], ['string', 'null', 'undefined']); + this._ensureTypes(data, ['lastModified'], ['string', 'null', 'undefined']); } @@ -351,6 +353,16 @@ class Database { } + /** + * Remove any expired subscriptions to a topic. + * @param {*} dbCtx + * @param {*} topicId + */ + async subscriptionDeleteExpired(dbCtx, topicId) { + this._notImplemented('subscriptionDeleteExpired', arguments); + } + + /** * Claim subscriptions needing content updates attempted. * @param {*} dbCtx @@ -416,7 +428,7 @@ class Database { * @param {String} callback * @param {*} topicId */ - async subscriptionGet(dbCtx, callback, topicId) { + async subscriptionGet(dbCtx, callback, topicId) { this._notImplemented('subscriptionGet', arguments); } @@ -442,7 +454,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 +532,7 @@ class Database { * @param {*} topicId * @returns {Boolean} */ - async topicFetchRequested(dbCtx, topicId) { + async topicFetchRequested(dbCtx, topicId) { this._notImplemented('topicPublish', arguments); } @@ -533,6 +545,7 @@ class Database { this._notImplemented('topicGetAll', arguments); } + /** * Get topic data, without content. * @param {*} dbCtx @@ -563,14 +576,27 @@ class Database { this._notImplemented('topicGetContentById', arguments); } - // /** - // * Call after an unsubscribe, to check if a topic is awaiting deletion, and that - // * was the last subscription belaying it. - // * @param {String|Integer} data topic url or id - // */ - // async topicPendingDelete(dbCtx, data) { - // this._notImplemented('topicPendingDelete', arguments); - // } + + /** + * Attempt to delete a topic, which must be set isDeleted, if there + * are no more subscriptions belaying its removal. + * @param {*} topicId + */ + async topicPendingDelete(dbCtx, topicId) { + this._notImplemented('topicPendingDelete', arguments); + } + + + /** + * Return an array of the counts of the last #days of topic updates. + * @param {*} dbCtx + * @param {*} topicId + * @param {Number} days + * @returns {Number[]} + */ + async topicPublishHistory(dbCtx, topicId, days) { + this._notImplemented('topicPublishHistory', arguments); + } /** @@ -586,10 +612,12 @@ class Database { /** * Updates a topic's content data and content update timestamp. * @param {Object} data - * @param {Integer} data.topicId + * @param {*} data.topicId * @param {String} data.content * @param {String} data.contentHash * @param {String=} data.contentType + * @param {String=} data.eTag + * @param {String=} data.lastModified */ async topicSetContent(dbCtx, data) { this._notImplemented('topicSetContent', arguments); @@ -679,7 +707,7 @@ class Database { * @param {Boolean} claim * @returns {*} verificationId */ - async verificationInsert(dbCtx, verification) { + async verificationInsert(dbCtx, verification) { this._notImplemented('verificationInsert', arguments); } @@ -704,9 +732,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); - } + } /**