From 54c143a1b4d6d6edb80e51c8d608f71df3d88fd2 Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Sun, 16 Oct 2022 14:43:35 +0700 Subject: [PATCH] Fixed optional syntax style for jsdoc refs https://jsdoc.app/tags-param.html#optional-parameters-and-default-values - using an equals sign in the type definition is part of the Google Closure syntax but we use the JSDoc syntax in all other places, and tsc detects the different syntax - this commit standardizes the syntax ahead of enforcing a certain style down the line --- .../serializers/output/mappers/snippets.js | 4 +-- .../utils/serializers/output/members.js | 6 ++-- .../core/core/server/data/schema/commands.js | 35 +++++++++++-------- ghost/magic-link/lib/MagicLink.js | 6 ++-- ghost/members-api/lib/repositories/product.js | 2 +- ghost/stripe/lib/StripeAPI.js | 2 +- ghost/stripe/lib/WebhookManager.js | 12 +++---- 7 files changed, 37 insertions(+), 30 deletions(-) diff --git a/ghost/core/core/server/api/endpoints/utils/serializers/output/mappers/snippets.js b/ghost/core/core/server/api/endpoints/utils/serializers/output/mappers/snippets.js index 6331d6e3e9..0e5ae4adb4 100644 --- a/ghost/core/core/server/api/endpoints/utils/serializers/output/mappers/snippets.js +++ b/ghost/core/core/server/api/endpoints/utils/serializers/output/mappers/snippets.js @@ -22,8 +22,8 @@ module.exports = (snippet, frame) => { /** * @typedef {Object} SerializedSnippet * @prop {string} id - * @prop {string=} name - * @prop {string=} mobiledoc + * @prop {string} [name] + * @prop {string} [mobiledoc] * @prop {string} created_at * @prop {string} updated_at * @prop {string} created_by diff --git a/ghost/core/core/server/api/endpoints/utils/serializers/output/members.js b/ghost/core/core/server/api/endpoints/utils/serializers/output/members.js index 7e3d689030..4182e63e74 100644 --- a/ghost/core/core/server/api/endpoints/utils/serializers/output/members.js +++ b/ghost/core/core/server/api/endpoints/utils/serializers/output/members.js @@ -216,15 +216,15 @@ function createSerializer(debugString, serialize) { * @prop {string} id * @prop {string} uuid * @prop {string} email - * @prop {string=} name - * @prop {string=} note + * @prop {string} [name] + * @prop {string} [note] * @prop {null|string} geolocation * @prop {boolean} subscribed * @prop {string} created_at * @prop {string} updated_at * @prop {string[]} labels * @prop {SerializedMemberStripeSubscription[]} subscriptions - * @prop {SerializedMemberProduct[]=} products + * @prop {SerializedMemberProduct[]} [products] * @prop {string} avatar_image * @prop {boolean} comped * @prop {number} email_count diff --git a/ghost/core/core/server/data/schema/commands.js b/ghost/core/core/server/data/schema/commands.js index 04dc071cb9..fc1e7a08fc 100644 --- a/ghost/core/core/server/data/schema/commands.js +++ b/ghost/core/core/server/data/schema/commands.js @@ -73,6 +73,9 @@ function dropNullable(tableName, column, transaction = db.knex) { }); } +/** + * @param {string} + */ async function addColumn(tableName, column, transaction = db.knex, columnSpec) { const addColumnBuilder = transaction.schema.table(tableName, function (table) { addTableColumn(tableName, table, column, columnSpec); @@ -85,14 +88,16 @@ async function addColumn(tableName, column, transaction = db.knex, columnSpec) { return; } - let sql = addColumnBuilder.toSQL()[0].sql; + for (const sqlQuery of addColumnBuilder.toSQL()) { + let sql = sqlQuery.sql; - if (DatabaseInfo.isMySQL(transaction)) { - // Guard against an ending semicolon - sql = sql.replace(/;\s*$/, '') + ', algorithm=copy'; + if (DatabaseInfo.isMySQL(transaction)) { + // Guard against an ending semicolon + sql = sql.replace(/;\s*$/, '') + ', algorithm=copy'; + } + + await transaction.raw(sql); } - - await transaction.raw(sql); } async function dropColumn(tableName, column, transaction = db.knex, columnSpec = {}) { @@ -101,25 +106,27 @@ async function dropColumn(tableName, column, transaction = db.knex, columnSpec = await dropForeign({fromTable: tableName, fromColumn: column, toTable, toColumn, transaction}); } - const dropTableBuilder = transaction.schema.table(tableName, function (table) { + const dropColumnBuilder = transaction.schema.table(tableName, function (table) { table.dropColumn(column); }); // Use the default flow for SQLite because .toSQL() is tricky with SQLite when // it does the table dance if (DatabaseInfo.isSQLite(transaction)) { - await dropTableBuilder; + await dropColumnBuilder; return; } - let sql = dropTableBuilder.toSQL()[0].sql; + for (const sqlQuery of dropColumnBuilder.toSQL()) { + let sql = sqlQuery.sql; - if (DatabaseInfo.isMySQL(transaction)) { - // Guard against an ending semicolon - sql = sql.replace(/;\s*$/, '') + ', algorithm=copy'; + if (DatabaseInfo.isMySQL(transaction)) { + // Guard against an ending semicolon + sql = sql.replace(/;\s*$/, '') + ', algorithm=copy'; + } + + await transaction.raw(sql); } - - await transaction.raw(sql); } /** diff --git a/ghost/magic-link/lib/MagicLink.js b/ghost/magic-link/lib/MagicLink.js index abbd43563c..a46b23b88b 100644 --- a/ghost/magic-link/lib/MagicLink.js +++ b/ghost/magic-link/lib/MagicLink.js @@ -52,8 +52,8 @@ class MagicLink { * @param {object} options * @param {string} options.email - The email to send magic link to * @param {TokenData} options.tokenData - The data for token - * @param {string=} [options.type='signin'] - The type to be passed to the url and content generator functions - * @param {string=} [options.referrer=null] - The referrer of the request, if exists + * @param {string} [options.type='signin'] - The type to be passed to the url and content generator functions + * @param {string} [options.referrer=null] - The referrer of the request, if exists * @returns {Promise<{token: Token, info: SentMessageInfo}>} */ async sendMagicLink(options) { @@ -83,7 +83,7 @@ class MagicLink { * * @param {object} options * @param {TokenData} options.tokenData - The data for token - * @param {string=} [options.type='signin'] - The type to be passed to the url and content generator functions. This type will also get stored in the token data. + * @param {string} [options.type='signin'] - The type to be passed to the url and content generator functions. This type will also get stored in the token data. * @returns {Promise} - signin URL */ async getMagicLink(options) { diff --git a/ghost/members-api/lib/repositories/product.js b/ghost/members-api/lib/repositories/product.js index 04c5f464e6..9e03a77a61 100644 --- a/ghost/members-api/lib/repositories/product.js +++ b/ghost/members-api/lib/repositories/product.js @@ -314,7 +314,7 @@ class ProductRepository { * @param {string} data.welcome_page_url * @param {BenefitInput[]} data.benefits * - * @param {StripePriceInput[]=} data.stripe_prices + * @param {StripePriceInput[]} [data.stripe_prices] * @param {StripePriceInput|null} data.monthly_price * @param {StripePriceInput|null} data.yearly_price * diff --git a/ghost/stripe/lib/StripeAPI.js b/ghost/stripe/lib/StripeAPI.js index af56a99144..7a09083402 100644 --- a/ghost/stripe/lib/StripeAPI.js +++ b/ghost/stripe/lib/StripeAPI.js @@ -139,7 +139,7 @@ module.exports = class StripeAPI { * @param {string} id * @param {object} options * @param {boolean} options.active - * @param {string=} options.nickname + * @param {string} [options.nickname] * * @returns {Promise} */ diff --git a/ghost/stripe/lib/WebhookManager.js b/ghost/stripe/lib/WebhookManager.js index 628f98de3e..cf154b0431 100644 --- a/ghost/stripe/lib/WebhookManager.js +++ b/ghost/stripe/lib/WebhookManager.js @@ -97,7 +97,7 @@ module.exports = class WebhookManager { /** * @param {object} config - * @param {string=} config.webhookSecret An optional webhook secret for use with stripe-cli, passing this will ensure a webhook is not created in Stripe + * @param {string} [config.webhookSecret] An optional webhook secret for use with stripe-cli, passing this will ensure a webhook is not created in Stripe * @param {string} config.webhookHandlerUrl The URL which the Webhook should hit * * @returns {Promise} @@ -111,11 +111,11 @@ module.exports = class WebhookManager { } /** - * @param {string=} id - * @param {string=} secret - * @param {object=} opts - * @param {boolean} opts.forceCreate - * @param {boolean} opts.skipDelete + * @param {string} [id] + * @param {string} [secret] + * @param {object} [opts] + * @param {boolean} [opts.forceCreate] + * @param {boolean} [opts.skipDelete] * * @returns {Promise} */