diff --git a/server/__mocks__/logger.ts b/server/__mocks__/logger.ts index 418620c..eba31a8 100644 --- a/server/__mocks__/logger.ts +++ b/server/__mocks__/logger.ts @@ -1,5 +1,5 @@ -import { LogLevel, TaggedLogger } from "../types"; -import { ActivatableLogger } from "../logger"; +import type { LogLevel, TaggedLogger } from "../types"; +import type { ActivatableLogger } from "../logger"; export type MockLogMessages = unknown[][]; type TaggedLogMessages = { diff --git a/server/db/__mocks__/database.ts b/server/db/__mocks__/database.ts index 769b188..b5a9bc6 100644 --- a/server/db/__mocks__/database.ts +++ b/server/db/__mocks__/database.ts @@ -80,4 +80,4 @@ export class MockDatabase implements TypedDatabase { export const db: MockDatabase = new MockDatabase(); -export { TypedDatabase, Statement }; +export { Statement }; diff --git a/server/db/database.ts b/server/db/database.ts index 3a96105..3259c50 100644 --- a/server/db/database.ts +++ b/server/db/database.ts @@ -6,7 +6,7 @@ import { config } from "../config"; import Logger from "../logger"; import { Database, open, Statement } from "sqlite"; import * as sqlite3 from "sqlite3"; -import { RunResult, SqlType, TypedDatabase } from "../types"; +import type { RunResult, SqlType, TypedDatabase } from "../types"; const pglob = util.promisify(glob); const pReadFile = util.promisify(fs.readFile); diff --git a/server/mail/index.ts b/server/mail/index.ts index 3bf343b..5eb69fd 100644 --- a/server/mail/index.ts +++ b/server/mail/index.ts @@ -1,7 +1,7 @@ import { createTransport, Transporter } from "nodemailer"; import { config } from "../config"; import * as MailTemplateService from "../services/mailTemplateService"; -import Mail from "nodemailer/lib/mailer"; +import type Mail from "nodemailer/lib/mailer"; import SMTPTransport from "nodemailer/lib/smtp-transport"; let transporterSingleton: Transporter | null = null; diff --git a/server/resources/frontendResource.ts b/server/resources/frontendResource.ts index 6fcd278..d1096af 100644 --- a/server/resources/frontendResource.ts +++ b/server/resources/frontendResource.ts @@ -3,7 +3,7 @@ import { promises as fs } from "graceful-fs"; import ErrorTypes from "../utils/errorTypes"; import Logger from "../logger"; import * as Resources from "../utils/resources"; -import { Request, Response } from "express"; +import type { Request, Response } from "express"; const indexHtml = __dirname + "/../../client/index.html"; diff --git a/server/resources/mailResource.ts b/server/resources/mailResource.ts index 143a648..6c0cea1 100644 --- a/server/resources/mailResource.ts +++ b/server/resources/mailResource.ts @@ -5,7 +5,7 @@ import * as Resources from "../utils/resources"; import { handleJSONWithData, RequestData } from "../utils/resources"; import { normalizeString, parseInteger } from "../shared/utils/strings"; import { forConstraint } from "../shared/validation/validator"; -import { Request, Response } from "express"; +import type { Request, Response } from "express"; import { isString, Mail, MailId } from "../types"; const isValidId = forConstraint(CONSTRAINTS.id, false); diff --git a/server/resources/monitoringResource.ts b/server/resources/monitoringResource.ts index e81ec55..a1be4bb 100644 --- a/server/resources/monitoringResource.ts +++ b/server/resources/monitoringResource.ts @@ -5,7 +5,7 @@ import * as Resources from "../utils/resources"; import { handleJSONWithData } from "../utils/resources"; import { normalizeString } from "../shared/utils/strings"; import { forConstraint } from "../shared/validation/validator"; -import { Request, Response } from "express"; +import type { Request, Response } from "express"; import { isMonitoringToken, JSONObject, diff --git a/server/resources/nodeResource.ts b/server/resources/nodeResource.ts index 2f1808f..10b6d62 100644 --- a/server/resources/nodeResource.ts +++ b/server/resources/nodeResource.ts @@ -6,7 +6,7 @@ import { normalizeMac, normalizeString } from "../shared/utils/strings"; import { forConstraint, forConstraints } from "../shared/validation/validator"; import * as Resources from "../utils/resources"; import { handleJSONWithData } from "../utils/resources"; -import { Request, Response } from "express"; +import type { Request, Response } from "express"; import { CreateOrUpdateNode, DomainSpecificNodeResponse, diff --git a/server/resources/taskResource.ts b/server/resources/taskResource.ts index dfadc96..feb03f6 100644 --- a/server/resources/taskResource.ts +++ b/server/resources/taskResource.ts @@ -5,7 +5,7 @@ import { handleJSONWithData, RequestData } from "../utils/resources"; import { getTasks, Task } from "../jobs/scheduler"; import { normalizeString } from "../shared/utils/strings"; import { forConstraint } from "../shared/validation/validator"; -import { Request, Response } from "express"; +import type { Request, Response } from "express"; import { isString, isTaskSortField, diff --git a/server/services/mailService.ts b/server/services/mailService.ts index 351f791..6cca5c4 100644 --- a/server/services/mailService.ts +++ b/server/services/mailService.ts @@ -4,7 +4,7 @@ import { db } from "../db/database"; import Logger from "../logger"; import * as MailTemplateService from "./mailTemplateService"; import * as Resources from "../utils/resources"; -import { RestParams } from "../utils/resources"; +import type { RestParams } from "../utils/resources"; import { EmailAddress, isJSONObject, diff --git a/server/services/mailTemplateService.ts b/server/services/mailTemplateService.ts index 9605115..2dbe15f 100644 --- a/server/services/mailTemplateService.ts +++ b/server/services/mailTemplateService.ts @@ -7,8 +7,8 @@ import { htmlToText } from "nodemailer-html-to-text"; import { config } from "../config"; import Logger from "../logger"; import { editNodeUrl } from "../utils/urlBuilder"; -import { Transporter } from "nodemailer"; -import { MailData, Mail } from "../types"; +import type { Transporter } from "nodemailer"; +import type { MailData, Mail } from "../types"; const templateBasePath = __dirname + "/../mailTemplates"; const snippetsBasePath = templateBasePath + "/snippets"; diff --git a/server/services/monitoringService.test.ts b/server/services/monitoringService.test.ts index cbb8e59..241d1e9 100644 --- a/server/services/monitoringService.test.ts +++ b/server/services/monitoringService.test.ts @@ -1,7 +1,7 @@ import { ParsedNode, parseNode, parseNodesJson } from "./monitoringService"; import { Domain, MAC, OnlineState, Site, UnixTimestampSeconds } from "../types"; import Logger from "../logger"; -import { MockLogger } from "../__mocks__/logger"; +import type { MockLogger } from "../__mocks__/logger"; import { now, parseTimestamp } from "../utils/time"; const mockedLogger = Logger as MockLogger; diff --git a/server/services/monitoringService.ts b/server/services/monitoringService.ts index a8dd83e..57c915a 100644 --- a/server/services/monitoringService.ts +++ b/server/services/monitoringService.ts @@ -10,7 +10,7 @@ import Logger from "../logger"; import * as MailService from "../services/mailService"; import * as NodeService from "../services/nodeService"; import * as Resources from "../utils/resources"; -import { RestParams } from "../utils/resources"; +import type { RestParams } from "../utils/resources"; import { normalizeMac, parseInteger } from "../shared/utils/strings"; import { monitoringDisableUrl } from "../utils/urlBuilder"; import CONSTRAINTS from "../shared/validation/constraints"; diff --git a/server/shared/types/newtypes.ts b/server/shared/types/newtypes.ts index d62b876..144c0c0 100644 --- a/server/shared/types/newtypes.ts +++ b/server/shared/types/newtypes.ts @@ -140,3 +140,15 @@ export type Domain = string & { readonly __tag: unique symbol }; * @param arg - Value to check. */ export const isDomain = toIsNewtype(isString, "" as Domain); + +/** + * A search term entered by the user in the frontend. + */ +export type SearchTerm = string & { readonly __tag: unique symbol }; + +/** + * Type guard for {@link Domain}. + * + * @param arg - Value to check. + */ +export const isSearchTerm = isString; diff --git a/server/tsconfig.json b/server/tsconfig.json index 9abae53..9359523 100644 --- a/server/tsconfig.json +++ b/server/tsconfig.json @@ -19,8 +19,9 @@ // "removeComments": true, /* Do not emit comments to output. */ // "noEmit": true, /* Do not emit outputs. */ // "importHelpers": true, /* Import emit helpers from 'tslib'. */ + "importsNotUsedAsValues": "error", /* Enforce using `import type` instead of `import` for types */ // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ - // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ + "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ /* Strict Type-Checking Options */ "strict": true, /* Enable all strict type-checking options. */ @@ -29,7 +30,7 @@ // "strictFunctionTypes": true, /* Enable strict checking of function types. */ // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ - // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ + "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ /* Additional Checks */ diff --git a/server/utils/resources.ts b/server/utils/resources.ts index 4ebcbbf..1600acc 100644 --- a/server/utils/resources.ts +++ b/server/utils/resources.ts @@ -9,7 +9,7 @@ import { isConstraints, NestedConstraints, } from "../shared/validation/validator"; -import { Request, Response } from "express"; +import type { Request, Response } from "express"; import { type GenericSortField, isJSONObject, diff --git a/server/utils/urlBuilder.ts b/server/utils/urlBuilder.ts index e2888d6..0e6a6f3 100644 --- a/server/utils/urlBuilder.ts +++ b/server/utils/urlBuilder.ts @@ -1,5 +1,5 @@ import { config } from "../config"; -import { MonitoringToken, Url } from "../types"; +import type { MonitoringToken, Url } from "../types"; function formUrl(route: string, queryParams?: { [key: string]: string }): Url { let url = config.server.baseUrl as string;