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
This commit is contained in:
Daniel Lockyer 2021-06-14 16:27:13 +01:00
parent de9960fc45
commit 0cd9acabec
No known key found for this signature in database
GPG Key ID: D21186F0B47295AD
8 changed files with 24 additions and 1 deletions

View File

@ -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;

View File

@ -1,3 +1,6 @@
/**
* @param {import('bookshelf')} Bookshelf
*/
const customQueryPlug = function customQueryPlug(Bookshelf) {
const Model = Bookshelf.Model.extend({
// override this on the model itself

View File

@ -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;

View File

@ -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

View File

@ -22,6 +22,9 @@ const addHasPostsWhere = (tableName, config) => {
};
};
/**
* @param {import('bookshelf')} Bookshelf
*/
const hasPosts = function hasPosts(Bookshelf) {
const modelPrototype = Bookshelf.Model.prototype;

View File

@ -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 = {

View File

@ -1,5 +1,8 @@
const _ = require('lodash');
/**
* @param {import('bookshelf')} Bookshelf
*/
const orderPlugin = function orderPlugin(Bookshelf) {
Bookshelf.Model = Bookshelf.Model.extend({
orderAttributes() {},

View File

@ -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