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 { ActivatableLogger } from "../logger";
import type { LogLevel, TaggedLogger } from "../types";
import type { ActivatableLogger } from "../logger";
export type MockLogMessages = unknown[][];
type TaggedLogMessages = {

View file

@ -80,4 +80,4 @@ export class MockDatabase implements TypedDatabase {
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 { 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);

View file

@ -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;

View file

@ -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";

View file

@ -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);

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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";

View file

@ -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;

View file

@ -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";

View file

@ -3,7 +3,7 @@
*
* @module arrays
*/
import { TypeGuard } from "./helpers";
import type { TypeGuard } from "./helpers";
/**
* 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 { 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.

View file

@ -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.

View file

@ -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.

View file

@ -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.

View file

@ -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;

View file

@ -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,

View file

@ -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.

View file

@ -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

View file

@ -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}.

View file

@ -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.

View file

@ -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.

View file

@ -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.

View file

@ -115,6 +115,3 @@ const 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. */
// "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 */

View file

@ -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,

View file

@ -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;