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/arrays.ts b/server/shared/types/arrays.ts index 49c0dec..92a559f 100644 --- a/server/shared/types/arrays.ts +++ b/server/shared/types/arrays.ts @@ -3,7 +3,7 @@ * * @module arrays */ -import { TypeGuard } from "./helpers"; +import type { TypeGuard } from "./helpers"; /** * Type guard for an array with elements of type ``. diff --git a/server/shared/types/config.ts b/server/shared/types/config.ts index 96ec9e3..7e5d906 100644 --- a/server/shared/types/config.ts +++ b/server/shared/types/config.ts @@ -9,8 +9,15 @@ import { isBoolean, isNumber, isString } from "./primitives"; import { isArray } from "./arrays"; import { isOptional } from "./helpers"; import { isJSONObject } from "./json"; -import { Domain, isDomain, isSite, isUrl, Site, Url } from "./newtypes"; -import { EmailAddress, isEmailAddress } from "./email"; +import { + type Domain, + isDomain, + isSite, + isUrl, + type Site, + type Url, +} from "./newtypes"; +import { type EmailAddress, isEmailAddress } from "./email"; /** * Configuration for a single coordinate. diff --git a/server/shared/types/email.ts b/server/shared/types/email.ts index 842cda6..24c19c9 100644 --- a/server/shared/types/email.ts +++ b/server/shared/types/email.ts @@ -3,10 +3,10 @@ */ import { toIsNewtype } from "./newtypes"; import { isNumber, isString } from "./primitives"; -import { JSONObject } from "./json"; +import type { JSONObject } from "./json"; import { toIsEnum } from "./enums"; -import { SortFieldFor, toIsSortField } from "./sortfields"; -import { UnixTimestampSeconds } from "./time"; +import { type SortFieldFor, toIsSortField } from "./sortfields"; +import type { UnixTimestampSeconds } from "./time"; /** * An email address. diff --git a/server/shared/types/enums.ts b/server/shared/types/enums.ts index 7a5a1fd..2874024 100644 --- a/server/shared/types/enums.ts +++ b/server/shared/types/enums.ts @@ -1,7 +1,7 @@ /** * Contains type guards and helpers for enums. */ -import { TypeGuard, ValueOf } from "./helpers"; +import type { TypeGuard, ValueOf } from "./helpers"; /** * Shorthand type alias for enum {@link TypeGuard}s. diff --git a/server/shared/types/monitoring.ts b/server/shared/types/monitoring.ts index baf496f..6386fbc 100644 --- a/server/shared/types/monitoring.ts +++ b/server/shared/types/monitoring.ts @@ -2,21 +2,26 @@ * Contains types and type guards for monitoring data. */ import { - Domain, + type Domain, isDomain, isMAC, isSite, - MAC, - Site, + type MAC, + type Site, toIsNewtype, } from "./newtypes"; import { isBoolean, isNumber, isString } from "./primitives"; import { toIsEnum } from "./enums"; -import { Hostname, isHostname, isMapId, MapId } from "./node"; -import { EmailAddress, isEmailAddress, isMailType, MailType } from "./email"; -import { isUnixTimestampSeconds, UnixTimestampSeconds } from "./time"; +import { type Hostname, isHostname, isMapId, type MapId } from "./node"; +import { + type EmailAddress, + isEmailAddress, + isMailType, + MailType, +} from "./email"; +import { isUnixTimestampSeconds, type UnixTimestampSeconds } from "./time"; import { isOptional } from "./helpers"; -import { SortFieldFor, toIsSortField } from "./sortfields"; +import { type SortFieldFor, toIsSortField } from "./sortfields"; /** * Token for activating monitoring of a Freifunk node. This is being sent to verify the email address to use. diff --git a/server/shared/types/newtypes.ts b/server/shared/types/newtypes.ts index 9a0a609..144c0c0 100644 --- a/server/shared/types/newtypes.ts +++ b/server/shared/types/newtypes.ts @@ -6,7 +6,7 @@ * * Also holds newtype definitions that don't fit elsewhere. */ -import { TypeGuard } from "./helpers"; +import type { TypeGuard } from "./helpers"; import { isString } from "./primitives"; // ===================================================================================================================== @@ -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/shared/types/node.ts b/server/shared/types/node.ts index ac204f4..60368cd 100644 --- a/server/shared/types/node.ts +++ b/server/shared/types/node.ts @@ -3,25 +3,27 @@ */ import { isObject } from "./objects"; import { isOptional } from "./helpers"; -import { +import type { Coordinates, Domain, FastdKey, + MAC, + Nickname, + Site, +} from "./newtypes"; +import { isCoordinates, isDomain, isFastdKey, isMAC, isNickname, isSite, - MAC, - Nickname, - Site, toIsNewtype, } from "./newtypes"; import { isBoolean, isString } from "./primitives"; -import { SortFieldFor, toIsSortField } from "./sortfields"; -import { EmailAddress, isEmailAddress } from "./email"; -import { isUnixTimestampSeconds, UnixTimestampSeconds } from "./time"; +import { type SortFieldFor, toIsSortField } from "./sortfields"; +import { type EmailAddress, isEmailAddress } from "./email"; +import { isUnixTimestampSeconds, type UnixTimestampSeconds } from "./time"; import { isMonitoringState, isOnlineState, diff --git a/server/shared/types/sortfields.ts b/server/shared/types/sortfields.ts index 46c8601..43a2ab5 100644 --- a/server/shared/types/sortfields.ts +++ b/server/shared/types/sortfields.ts @@ -1,9 +1,9 @@ /** * Contains helper types and type guards for sort fields. */ -import { Enum, toIsEnum } from "./enums"; +import { type Enum, toIsEnum } from "./enums"; import { isString } from "./primitives"; -import { TypeGuard } from "./helpers"; +import type { TypeGuard } from "./helpers"; /** * Generic untyped sort field. diff --git a/server/shared/types/task.ts b/server/shared/types/task.ts index c482cf0..4ecb71c 100644 --- a/server/shared/types/task.ts +++ b/server/shared/types/task.ts @@ -5,12 +5,12 @@ import { toIsEnum } from "./enums"; import { isNullable } from "./helpers"; import { isPlainObject } from "./objects"; import { isBoolean, isNumber, isString } from "./primitives"; -import { SortFieldFor, toIsSortField } from "./sortfields"; +import { type SortFieldFor, toIsSortField } from "./sortfields"; import { - DurationSeconds, + type DurationSeconds, isDurationSeconds, isUnixTimestampSeconds, - UnixTimestampSeconds, + type UnixTimestampSeconds, } from "./time"; // FIXME: Naming Task vs. Job diff --git a/server/shared/utils/json.ts b/server/shared/utils/json.ts index 93d2791..d6b7884 100644 --- a/server/shared/utils/json.ts +++ b/server/shared/utils/json.ts @@ -1,7 +1,7 @@ /** * Utility functions for JSON. */ -import { isJSONValue, JSONObject, JSONValue } from "../types"; +import { isJSONValue, type JSONObject, type JSONValue } from "../types"; /** * Parses the given `string` and converts it into a {@link JSONValue}. diff --git a/server/shared/utils/node.ts b/server/shared/utils/node.ts index d3fa480..d76fcf7 100644 --- a/server/shared/utils/node.ts +++ b/server/shared/utils/node.ts @@ -1,7 +1,7 @@ /** * Utility functions for node related data. */ -import { MAC, MapId } from "../types"; +import type { MAC, MapId } from "../types"; /** * Converts the MAC address of a Freifunk node to an id representing it on the community's node map. diff --git a/server/shared/utils/strings.ts b/server/shared/utils/strings.ts index 5413888..0068e8a 100644 --- a/server/shared/utils/strings.ts +++ b/server/shared/utils/strings.ts @@ -1,7 +1,7 @@ /** * Utility functions all around strings. */ -import { isInteger, MAC } from "../types"; +import { isInteger, type MAC } from "../types"; /** * Trims the given `string` and replaces multiple whitespaces by one space each. diff --git a/server/shared/utils/time.ts b/server/shared/utils/time.ts index e530397..3de027b 100644 --- a/server/shared/utils/time.ts +++ b/server/shared/utils/time.ts @@ -1,7 +1,7 @@ /** * Utility functions for "wibbly wobbly timey wimey" stuff. */ -import { UnixTimestampMilliseconds, UnixTimestampSeconds } from "../types"; +import type { UnixTimestampMilliseconds, UnixTimestampSeconds } from "../types"; /** * Converts an {@link UnixTimestampMilliseconds} to an {@link UnixTimestampSeconds} rounding down. diff --git a/server/shared/validation/constraints.ts b/server/shared/validation/constraints.ts index c35d7a3..97f1fa4 100644 --- a/server/shared/validation/constraints.ts +++ b/server/shared/validation/constraints.ts @@ -115,6 +115,3 @@ const CONSTRAINTS = { }; export default CONSTRAINTS; - -// TODO: Remove after refactoring. -module.exports = CONSTRAINTS; 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;