From a56600c8c49e94daafaf879f8fdf2f871098c310 Mon Sep 17 00:00:00 2001 From: Rowan Manning <138944+rowanmanning@users.noreply.github.com> Date: Thu, 17 Oct 2024 12:08:40 +0100 Subject: [PATCH] Migrate to @import statements These are available in later versions of TypeScript and they're a lot neater/easier to understand. Let's use them. --- main.js | 6 ++---- src/lib/guess-app-details.js | 2 +- src/lib/health-checks.js | 4 ++-- src/middleware/anon.js | 4 +--- src/middleware/backend-authentication.js | 5 ++--- src/middleware/cache.js | 7 +++++-- src/middleware/consent.js | 2 +- src/middleware/log-vary.js | 2 +- src/middleware/robots.js | 2 +- src/middleware/security.js | 2 +- src/middleware/vary.js | 2 +- src/middleware/via.js | 2 +- 12 files changed, 19 insertions(+), 21 deletions(-) diff --git a/main.js b/main.js index dbcf1a48..b9db4685 100644 --- a/main.js +++ b/main.js @@ -1,8 +1,6 @@ /** - * @typedef {import("express").Application} Application - * @typedef {import("./typings/n-express").Callback} Callback - * @typedef {import("./typings/n-express").AppOptions} AppOptions - * @typedef {import("./typings/n-express").AppContainer} AppContainer + * @import {Application} from 'express' + * @import {AppContainer, AppOptions, Callback} from './typings/n-express' */ require('isomorphic-fetch'); diff --git a/src/lib/guess-app-details.js b/src/lib/guess-app-details.js index 308c3e21..28745c21 100644 --- a/src/lib/guess-app-details.js +++ b/src/lib/guess-app-details.js @@ -1,5 +1,5 @@ /** - * @typedef {import("../../typings/n-express").AppMeta} AppMeta + * @import {AppMeta} from '../../typings/n-express' */ const normalizeName = require('./normalize-name'); diff --git a/src/lib/health-checks.js b/src/lib/health-checks.js index ec970fff..663e040c 100644 --- a/src/lib/health-checks.js +++ b/src/lib/health-checks.js @@ -1,6 +1,6 @@ /** - * @typedef {import("express").Application} ExpressApp - * @typedef {import("../../typings/n-express").AppOptions} AppOptions + * @import {Application as ExpressApp} from 'express' + * @import {AppOptions} from '../../typings/n-express' */ const logger = require('@dotcom-reliability-kit/logger'); diff --git a/src/middleware/anon.js b/src/middleware/anon.js index 5d1a2acc..a8174cce 100644 --- a/src/middleware/anon.js +++ b/src/middleware/anon.js @@ -1,7 +1,5 @@ /** - * @typedef {import("../../typings/n-express").Callback} Callback - * @typedef {import("../../typings/n-express").Request} Request - * @typedef {import("../../typings/n-express").Response} Response + * @import {Callback, Request, Response} from '../../typings/n-express' */ /** diff --git a/src/middleware/backend-authentication.js b/src/middleware/backend-authentication.js index 877f1707..ff831127 100644 --- a/src/middleware/backend-authentication.js +++ b/src/middleware/backend-authentication.js @@ -1,6 +1,5 @@ /** - * @typedef {import("express")} Express - * @typedef {import("../../typings/n-express").Callback} Callback + * @import Express from 'express' */ const logger = require('@dotcom-reliability-kit/logger'); @@ -39,7 +38,7 @@ module.exports = (app) => { // @ts-ignore app.use( - /** @type {Callback} */ (req, res, next) => { + /** @type {Express.Handler} */ (req, res, next) => { // allow static assets, healthchecks, etc., through if (req.path.indexOf('/__') === 0) { next(); diff --git a/src/middleware/cache.js b/src/middleware/cache.js index 7e93113e..1e644ffa 100644 --- a/src/middleware/cache.js +++ b/src/middleware/cache.js @@ -1,6 +1,9 @@ /** - * @typedef {import("../../typings/n-express").Callback} Callback - * @typedef {[key: keyof import("../../typings/n-express").CacheHeaders, val: string]} CacheHeader + * @import {Callback, CacheHeaders} from '../../typings/n-express' + */ + +/** + * @typedef {[key: keyof CacheHeaders, val: string]} CacheHeader */ const cacheHeaders = { diff --git a/src/middleware/consent.js b/src/middleware/consent.js index 36fc3148..56a46493 100644 --- a/src/middleware/consent.js +++ b/src/middleware/consent.js @@ -1,5 +1,5 @@ /** - * @typedef {import("../../typings/n-express").Callback} Callback + * @import {Callback} from '../../typings/n-express' */ /** diff --git a/src/middleware/log-vary.js b/src/middleware/log-vary.js index 6f07825a..731ec167 100644 --- a/src/middleware/log-vary.js +++ b/src/middleware/log-vary.js @@ -1,5 +1,5 @@ /** - * @typedef {import("../../typings/n-express").Callback} Callback + * @import {Callback} from '../../typings/n-express' */ const logger = require('@dotcom-reliability-kit/logger'); diff --git a/src/middleware/robots.js b/src/middleware/robots.js index be1b0e75..22154702 100644 --- a/src/middleware/robots.js +++ b/src/middleware/robots.js @@ -1,5 +1,5 @@ /** - * @typedef {import("../../typings/n-express").Callback} Callback + * @import {Callback} from '../../typings/n-express' */ const fs = require('fs'); diff --git a/src/middleware/security.js b/src/middleware/security.js index ec2b9206..2d64ad74 100644 --- a/src/middleware/security.js +++ b/src/middleware/security.js @@ -1,5 +1,5 @@ /** - * @typedef {import("../../typings/n-express").Callback} Callback + * @import {Callback} from '../../typings/n-express' */ /** diff --git a/src/middleware/vary.js b/src/middleware/vary.js index a553d4f5..183a2672 100644 --- a/src/middleware/vary.js +++ b/src/middleware/vary.js @@ -1,5 +1,5 @@ /** - * @typedef {import("../../typings/n-express").Callback} Callback + * @import {Callback} from '../../typings/n-express' */ /** diff --git a/src/middleware/via.js b/src/middleware/via.js index 268d046d..404fad8d 100644 --- a/src/middleware/via.js +++ b/src/middleware/via.js @@ -1,5 +1,5 @@ /** - * @typedef {import("../../typings/n-express").Callback} Callback + * @import {Callback} from '../../typings/n-express' */ /**