Harmonize tsconfig for frontend and server.

This commit is contained in:
baldo 2022-09-14 16:33:43 +02:00
parent 894ee97fdf
commit 22bff3496a
30 changed files with 77 additions and 53 deletions

View file

@ -1,5 +1,5 @@
import { LogLevel, TaggedLogger } from "../types"; import type { LogLevel, TaggedLogger } from "../types";
import { ActivatableLogger } from "../logger"; import type { ActivatableLogger } from "../logger";
export type MockLogMessages = unknown[][]; export type MockLogMessages = unknown[][];
type TaggedLogMessages = { type TaggedLogMessages = {

View file

@ -80,4 +80,4 @@ export class MockDatabase implements TypedDatabase {
export const db: MockDatabase = new MockDatabase(); export const db: MockDatabase = new MockDatabase();
export { TypedDatabase, Statement }; export { Statement };

View file

@ -6,7 +6,7 @@ import { config } from "../config";
import Logger from "../logger"; import Logger from "../logger";
import { Database, open, Statement } from "sqlite"; import { Database, open, Statement } from "sqlite";
import * as sqlite3 from "sqlite3"; import * as sqlite3 from "sqlite3";
import { RunResult, SqlType, TypedDatabase } from "../types"; import type { RunResult, SqlType, TypedDatabase } from "../types";
const pglob = util.promisify(glob); const pglob = util.promisify(glob);
const pReadFile = util.promisify(fs.readFile); const pReadFile = util.promisify(fs.readFile);

View file

@ -1,7 +1,7 @@
import { createTransport, Transporter } from "nodemailer"; import { createTransport, Transporter } from "nodemailer";
import { config } from "../config"; import { config } from "../config";
import * as MailTemplateService from "../services/mailTemplateService"; 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"; import SMTPTransport from "nodemailer/lib/smtp-transport";
let transporterSingleton: Transporter | null = null; let transporterSingleton: Transporter | null = null;

View file

@ -3,7 +3,7 @@ import { promises as fs } from "graceful-fs";
import ErrorTypes from "../utils/errorTypes"; import ErrorTypes from "../utils/errorTypes";
import Logger from "../logger"; import Logger from "../logger";
import * as Resources from "../utils/resources"; import * as Resources from "../utils/resources";
import { Request, Response } from "express"; import type { Request, Response } from "express";
const indexHtml = __dirname + "/../../client/index.html"; const indexHtml = __dirname + "/../../client/index.html";

View file

@ -5,7 +5,7 @@ import * as Resources from "../utils/resources";
import { handleJSONWithData, RequestData } from "../utils/resources"; import { handleJSONWithData, RequestData } from "../utils/resources";
import { normalizeString, parseInteger } from "../shared/utils/strings"; import { normalizeString, parseInteger } from "../shared/utils/strings";
import { forConstraint } from "../shared/validation/validator"; import { forConstraint } from "../shared/validation/validator";
import { Request, Response } from "express"; import type { Request, Response } from "express";
import { isString, Mail, MailId } from "../types"; import { isString, Mail, MailId } from "../types";
const isValidId = forConstraint(CONSTRAINTS.id, false); const isValidId = forConstraint(CONSTRAINTS.id, false);

View file

@ -5,7 +5,7 @@ import * as Resources from "../utils/resources";
import { handleJSONWithData } from "../utils/resources"; import { handleJSONWithData } from "../utils/resources";
import { normalizeString } from "../shared/utils/strings"; import { normalizeString } from "../shared/utils/strings";
import { forConstraint } from "../shared/validation/validator"; import { forConstraint } from "../shared/validation/validator";
import { Request, Response } from "express"; import type { Request, Response } from "express";
import { import {
isMonitoringToken, isMonitoringToken,
JSONObject, JSONObject,

View file

@ -6,7 +6,7 @@ import { normalizeMac, normalizeString } from "../shared/utils/strings";
import { forConstraint, forConstraints } from "../shared/validation/validator"; import { forConstraint, forConstraints } from "../shared/validation/validator";
import * as Resources from "../utils/resources"; import * as Resources from "../utils/resources";
import { handleJSONWithData } from "../utils/resources"; import { handleJSONWithData } from "../utils/resources";
import { Request, Response } from "express"; import type { Request, Response } from "express";
import { import {
CreateOrUpdateNode, CreateOrUpdateNode,
DomainSpecificNodeResponse, DomainSpecificNodeResponse,

View file

@ -5,7 +5,7 @@ import { handleJSONWithData, RequestData } from "../utils/resources";
import { getTasks, Task } from "../jobs/scheduler"; import { getTasks, Task } from "../jobs/scheduler";
import { normalizeString } from "../shared/utils/strings"; import { normalizeString } from "../shared/utils/strings";
import { forConstraint } from "../shared/validation/validator"; import { forConstraint } from "../shared/validation/validator";
import { Request, Response } from "express"; import type { Request, Response } from "express";
import { import {
isString, isString,
isTaskSortField, isTaskSortField,

View file

@ -4,7 +4,7 @@ import { db } from "../db/database";
import Logger from "../logger"; import Logger from "../logger";
import * as MailTemplateService from "./mailTemplateService"; import * as MailTemplateService from "./mailTemplateService";
import * as Resources from "../utils/resources"; import * as Resources from "../utils/resources";
import { RestParams } from "../utils/resources"; import type { RestParams } from "../utils/resources";
import { import {
EmailAddress, EmailAddress,
isJSONObject, isJSONObject,

View file

@ -7,8 +7,8 @@ import { htmlToText } from "nodemailer-html-to-text";
import { config } from "../config"; import { config } from "../config";
import Logger from "../logger"; import Logger from "../logger";
import { editNodeUrl } from "../utils/urlBuilder"; import { editNodeUrl } from "../utils/urlBuilder";
import { Transporter } from "nodemailer"; import type { Transporter } from "nodemailer";
import { MailData, Mail } from "../types"; import type { MailData, Mail } from "../types";
const templateBasePath = __dirname + "/../mailTemplates"; const templateBasePath = __dirname + "/../mailTemplates";
const snippetsBasePath = templateBasePath + "/snippets"; const snippetsBasePath = templateBasePath + "/snippets";

View file

@ -1,7 +1,7 @@
import { ParsedNode, parseNode, parseNodesJson } from "./monitoringService"; import { ParsedNode, parseNode, parseNodesJson } from "./monitoringService";
import { Domain, MAC, OnlineState, Site, UnixTimestampSeconds } from "../types"; import { Domain, MAC, OnlineState, Site, UnixTimestampSeconds } from "../types";
import Logger from "../logger"; import Logger from "../logger";
import { MockLogger } from "../__mocks__/logger"; import type { MockLogger } from "../__mocks__/logger";
import { now, parseTimestamp } from "../utils/time"; import { now, parseTimestamp } from "../utils/time";
const mockedLogger = Logger as MockLogger; const mockedLogger = Logger as MockLogger;

View file

@ -10,7 +10,7 @@ import Logger from "../logger";
import * as MailService from "../services/mailService"; import * as MailService from "../services/mailService";
import * as NodeService from "../services/nodeService"; import * as NodeService from "../services/nodeService";
import * as Resources from "../utils/resources"; 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 { normalizeMac, parseInteger } from "../shared/utils/strings";
import { monitoringDisableUrl } from "../utils/urlBuilder"; import { monitoringDisableUrl } from "../utils/urlBuilder";
import CONSTRAINTS from "../shared/validation/constraints"; import CONSTRAINTS from "../shared/validation/constraints";

View file

@ -3,7 +3,7 @@
* *
* @module arrays * @module arrays
*/ */
import { TypeGuard } from "./helpers"; import type { TypeGuard } from "./helpers";
/** /**
* Type guard for an array with elements of type `<Element>`. * Type guard for an array with elements of type `<Element>`.

View file

@ -9,8 +9,15 @@ import { isBoolean, isNumber, isString } from "./primitives";
import { isArray } from "./arrays"; import { isArray } from "./arrays";
import { isOptional } from "./helpers"; import { isOptional } from "./helpers";
import { isJSONObject } from "./json"; import { isJSONObject } from "./json";
import { Domain, isDomain, isSite, isUrl, Site, Url } from "./newtypes"; import {
import { EmailAddress, isEmailAddress } from "./email"; type Domain,
isDomain,
isSite,
isUrl,
type Site,
type Url,
} from "./newtypes";
import { type EmailAddress, isEmailAddress } from "./email";
/** /**
* Configuration for a single coordinate. * Configuration for a single coordinate.

View file

@ -3,10 +3,10 @@
*/ */
import { toIsNewtype } from "./newtypes"; import { toIsNewtype } from "./newtypes";
import { isNumber, isString } from "./primitives"; import { isNumber, isString } from "./primitives";
import { JSONObject } from "./json"; import type { JSONObject } from "./json";
import { toIsEnum } from "./enums"; import { toIsEnum } from "./enums";
import { SortFieldFor, toIsSortField } from "./sortfields"; import { type SortFieldFor, toIsSortField } from "./sortfields";
import { UnixTimestampSeconds } from "./time"; import type { UnixTimestampSeconds } from "./time";
/** /**
* An email address. * An email address.

View file

@ -1,7 +1,7 @@
/** /**
* Contains type guards and helpers for enums. * 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. * Shorthand type alias for enum {@link TypeGuard}s.

View file

@ -2,21 +2,26 @@
* Contains types and type guards for monitoring data. * Contains types and type guards for monitoring data.
*/ */
import { import {
Domain, type Domain,
isDomain, isDomain,
isMAC, isMAC,
isSite, isSite,
MAC, type MAC,
Site, type Site,
toIsNewtype, toIsNewtype,
} from "./newtypes"; } from "./newtypes";
import { isBoolean, isNumber, isString } from "./primitives"; import { isBoolean, isNumber, isString } from "./primitives";
import { toIsEnum } from "./enums"; import { toIsEnum } from "./enums";
import { Hostname, isHostname, isMapId, MapId } from "./node"; import { type Hostname, isHostname, isMapId, type MapId } from "./node";
import { EmailAddress, isEmailAddress, isMailType, MailType } from "./email"; import {
import { isUnixTimestampSeconds, UnixTimestampSeconds } from "./time"; type EmailAddress,
isEmailAddress,
isMailType,
MailType,
} from "./email";
import { isUnixTimestampSeconds, type UnixTimestampSeconds } from "./time";
import { isOptional } from "./helpers"; 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. * Token for activating monitoring of a Freifunk node. This is being sent to verify the email address to use.

View file

@ -6,7 +6,7 @@
* *
* Also holds newtype definitions that don't fit elsewhere. * Also holds newtype definitions that don't fit elsewhere.
*/ */
import { TypeGuard } from "./helpers"; import type { TypeGuard } from "./helpers";
import { isString } from "./primitives"; import { isString } from "./primitives";
// ===================================================================================================================== // =====================================================================================================================
@ -140,3 +140,15 @@ export type Domain = string & { readonly __tag: unique symbol };
* @param arg - Value to check. * @param arg - Value to check.
*/ */
export const isDomain = toIsNewtype(isString, "" as Domain); 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;

View file

@ -3,25 +3,27 @@
*/ */
import { isObject } from "./objects"; import { isObject } from "./objects";
import { isOptional } from "./helpers"; import { isOptional } from "./helpers";
import { import type {
Coordinates, Coordinates,
Domain, Domain,
FastdKey, FastdKey,
MAC,
Nickname,
Site,
} from "./newtypes";
import {
isCoordinates, isCoordinates,
isDomain, isDomain,
isFastdKey, isFastdKey,
isMAC, isMAC,
isNickname, isNickname,
isSite, isSite,
MAC,
Nickname,
Site,
toIsNewtype, toIsNewtype,
} from "./newtypes"; } from "./newtypes";
import { isBoolean, isString } from "./primitives"; import { isBoolean, isString } from "./primitives";
import { SortFieldFor, toIsSortField } from "./sortfields"; import { type SortFieldFor, toIsSortField } from "./sortfields";
import { EmailAddress, isEmailAddress } from "./email"; import { type EmailAddress, isEmailAddress } from "./email";
import { isUnixTimestampSeconds, UnixTimestampSeconds } from "./time"; import { isUnixTimestampSeconds, type UnixTimestampSeconds } from "./time";
import { import {
isMonitoringState, isMonitoringState,
isOnlineState, isOnlineState,

View file

@ -1,9 +1,9 @@
/** /**
* Contains helper types and type guards for sort fields. * 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 { isString } from "./primitives";
import { TypeGuard } from "./helpers"; import type { TypeGuard } from "./helpers";
/** /**
* Generic untyped sort field. * Generic untyped sort field.

View file

@ -5,12 +5,12 @@ import { toIsEnum } from "./enums";
import { isNullable } from "./helpers"; import { isNullable } from "./helpers";
import { isPlainObject } from "./objects"; import { isPlainObject } from "./objects";
import { isBoolean, isNumber, isString } from "./primitives"; import { isBoolean, isNumber, isString } from "./primitives";
import { SortFieldFor, toIsSortField } from "./sortfields"; import { type SortFieldFor, toIsSortField } from "./sortfields";
import { import {
DurationSeconds, type DurationSeconds,
isDurationSeconds, isDurationSeconds,
isUnixTimestampSeconds, isUnixTimestampSeconds,
UnixTimestampSeconds, type UnixTimestampSeconds,
} from "./time"; } from "./time";
// FIXME: Naming Task vs. Job // FIXME: Naming Task vs. Job

View file

@ -1,7 +1,7 @@
/** /**
* Utility functions for JSON. * 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}. * Parses the given `string` and converts it into a {@link JSONValue}.

View file

@ -1,7 +1,7 @@
/** /**
* Utility functions for node related data. * 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. * Converts the MAC address of a Freifunk node to an id representing it on the community's node map.

View file

@ -1,7 +1,7 @@
/** /**
* Utility functions all around strings. * 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. * Trims the given `string` and replaces multiple whitespaces by one space each.

View file

@ -1,7 +1,7 @@
/** /**
* Utility functions for "wibbly wobbly timey wimey" stuff. * 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. * Converts an {@link UnixTimestampMilliseconds} to an {@link UnixTimestampSeconds} rounding down.

View file

@ -115,6 +115,3 @@ const CONSTRAINTS = {
}; };
export default CONSTRAINTS; export default CONSTRAINTS;
// TODO: Remove after refactoring.
module.exports = CONSTRAINTS;

View file

@ -19,8 +19,9 @@
// "removeComments": true, /* Do not emit comments to output. */ // "removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */ // "noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */ // "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'. */ // "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 Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */ "strict": true, /* Enable all strict type-checking options. */
@ -29,7 +30,7 @@
// "strictFunctionTypes": true, /* Enable strict checking of function types. */ // "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ // "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. */ // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
/* Additional Checks */ /* Additional Checks */

View file

@ -9,7 +9,7 @@ import {
isConstraints, isConstraints,
NestedConstraints, NestedConstraints,
} from "../shared/validation/validator"; } from "../shared/validation/validator";
import { Request, Response } from "express"; import type { Request, Response } from "express";
import { import {
type GenericSortField, type GenericSortField,
isJSONObject, isJSONObject,

View file

@ -1,5 +1,5 @@
import { config } from "../config"; import { config } from "../config";
import { MonitoringToken, Url } from "../types"; import type { MonitoringToken, Url } from "../types";
function formUrl(route: string, queryParams?: { [key: string]: string }): Url { function formUrl(route: string, queryParams?: { [key: string]: string }): Url {
let url = config.server.baseUrl as string; let url = config.server.baseUrl as string;