From 0cd9acabec07284a54b00e844ac07e7554d05b5d Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Mon, 14 Jun 2021 16:27:13 +0100 Subject: [PATCH] Imported Bookshelf type into plugin JSDocs no issue - the `Bookshelf` type wasn't being imported anywhere and editors were showing warnings for the missing type - also fixes use of `Bookshelf.Model` - this doesn't work if we declare `Bookshelf` using a `@typedef` and the preferred syntax is using an array index - note: it still complains because we're calling functions that are only declared in our custom Bookshelf Model but this is a step in the right direction --- core/server/models/plugins/collision.js | 3 +++ core/server/models/plugins/custom-query.js | 3 +++ core/server/models/plugins/eager-load.js | 1 + core/server/models/plugins/filter.js | 3 +++ core/server/models/plugins/has-posts.js | 3 +++ core/server/models/plugins/include-count.js | 3 +++ core/server/models/plugins/order.js | 3 +++ core/server/models/plugins/pagination.js | 6 +++++- 8 files changed, 24 insertions(+), 1 deletion(-) diff --git a/core/server/models/plugins/collision.js b/core/server/models/plugins/collision.js index fb3b0af11d..a79a60f274 100644 --- a/core/server/models/plugins/collision.js +++ b/core/server/models/plugins/collision.js @@ -3,6 +3,9 @@ const Promise = require('bluebird'); const _ = require('lodash'); const errors = require('@tryghost/errors'); +/** + * @param {import('bookshelf')} Bookshelf + */ module.exports = function (Bookshelf) { const ParentModel = Bookshelf.Model; diff --git a/core/server/models/plugins/custom-query.js b/core/server/models/plugins/custom-query.js index 26ef11f9ea..ec373b8618 100644 --- a/core/server/models/plugins/custom-query.js +++ b/core/server/models/plugins/custom-query.js @@ -1,3 +1,6 @@ +/** + * @param {import('bookshelf')} Bookshelf + */ const customQueryPlug = function customQueryPlug(Bookshelf) { const Model = Bookshelf.Model.extend({ // override this on the model itself diff --git a/core/server/models/plugins/eager-load.js b/core/server/models/plugins/eager-load.js index 174fe191e4..2e53fb7e54 100644 --- a/core/server/models/plugins/eager-load.js +++ b/core/server/models/plugins/eager-load.js @@ -47,6 +47,7 @@ function load(options) { * a join to "eager loaded" relation. An exaple of such loading is when * there is a need to order by fields in the related table. * + * @param {import('bookshelf')} Bookshelf */ module.exports = function eagerLoadPlugin(Bookshelf) { const modelPrototype = Bookshelf.Model.prototype; diff --git a/core/server/models/plugins/filter.js b/core/server/models/plugins/filter.js index 104ca9a079..4b0ba5c686 100644 --- a/core/server/models/plugins/filter.js +++ b/core/server/models/plugins/filter.js @@ -80,6 +80,9 @@ const EXPANSIONS = { }] }; +/** + * @param {import('bookshelf')} Bookshelf + */ const filter = function filter(Bookshelf) { const Model = Bookshelf.Model.extend({ // Cached copy of the filters setup for this model instance diff --git a/core/server/models/plugins/has-posts.js b/core/server/models/plugins/has-posts.js index 0f82b46f75..6a5bcca7d5 100644 --- a/core/server/models/plugins/has-posts.js +++ b/core/server/models/plugins/has-posts.js @@ -22,6 +22,9 @@ const addHasPostsWhere = (tableName, config) => { }; }; +/** + * @param {import('bookshelf')} Bookshelf + */ const hasPosts = function hasPosts(Bookshelf) { const modelPrototype = Bookshelf.Model.prototype; diff --git a/core/server/models/plugins/include-count.js b/core/server/models/plugins/include-count.js index 5a7eec891b..fe35ffb271 100644 --- a/core/server/models/plugins/include-count.js +++ b/core/server/models/plugins/include-count.js @@ -2,6 +2,9 @@ const _debug = require('ghost-ignition').debug._base; const debug = _debug('ghost-query'); const _ = require('lodash'); +/** + * @param {import('bookshelf')} Bookshelf + */ module.exports = function (Bookshelf) { const modelProto = Bookshelf.Model.prototype; const countQueryBuilder = { diff --git a/core/server/models/plugins/order.js b/core/server/models/plugins/order.js index 395d6cf86b..840779aefd 100644 --- a/core/server/models/plugins/order.js +++ b/core/server/models/plugins/order.js @@ -1,5 +1,8 @@ const _ = require('lodash'); +/** + * @param {import('bookshelf')} Bookshelf + */ const orderPlugin = function orderPlugin(Bookshelf) { Bookshelf.Model = Bookshelf.Model.extend({ orderAttributes() {}, diff --git a/core/server/models/plugins/pagination.js b/core/server/models/plugins/pagination.js index d32cdcb80a..8b91a44bb7 100644 --- a/core/server/models/plugins/pagination.js +++ b/core/server/models/plugins/pagination.js @@ -99,7 +99,7 @@ paginationUtils = { /** * - * @param {Bookshelf.Model} model instance of Bookshelf model + * @param {Bookshelf['Model']} model instance of Bookshelf model * @param {string} propertyName property to be inspected and included in the relation */ handleRelation: function handleRelation(model, propertyName) { @@ -268,6 +268,10 @@ const pagination = function pagination(bookshelf) { }); }; +/** + * @typedef {import('bookshelf')} Bookshelf + */ + /** * ## Export pagination plugin * @api public